diff options
author | BlackDex <[email protected]> | 2022-07-10 16:39:38 +0200 |
---|---|---|
committer | BlackDex <[email protected]> | 2022-07-10 16:39:38 +0200 |
commit | 55d7c48b1da23770d8152724ad8b6c733739e64d (patch) | |
tree | 619ebee1c93b0648db28e038548e74d70312efbf /src/util.rs | |
parent | b64cf27038f04368af8f25aa80782d37471e6303 (diff) | |
download | vaultwarden-55d7c48b1da23770d8152724ad8b6c733739e64d.tar.gz vaultwarden-55d7c48b1da23770d8152724ad8b6c733739e64d.zip |
Add more clippy checks for better code/readability
A bit inspired by @paolobarbolini from this commit at lettre https://github.com/lettre/lettre/pull/784 .
I added a few more clippy lints here, and fixed the resulted issues.
Overall i think this could help in preventing future issues, and maybe
even peformance problems. It also makes some code a bit more clear.
We could always add more if we want to, i left a few out which i think
arn't that huge of an issue. Some like the `unused_async` are nice,
which resulted in a few `async` removals.
Some others are maybe a bit more estatic, like `string_to_string`, but i
think it looks better to use `clone` in those cases instead of `to_string` while they already are a string.
Diffstat (limited to 'src/util.rs')
-rw-r--r-- | src/util.rs | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/src/util.rs b/src/util.rs index 82cb328e..e00583b6 100644 --- a/src/util.rs +++ b/src/util.rs @@ -300,7 +300,7 @@ impl Fairing for BetterLogging { // use std::{ fs::{self, File}, - io::{Read, Result as IOResult}, + io::Result as IOResult, path::Path, }; @@ -309,11 +309,7 @@ pub fn file_exists(path: &str) -> bool { } pub fn read_file(path: &str) -> IOResult<Vec<u8>> { - let mut contents: Vec<u8> = Vec::new(); - - let mut file = File::open(Path::new(path))?; - file.read_to_end(&mut contents)?; - + let contents = fs::read(Path::new(path))?; Ok(contents) } @@ -326,11 +322,7 @@ pub fn write_file(path: &str, content: &[u8]) -> Result<(), crate::error::Error> } pub fn read_file_string(path: &str) -> IOResult<String> { - let mut contents = String::new(); - - let mut file = File::open(Path::new(path))?; - file.read_to_string(&mut contents)?; - + let contents = fs::read_to_string(Path::new(path))?; Ok(contents) } |