How to Elegantly Return a Structure and Its Reference? (See the build Function)
原文英文,约200词,阅读约需1分钟。发表于: 。use std::{marker::PhantomPinned, pin::Pin, ptr::NonNull}; pub struct User { pub name: String, } pub struct Token<'a> { pub data: &'a str, } impl<'a> Token<'a> { pub fn data(&self)...
本文介绍了一个Rust程序,定义了User和Token结构体,并实现了user_token函数以生成Token。build函数创建包含User和Token的ResData实例,并通过测试验证Token数据的正确性。