From 809c3a5c612e86130ce25c03e9ae2194f9d614ee Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Sun, 22 Sep 2024 00:22:11 -0400 Subject: [PATCH 1/3] fix: update example code for get_typed_blob and get_typed_state to correct --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fae9a0b..cec9056 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -236,7 +236,7 @@ where /// field_two: HashSet, /// } /// -/// get_typed_blob(|bytes| Ok(bincode::deserialize(bytes)?)).unwrap_or(MyType { +/// get_typed_blob(|bytes| bincode::deserialize(bytes)).unwrap_or(MyType { /// field: HashMap::new(), /// field_two: HashSet::new(), /// }); @@ -272,7 +272,7 @@ where /// field_two: HashSet, /// } /// -/// get_typed_state(|bytes| Ok(bincode::deserialize(bytes)?)).unwrap_or(MyStateType { +/// get_typed_state(|bytes| bincode::deserialize(bytes)).unwrap_or(MyStateType { /// field: HashMap::new(), /// field_two: HashSet::new(), /// }); From 04553a05a54e899ca10207e50962126387fb3fda Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Tue, 1 Oct 2024 14:28:07 -0700 Subject: [PATCH 2/3] vfs file: drop -> close file --- src/vfs/file.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/vfs/file.rs b/src/vfs/file.rs index 861d8ea..9ebee88 100644 --- a/src/vfs/file.rs +++ b/src/vfs/file.rs @@ -20,6 +20,12 @@ impl File { } } + fn drop(&self) { + vfs_request(&self.path, VfsAction::CloseFile) + .send() + .unwrap(); + } + /// Reads the entire file, from start position. /// Returns a vector of bytes. pub fn read(&self) -> Result, VfsError> { From 18a11bc9f777a6659af800e0a858fe0fbad489e2 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Tue, 1 Oct 2024 14:43:40 -0700 Subject: [PATCH 3/3] vfs file: dropping a File object sends a `CloseFile` to vfs --- src/vfs/file.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/vfs/file.rs b/src/vfs/file.rs index 9ebee88..f4718ff 100644 --- a/src/vfs/file.rs +++ b/src/vfs/file.rs @@ -20,12 +20,6 @@ impl File { } } - fn drop(&self) { - vfs_request(&self.path, VfsAction::CloseFile) - .send() - .unwrap(); - } - /// Reads the entire file, from start position. /// Returns a vector of bytes. pub fn read(&self) -> Result, VfsError> { @@ -329,6 +323,14 @@ impl File { } } +impl Drop for File { + fn drop(&mut self) { + vfs_request(&self.path, VfsAction::CloseFile) + .send() + .unwrap(); + } +} + /// Creates a drive with path "/package_id/drive", gives you read and write caps. /// Will only work on the same package_id as you're calling it from, unless you /// have root capabilities.