Questions tagged [mutable]
A mutable can be modified after it is created.
mutable
1,207
questions
0
votes
0
answers
46
views
Function adapting to mutable or non-mutable input
I wanted to build a function/method that could adapt if a non-mutable or mutable reference was provided.
I tried something like this (playground):
trait TryAsMut<'a, T> where T: 'a {
fn ...
0
votes
1
answer
61
views
Best way to have a nested mutable data element in rust
I'm trying to figure out the best way to handle some nested mutable changes. I've got the following code that mimicks the issue I'm running into:
use std::collections::HashMap;
use circular_buffer::...
0
votes
1
answer
74
views
Kotlin backing field wrong type
ViewModel
private val _wordPressPostsState = Channel<WordPressPostsState>()
val wordPressPostList: List<WordPressPostDataDomain>
field = mutableListOf<WordPressPostDataDomain>()
...
0
votes
1
answer
38
views
How to use Kotlin backing field with Channel and Flow?
I am playing with the new backing field feature introduced in Kotlin 2.0, however I am encountering some problem when using it on data type that is not a superclass/subclass of one and another.
...
3
votes
1
answer
101
views
Why does `Option::map` work with immutable data, but not with mutable data
Why does the immutable version in the following example work, but the mutable version does not compile with error error: lifetime may not live long enough?
trait Car {
fn honk(&self);
}
...
0
votes
1
answer
93
views
Can I Prove Monotonicity of Allocations to the Rust Borrow Checker
I have the following code which does not compile:
// TODO: Return Result, remove `.expect`s
fn to_blender_subfile<'a>(
filepath: &str,
transform: Transform,
visited_file_cache: &...
1
vote
1
answer
117
views
How to use Rust OnceLock get_mut() method?
The Rust documentation has a OnceLock::get_mut method that returns a mutable reference. But the following code does not compile. What am I missing?
use std::sync::OnceLock;
#[derive(Clone)]
struct ...
0
votes
1
answer
71
views
Bad design for Rust program with lifetime and multiple references
I am implementing a graph data structure in Rust. For each node (and also edges - omitted from this snippet) in the graph I have a struct Algorithm (perhaps poorly named) that performs some node and ...
-1
votes
1
answer
36
views
How to avoid second borrow in rust when iterating over mutable member of a struct and changing other members [duplicate]
I'm trying to write a code which borrow a mutable copy of the last member of a vector and then change another member of the vector. There is a check that the vector has more than 2 elements so there ...
0
votes
0
answers
70
views
making a Vec<Child> containing reference to Parent struct? [duplicate]
Im new to Rust, and i'm having this problem where I need to keep a Vec of Child in the Parent struct, and each child needs to be able to use the Parent functions, so with some research I ended up with ...
0
votes
0
answers
44
views
Cannot borrow variable as mutable within loop [duplicate]
I have the following file in my interpreter for a personal programming language. The program itself is meant to take the output of the parser and convert it into an active parse tree.
use crate::...
0
votes
1
answer
130
views
Two-way mutable pointer relationship with trait DerefMut in a container-element setup?
I am trying to implement something which Rust's ownership rules almost seem designed to make impossible. But it's very simple: I want a framework containing a hashmap where the values are a class, ...
1
vote
1
answer
57
views
Abstracting mutable/immutable references in rust
I need to get rid of duplication in this code:
pub struct Memory {
layout: MemoryLayout,
rom: Vec<u8>,
ram: Vec<u8>,
}
impl Memory {
pub fn get_mem_vec_ref(&self, ...
-1
votes
1
answer
146
views
Exposing an Immutable and Mutable Record Class C#
I would like to write a set of c# record classes that offer both a Immutable and Mutable version of themselves.
This is similar to how there is a List and ReadOnlyList offered in c# (yes, arguably not ...
0
votes
0
answers
100
views
How to resolve mutable borrow followed by immutable borrow within a loop in Rust?
I'm encountering a borrow checker issue in Rust where I am attempting to modify a Vec<u8> within a loop using splice, and then obtain a reference to the same Vec immediately afterwards. The ...