Jelajahi Sumber

Simplify file reading/writing with Rust 1.26 which is now stable

timvisee 7 tahun lalu
induk
melakukan
2755d6ed5c
4 mengubah file dengan 5 tambahan dan 24 penghapusan
  1. 1 1
      REQUIREMENTS.md
  2. 0 1
      ROADMAP.md
  3. 1 5
      api/src/file/remote_file.rs
  4. 3 17
      cli/src/history.rs

+ 1 - 1
REQUIREMENTS.md

@@ -2,7 +2,7 @@
 This tool has some additional compilation requirements besides the Rust
 toolchain.
 
-- Rust 1.20 or above (verify this)
+- Rust 1.26 or above (verify this)
 
 ## Requirements
 - OpenSSL development files

+ 0 - 1
ROADMAP.md

@@ -1,5 +1,4 @@
 # Release 0.1
-- Panic when secret is missing from URL with info action
 - Switch to `directories` instead of `app_dirs2`?
 - Allow file/directory archiving on upload
 - Allow unarchiving on download 

+ 1 - 5
api/src/file/remote_file.rs

@@ -228,12 +228,8 @@ impl RemoteFile {
     }
 
     /// Get the raw secret.
+    // TODO: ensure whether the secret is set?
     pub fn secret_raw(&self) -> &Vec<u8> {
-        // A secret must have been set
-        if !self.has_secret() {
-            panic!("missing secret");
-        }
-
         &self.secret
     }
 

+ 3 - 17
cli/src/history.rs

@@ -52,14 +52,7 @@ impl History {
     /// Load the history from the given file.
     pub fn load(path: PathBuf) -> Result<Self, LoadError> {
         // Read the file to a string
-        use std::fs::File;
-        use std::io::Read;
-        let mut file = File::open(&path)?;
-        let mut data = String::new();
-        file.read_to_string(&mut data)?;
-
-        // TODO: switch to this instead in stable Rust 1.26
-        // let data = fs::read_to_string(&path)?;
+        let data = fs::read_to_string(&path)?;
 
         // Parse the data, set the autosave path
         let mut history: Self = toml::from_str(&data)?;
@@ -122,16 +115,9 @@ impl History {
             fs::create_dir_all(parent)?;
         }
 
-        // Build the data
+        // Build the data and write to a file
         let data = toml::to_string(self)?;
-
-        // Write to the file
-        use std::fs::File;
-        use std::io::Write;
-        File::create(&path)?.write_all(data.as_ref())?;
-
-        // TODO: switch to this instead in stable Rust 1.26
-        // let data = fs::read_to_string(path.clone())?;
+        fs::write(&path, data)?;
 
         // There are no new changes, set the flag
         self.changed = false;