rust - X 类型的值的大小在编译时是未知的
问题描述
我正在尝试 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`
这些错误是如何产生的,我能做些什么来解决它们?
解决方案
推荐阅读
- java - 如何在项目出现之前返回节点的值?
- ios - ios 可访问性 magictap 不会传播到选项卡视图之外
- android - 在 Android 11 上添加到主屏幕功能
- excel - Excel中有没有办法根据单元格样式对单元格进行排序?
- python - 将标签添加到 OneLineAvataListItem Python kivy
- c++ - 命名空间范围在 C++ 中如何工作?
- php - 来自子文件夹 MVC PHP 的访问控制器
- c# - 测试结束时未调用 Specflow.Autofac IDisposable
- javascript - 使用严格相等运算符而不是普通相等运算符获得未定义
- python - Django - POST 端点以更新多个表。返回包含所有相关数据的响应