Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rust 编译时无法知道类型为`(dyn-SeekRead+;';static)`的值的大小_Rust - Fatal编程技术网

Rust 编译时无法知道类型为`(dyn-SeekRead+;';static)`的值的大小

Rust 编译时无法知道类型为`(dyn-SeekRead+;';static)`的值的大小,rust,Rust,我正在尝试编译以下代码: error[E0277]: the size for values of type `(dyn SeekRead + 'static)` cannot be known at compilation time --> src/archive/zipfile.rs:10:18 | 10 | zip_archive: Box<ZipArchive<dyn SeekRead>>, | ^^

我正在尝试编译以下代码:

error[E0277]: the size for values of type `(dyn SeekRead + 'static)` cannot be known at compilation time
  --> src/archive/zipfile.rs:10:18
   |
10 |     zip_archive: Box<ZipArchive<dyn SeekRead>>,
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
   | 
  ::: ~/.cargo/registry/src/github.com-1ecc6299db9ec823/zip-0.5.11/src/read.rs:50:23
   |
50 | pub struct ZipArchive<R: Read + io::Seek> {
   |                       - required by this bound in `ZipArchive`
   |
   = help: the trait `std::marker::Sized` is not implemented for `(dyn SeekRead + 'static)`
# cargo.toml
[dependencies]
zip = "0.5.11"
使用zip::read::ZipArchive;
使用std::io::{Read,Seek};
trait SeekRead:Seek+Read{}

pub-struct-ArchiveZip您只需要在结构中使用泛型类型,就像ZipArchive
那样。请注意,
ZipArchive
需要一种特定类型:

使用zip::read::ZipArchive;
使用std::io::{Read,Seek};
trait SeekRead:Seek+Read{}

pub struct ArchiveZipHow large你认为dyn SeekRead是什么?
ZipArchive
的第一个成员必须是一个。我不明白大小概念是如何结合在一起的。如何将
ZipArchive
存储为我的
struct
的成员?问题是
ZipArchive
不是有效的类型,因为
ZipArchive
不可能直接包含
dyn SeekRead
。您需要对trait对象使用某种形式的间接寻址,例如
ZipArchive