You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在自引用结构体中使用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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 04:10:39