-
Using unsafe 관련 글(The Rustonomicon=unsafe설명서Rust) -Reddit-learnrust코딩Coding/★Rust★기초★Syntax 2022. 2. 24. 18:33728x90
Using unsafe to borrow *self as mutable more than once?
So I have a the following situation, where I am calling two methods inside a struct that borrow self as mutable
if let Some(list_item) = self.selected_item_mut(){
if let Some(item) = self.get_item_in_tree_mut(list_item){
<code snipped>
Then I get the "cannot borrow `*self` as mutable more than once at a time".
So then I thought I'd try some unsafe code?
unsafe{
if let Some(list_item) = self.selected_item_mut(){
if let Some(item) = self.get_item_in_tree_mut(list_item){
<code snipped>
}
But then I get the same error along with "unnecessary unsafe block"
Any help appreciated!
edit: I guess what I'm really trying to do is access two different data structures inside the struct, but I can't borrow self as both immutable and mutable, and can't borrow it as mutable twice, and I need a mutable reference to the object inside the second data structure.Rust
Unsafe 지침서
Nomicon
https://doc.rust-lang.org/nomicon/index.html반응형'코딩Coding > ★Rust★기초★Syntax' 카테고리의 다른 글
Vec<String> or Vec<&str> for function argument? (0) 2022.02.26 WebGPU]Building WebGPU with Rust- Code Geek (0) 2022.02.25 Rust_slices]❤️String Literals Are Slices (0) 2022.02.25 Rust]❤️String ->as_bytes메소드를 이용해 바이트 배열로 변환 (0) 2022.02.25 Rust]<What is a function signature and type? (0) 2022.02.23 Rust 27분 짜리 간단한 강의- Tim McNamara- Rist Linz (0) 2022.02.23 Rust Async- How to build an Async Router in Rust!!- Jeremy Chone (0) 2022.02.22 Rust] 16진수 -> 10진수 숫자 출력하는 방법 (0) 2022.02.22