Rust std::marker::Sized不满足要求

Rust std::marker::Sized不满足要求,rust,Rust,我正试图创建一种组件系统,其灵感来源于react,我正在为一个OpenGL项目工作。该组件系统由包含一些属性和函数的结构定义。像这样: pub struct Component<Lifecycle, PropType> { lifecycle: Lifecycle, props: PropType, children: Vec<Component<Lifecycle, PropType>>, } PropType示例如下所示: pub

我正试图创建一种组件系统,其灵感来源于react,我正在为一个OpenGL项目工作。该组件系统由包含一些属性和函数的结构定义。像这样:

pub struct Component<Lifecycle, PropType> {
    lifecycle: Lifecycle,
    props: PropType,
    children: Vec<Component<Lifecycle, PropType>>,
}
PropType示例如下所示:

pub struct MeshLifecycle {
    render: (Fn(ComponentProps) -> Mesh),
}
pub struct ComponentProps {
    position: Vertex,
}
现在,这导致了一些错误。首先:

the trait bound `std::ops::Fn(ComponentProps) -> Mesh + 'static: std::marker::Sized`
经过一些挖掘,我想我应该将
?size
应用于基本上包含函数的类型。因此,
组件
的定义现在是:

pub struct Component<Lifecycle: ?Sized, PropType> {

有没有办法让这样的事情成功(以及如何成功),或者这在本质上太“动态”了?我在某个地方读到,我实际上想做的是创建一个“VTable”。在线的各种示例似乎没有指定动态大小的类型,因此我想知道我做得有什么不对。

您是否尝试将
渲染
定义为
长方体网格>
?@WiSaGaN我没有尝试过!我确实看到了一些关于“Box”的提示,但我无法真正理解它是什么。
Box
在堆栈上有一个固定的长度。但是像其他特征一样,
Fn
没有固定的长度,因此绑定的
std::market::Sized
是不满足的。@WiSaGaN对我有用@WiSaGaN您可能希望添加您的评论作为答案,并让它解决问题!顺便说一句,谢谢你的提示
src/main.rs:10:5: 10:25 error: the trait bound `Lifecycle: std::marker::Sized` is not satisfied [E0277]
src/main.rs:10     lifecycle: Lifecycle,
                   ^~~~~~~~~~~~~~~~~~~~
src/main.rs:10:5: 10:25 help: run `rustc --explain E0277` to see a detailed explanation
src/main.rs:10:5: 10:25 help: consider adding a `where Lifecycle: std::marker::Sized` bound
src/main.rs:10:5: 10:25 note: only the last field of a struct or enum variant may have a dynamically sized type