如何在自引用结构体中使用Pin struct?代码实现咨询
尝试Rust Pin特性的代码实践
最近我在摸索Rust里的新Pin特性,看完一篇博客文章后,我动手写了下面这段代码:
#![feature(pin, arbitrary_self_types)] use std::mem::Pin; pub struct Foo { var: i32, } pub struct FooRef<'i> { ref_var: &'i i32, other: i32, } pub struct SimpleRef<'data> { foo: Box<Foo>, bar: Option<FooRef<'data>>, } impl<'data> SimpleRef<'data> { fn new() -> SimpleRef<'data> { SimpleRef { foo: Box::new({ Foo { var: 42 } }), bar: None, } }...
内容的提问来源于stack exchange,提问作者Sébastien Chapuis
相关产品推荐
相关产品推荐

