我有这样一件事:
type G2d<'a> = GfxGraphics<'a, Resources, CommandBuffer>;如何将其作为字段包含到结构中?
pub struct Dc
{
g : G2d,
c : Context,
}但它提供了:
expected named lifetime parameter我试过了:
pub struct Dc
{
g : &'a mut G2d<'a>,
c : Context,
}
window.draw_2d( &event, | c, g, device |
{
let mut dc = Dc { c, g };
});但它提供了:

如果有任何帮助,我将不胜感激。
发布于 2021-07-05 19:27:22
正确的解决方案是
pub struct Dc<'a, 'b>
{
g : &'a mut G2d<'b>,
c : Context,
}这在逻辑上是不恰当的,让外部&mut borrow与G2d< 'a > was内部的引用同时创建。所以在表达式&'a mut G2d<'a>这两个生命周期中,这两个生命周期不可能意味着它们借用了相同的东西。正确的解决方案是使用多个生命周期。
发布于 2021-07-05 04:48:31
整个结构应该由生命周期来注解:
pub struct Dc<'a>
{
g : G2d<'a>,
c : Context,
}https://stackoverflow.com/questions/68248611
复制相似问题