在编译时无法得知类型为“ Web3”的值的大小

问题描述 投票:-1回答:1

我正在尝试使用Rust-web3 API,并将所有与web3相关的功能放在main.rs块之外的单独模块中(例如,ethereum.rs),但是遇到错误,所以我想知道是否可能完全没有。

ethereum.rs

extern crate web3;
use web3::api::Web3;
use web3::Transport;
use web3::error::Error;
use web3::transports::http::Http;

extern crate serde_json;
use serde_json::value::Value;

use web3::futures::Future;
pub fn establish_connection() -> Web3<Transport<Out: Future<Item = Value, Error = Error>>> {
    let infura_address = "https://ropsten.infura.io/v3/XXXX";
    let (_eloop, http) = web3::transports::Http::new(&infura_address).unwrap();
    let web3 = web3::Web3::new(http);
}

错误消息:

error[E0277]: the size for values of type `(dyn web3::Transport<Out = impl web3::futures::Future> + 'static)` cannot be known at compilation time
  --> src/ethereum.rs:14:1
   |
14 | / pub fn establish_connection() -> Web3 <Transport<Out: Future<Item = Value, Error = Error>>>{
15 | |     let infura_address = "https://ropsten.infura.io/v3/3716b01517a742c7b34a70040e3b17a1";
16 | |     let (_eloop, http) = web3::transports::Http::new(&infura_address).unwrap();
17 | |     let web3 = web3::Web3::new(http);
18 | | }
   | |_^ doesn't have a size known at compile-time
   |
   = help: the trait `std::marker::Sized` is not implemented for `(dyn web3::Transport<Out = impl web3::futures::Future> + 'static)`
   = note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
   = note: required by `web3::Web3`

error[E0038]: the trait `web3::Transport` cannot be made into an object
  --> src/ethereum.rs:14:1
   |
14 | pub fn establish_connection() -> Web3 <Transport<Out: Future<Item = Value, Error = Error>>>{
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `web3::Transport` cannot be made into an object
   |
   = note: the trait cannot require that `Self : Sized`

编辑:将外部包装箱web3添加到上面的代码中。如web3 doc

中所述,运输确实是一个特征
rust ethereum web3
1个回答
0
投票

除了上面来自Shepmaster的有用评论之外,我还从同事那里得到了这个清晰而有用的答案:

© www.soinside.com 2019 - 2024. All rights reserved.