- 63 名前:デフォルトの名無しさん mailto:sage [2017/10/30(月) 22:54:07.55 ID:nDqoZaw+.net]
- ありがとう。
move するとアドレスが変わるというのは無理矢理実験したときに気付いたけれど、 実際はこんな感じで Box 化された構造体の特定の変数への参照が欲しかったので、 >>38が言った前スレの>>507-514辺りを見て、こんな感じで解決してました。 use std::mem; struct Bar(i32); struct Foo { x: Box<Bar>, x_ref: &'static i32, } impl Foo { fn new() -> Self { let mut foo = Foo { x: Box::new(Bar(10)), x_ref: unsafe { mem::uninitialized() }, }; let dummy = mem::replace(&mut foo.x_ref, unsafe { mem::transmute(&foo.x.0) } ); mem::forget(dummy); foo } }
|

|