当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Rust RefCell.swap用法及代码示例


本文简要介绍rust语言中 std::cell::RefCell.swap 的用法。

用法

pub fn swap(&self, other: &RefCell<T>)

self 的包装值与 other 的包装值交换,而不取消初始化任何一个。

此函数对应于 std::mem::swap

Panics

如果当前借用了 RefCell 中的值,则会出现Panics。

例子

use std::cell::RefCell;
let c = RefCell::new(5);
let d = RefCell::new(6);
c.swap(&d);
assert_eq!(c, RefCell::new(6));
assert_eq!(d, RefCell::new(5));

相关用法


注:本文由纯净天空筛选整理自rust-lang.org大神的英文原创作品 std::cell::RefCell.swap。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。