Dave Herman最近在Rust 的演讲中说他们从C++借用了这个属性.我无法找到有关该主题的任何内容.有人可以解释一下单态意味着什么吗?
我正在尝试创建一个返回Shader特征实例的函数.这是我极为简化的代码:
trait Shader {}
struct MyShader;
impl Shader for MyShader {}
struct GraphicsContext;
impl GraphicsContext {
fn create_shader(&self) -> Shader {
let shader = MyShader;
shader
}
}
fn main() {}
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:
error[E0277]: the trait bound `Shader + 'static: std::marker::Sized` is not satisfied
--> src/main.rs:10:32
|
10 | fn create_shader(&self) -> Shader {
| ^^^^^^ `Shader + 'static` does not have a constant size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `Shader …Run Code Online (Sandbox Code Playgroud)