interior-mutability Questions

5

Solved

I have a struct that has inner mutability. use std::cell::RefCell; struct MutableInterior { hide_me: i32, vec: Vec<i32>, } struct Foo { //although not used in this particular snippet, /...

3

Solved

I want to solve a leetcode question in Rust (Remove Nth Node From End of List). My solution uses two pointers to find the Node to remove: #[derive(PartialEq, Eq, Debug)] pub struct ListNode { pub...
Superjacent asked 17/1, 2019 at 14:3

1

Solved

I have a Rust data structure that I will have to pass around and manipulate from various places in my code. To my understanding the most simple and default way to do this is to wrap everything in R...
Dysfunction asked 6/5, 2023 at 11:2

2

Solved

Standard Cell struct provides interior mutability but allows only a few mutation methods such as set(), swap() and replace(). All of these methods change the whole content of the Cell. However, som...
Bendicty asked 19/12, 2020 at 20:53

1

Solved

My background in C++ makes me uncomfortable about interior mutability. The code below is my investigation around this topic. I agree that, from the borrow checker point of view, dealing with many r...
Seisin asked 19/8, 2020 at 12:50

1

Solved

I've been thinking about why interior mutability in Rust in most cases requires runtime checks (e.g. RefCell). It looks like I've found a safe alternative without a runtime cost. I've called the ty...
Katinakatine asked 11/4, 2020 at 15:47

1

The Rust documentation covers Rc<RefCell<T>> pretty extensively but doesn't go into RefCell<Rc<T>>, which I am now encountering. Do these effectively give the same result? ...
Laevorotation asked 5/8, 2019 at 23:17

1

Solved

Why was Mutex<T> designed to need an Arc<T> if the only reason to use a Mutex<T> is for concurrent code, i.e. multiple threads? Wouldn't it be better to alias a Mutex<T> to ...
Coleorhiza asked 13/6, 2019 at 6:37

1

Solved

For example given this code: use std::rc::Rc; use std::cell::RefCell; // Don't want to copy for performance reasons struct LibraryData { // Fields ... } // Creates and mutates data field in me...
Stater asked 1/9, 2018 at 20:18

1

If I get correctly it is not possible to create a mutable borrow over a std::rc::Rc in Rust, you have to use Cell or RefCell. But anyway I cannot understand how to use them. For example consider th...
Fraley asked 15/9, 2015 at 16:51

3

Solved

When would you be required to use Cell or RefCell? It seems like there are many other type choices that would be suitable in place of these, and the documentation warns that using RefCell is a bit ...
Visser asked 14/6, 2015 at 15:16

1

I have a RefCell<HashMap> and want to borrow the table, find a key, and return a reference to the result: use std::cell::RefCell; use std::collections::HashMap; struct Frame { map: R...
Tinct asked 16/5, 2015 at 23:9

1

Solved

I'm trying to wrap my head around Rc and RefCell in Rust. What I'm trying to achieve is to to have multiple mutable references to the same objects. I came up with this dummy code: use std::rc::Rc...
Zelmazelten asked 13/8, 2014 at 22:47
1

© 2022 - 2024 — McMap. All rights reserved.