简体   繁体   English

如何使用 Rust 中的 Ref 字段初始化结构?

[英]how to initial a struct with Ref field in Rust?

If has a Stuct A and a Struct B如果有一个结构 A 和一个结构 B

struct B {}

stuct A<'a> {
 id: i32,
 b: &'a B
}
impl A<'_> {
 fn new() -> A {
   id: 3,
   b: //(I Have No B at moment, hwo to create a A without B )
 }
}

I would like to create A, then assign &B to A.我想创建 A,然后将 &B 分配给 A。

Why not use Option ?为什么不使用Option Rust doesn't have null, thankfully.谢天谢地,Rust 没有 null。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM