当前位置:网站首页>Refcell in rust
Refcell in rust
2022-04-23 18:03:00 【Xu Yeping】
RefCell And Cell Basically the same , The difference lies in RefCell When reading content , The return is the reference , It's essentially a pointer . This is because RefCell The data to be packaged is not implemented Copy characteristic . The code example is as follows :
use std::cell::{
Ref, RefCell};
fn main() {
let x = RefCell::new("good".to_string());
let a = &x;
let b = &x;
*a.borrow_mut() = "nice".to_string();
*b.borrow_mut() = "best".to_string();
let y: Ref<String> = x.borrow();
println!("x = {:?}", x);
println!("y = {:?}", y);
}
---------------------------------------------------
>cargo run
x = RefCell {
value: "best" }
y = "best"
rust This set of tools is really beautiful !
版权声明
本文为[Xu Yeping]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230544498524.html
边栏推荐
- Gobang game based on pyGame Library
- 2022 tea artist (primary) examination simulated 100 questions and simulated examination
- 列錶的使用-增删改查
- The ultimate experience, the audio and video technology behind the tiktok
- re正则表达式
- ROS package NMEA_ navsat_ Driver reads GPS and Beidou Positioning Information Notes
- 2022江西储能技术展会,中国电池展,动力电池展,燃料电池展
- Qt读写XML文件(含源码+注释)
- Docker 安裝 Redis
- Pyppeter crawler
猜你喜欢
Classification of cifar100 data set based on convolutional neural network
re正则表达式
[UDS unified diagnostic service] v. diagnostic application example: Flash bootloader
C1小笔记【任务训练篇二】
mysql自动启动设置用Systemctl start mysqld启动
Go file operation
[UDS unified diagnostic service] IV. typical diagnostic service (6) - input / output control unit (0x2F)
Re regular expression
Eigen learning summary
Summary of floating point double precision, single precision and half precision knowledge
随机推荐
.105Location
Using files to save data (C language)
I/O多路复用及其相关详解
Nodejs安装
Data stream encryption and decryption of C
Docker 安装 Redis
JS get link? The following parameter name or value, according to the URL? Judge the parameters after
Process management command
MySQL 中的字符串函数
re正則錶達式
Nat commun | current progress and open challenges of applied deep learning in Bioscience
Go的Gin框架学习
[UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (1)
Docker 安裝 Redis
Crawl the product data of Xiaomi Youpin app
Summary of floating point double precision, single precision and half precision knowledge
MySQL auto start settings start with systemctl start mysqld
C1 notes [task training part 2]
Auto.js 自定义对话框
Qtablewidget usage explanation