我正在尝试Rust并努力解决许多基本问题,例如错误本身。我有以下代码(使用Termion lib,但我确定这是不相关的)
extern crate termion;
use termion::color;
static bg_white: color::Bg<color::Color> = color::Bg(color::Rgb(255, 255, 255));
static bg_reset: color::Bg<color::Color> = color::Bg(color::Reset);
fn main() {
println!("Hello, world!");
}
当我使用cargo run
进行编译时,出现以下错误:
error[E0277]: the size for values of type `(dyn termion::color::Color + 'static)` cannot be known at compilation time
--> src/main.rs:5:1
|
5 | static bg_white: color::Bg<color::Color> = color::Bg(color::Rgb(255, 255, 255));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `(dyn termion::color::Color + 'static)`
= note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-sized>
= note: required by `termion::color::Bg`
error[E0277]: the size for values of type `(dyn termion::color::Color + 'static)` cannot be known at compilation time
--> src/main.rs:6:1
|
6 | static bg_reset: color::Bg<color::Color> = color::Bg(color::Reset);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `(dyn termion::color::Color + 'static)`
= note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-sized>
= note: required by `termion::color::Bg`
这些错误是怎么发生的,我该怎么解决?