当前位置:网站首页>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
边栏推荐
- Halo open source project learning (II): entity classes and data tables
- Climbing watermelon video URL
- Nat commun | current progress and open challenges of applied deep learning in Bioscience
- 列錶的使用-增删改查
- Flash - Middleware
- Using files to save data (C language)
- 由tcl脚本生成板子对应的vivado工程
- Welcome to the markdown editor
- 587. Install fence / Sword finger offer II 014 Anagrams in strings
- [UDS unified diagnostic service] IV. typical diagnostic service (4) - online programming function unit (0x34-0x38)
猜你喜欢
云原生虚拟化:基于 Kubevirt 构建边缘计算实例
Installation du docker redis
[UDS unified diagnostic service] v. diagnostic application example: Flash bootloader
Implementation of image recognition code based on VGg convolutional neural network
Go的Gin框架学习
Qt读写XML文件(含源码+注释)
MySQL auto start settings start with systemctl start mysqld
JS high frequency interview questions
2022 judgment questions and answers for operation of refrigeration and air conditioning equipment
Summary of floating point double precision, single precision and half precision knowledge
随机推荐
ROS package NMEA_ navsat_ Driver reads GPS and Beidou Positioning Information Notes
Flash - Middleware
C language input and output (printf and scanf functions, putchar and getchar functions)
Implement a simple function to calculate the sum of all integers between M ~ n (m < n)
Eigen learning summary
Jenkspy package installation
Arcpy adds fields and loop assignments to vector data
20222 return to the workplace
Go语言JSON包使用
纳米技术+AI赋能蛋白质组学|珞米生命科技完成近千万美元融资
I/O多路复用及其相关详解
Nat commun | current progress and open challenges of applied deep learning in Bioscience
[UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (1)
re正則錶達式
2022 Shanghai safety officer C certificate operation certificate examination question bank and simulation examination
Go language JSON package usage
Open source key component multi_ Button use, including test engineering
cartographer_ There is no problem compiling node, but running the bug that hangs directly
C1小笔记【任务训练篇二】
ES6