Remove borrow in borrow

This commit is contained in:
Daniel Kluge 2024-01-03 12:51:20 +01:00
parent 49edf93691
commit 2d9db49fef
3 changed files with 26 additions and 14 deletions

11
Cargo.lock generated
View File

@ -14,6 +14,16 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "console_error_panic_hook"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc"
dependencies = [
"cfg-if",
"wasm-bindgen",
]
[[package]]
name = "log"
version = "0.4.20"
@ -119,5 +129,6 @@ checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f"
name = "wasm-terminal"
version = "0.1.0"
dependencies = [
"console_error_panic_hook",
"wasm-bindgen",
]

View File

@ -11,4 +11,5 @@ repository = "https://git.c0ntroller.de/c0ntroller/wasm-terminal"
crate-type = ["cdylib"]
[dependencies]
console_error_panic_hook = "0.1.7"
wasm-bindgen = "0.2.89"

View File

@ -182,27 +182,27 @@ impl Directory {
}*/
pub fn remove_file(&self, name: String) -> Result<(), &'static str> {
let mut index = 0;
for file in self.files.borrow().iter() {
if file.borrow().get_name() == name {
let index = self.files.borrow().iter().position(|file| file.borrow().get_name() == name);
match index {
Some(index) => {
self.files.borrow_mut().remove(index);
return Ok(());
}
index += 1;
Ok(())
},
None => Err("File not found"),
}
Err("File not found")
}
pub fn remove_dir(&self, name: String) -> Result<(), &'static str> {
let mut index = 0;
for dir in self.subdirs.borrow().iter() {
if dir.borrow().get_name() == name {
let index: Option<usize> = self.subdirs.borrow().iter().position(|dir: &Rc<RefCell<Directory>>| dir.borrow().get_name() == name);
match index {
Some(index) => {
self.subdirs.borrow_mut().remove(index);
return Ok(());
}
index += 1;
Ok(())
},
None => Err("Directory not found"),
}
Err("Directory not found")
}
pub fn rename(&mut self, name: String) {