about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/database/file/mod.rs20
1 files changed, 6 insertions, 14 deletions
diff --git a/src/database/file/mod.rs b/src/database/file/mod.rs
index a059d22..9e33f0b 100644
--- a/src/database/file/mod.rs
+++ b/src/database/file/mod.rs
@@ -197,21 +197,13 @@ impl Storage for FileStorage {
                 let lock = get_lockable_file(f).await;
                 let guard = lock.read()?;
 
-                // HOW DOES THIS TYPECHECK?!!!!!!!!
-                // Read::read(&mut self) requires a mutable reference
-                // yet Read is implemented for &File
-                // We can't get a &mut File from &File, can we?
-                // And we need a &mut File to use Read::read_to_string()
-                // Yet if we pass it to a BufReader it works?!!
-                //
-                // I hate magic
-                //
-                // TODO find a way to get rid of BufReader here
                 let mut content = String::new();
-                let mut reader = BufReader::new(&*guard);
-                reader.read_to_string(&mut content).await?;
-                drop(reader);
-                drop(guard);
+                // Apparently this typechecks. Somehow.
+                // I can take &mut for a &File because File is not a real type
+                // The operating system guards it using something
+                // that looks like a mutex to Rust's runtime, allowing me
+                // to grab a mutable reference from an immutable reference
+                (&mut &*guard).read_to_string(&mut content).await?;
                 Ok(Some(serde_json::from_str(&content)?))
             }
             Err(err) => {