Skip to content

Commit

Permalink
Use inline format arguments
Browse files Browse the repository at this point in the history
Signed-off-by: Bryan Gurney <[email protected]>
  • Loading branch information
bgurney-rh committed Jan 27, 2023
1 parent 747743b commit 64bdcb2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn main() {
.probe("libcryptsetup")
{
Ok(l) => Version::parse(&l.version).unwrap(),
Err(e) => panic!("Bindings require at least cryptsetup-2.2.0: {}", e),
Err(e) => panic!("Bindings require at least cryptsetup-2.2.0: {e}"),
};
for ver in SUPPORTED_VERSIONS.iter().take_while(|ver_string| {
let iter_version = Version::parse(ver_string).expect("Could not parse version");
Expand Down
2 changes: 1 addition & 1 deletion examples/cryptsetup-luks2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn parse_args() -> Result<CryptCommand, LibcryptErr> {
})?;
Ok(CryptCommand::Deactivate(dev, name))
}
Some(s) => Err(LibcryptErr::Other(format!("Unrecognized command {}", s))),
Some(s) => Err(LibcryptErr::Other(format!("Unrecognized command {s}"))),
None => Err(LibcryptErr::Other("Missing command".to_string())),
}
}
Expand Down
2 changes: 1 addition & 1 deletion libcryptsetup-rs-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::path::PathBuf;
fn get_version() -> Version {
match Config::new().atleast_version("2.2.0").probe("libcryptsetup") {
Ok(l) => Version::parse(&l.version).expect("Could not parse version"),
Err(e) => panic!("Bindings require at least cryptsetup-2.2.0: {}", e),
Err(e) => panic!("Bindings require at least cryptsetup-2.2.0: {e}"),
}
}

Expand Down
26 changes: 11 additions & 15 deletions src/err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,25 @@ pub enum LibcryptErr {
impl Display for LibcryptErr {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
LibcryptErr::IOError(ref e) => write!(f, "IO error occurred: {}", e),
LibcryptErr::UuidError(ref e) => write!(f, "Failed to parse UUID from C string: {}", e),
LibcryptErr::NullError(ref e) => write!(
f,
"Null error occurred when handling &str conversion: {}",
e
),
LibcryptErr::Utf8Error(ref e) => write!(
f,
"UTF8 error occurred when handling &str conversion: {}",
e
),
LibcryptErr::IOError(ref e) => write!(f, "IO error occurred: {e}"),
LibcryptErr::UuidError(ref e) => write!(f, "Failed to parse UUID from C string: {e}"),
LibcryptErr::NullError(ref e) => {
write!(f, "Null error occurred when handling &str conversion: {e}")
}
LibcryptErr::Utf8Error(ref e) => {
write!(f, "UTF8 error occurred when handling &str conversion: {e}")
}
LibcryptErr::JsonError(ref e) => {
write!(f, "Failed to parse the provided string into JSON: {}", e)
write!(f, "Failed to parse the provided string into JSON: {e}")
}
LibcryptErr::InvalidConversion => {
write!(f, "Failed to perform the specified conversion")
}
LibcryptErr::NullPtr => write!(f, "Cryptsetup returned a null pointer"),
LibcryptErr::NoNull(s) => {
write!(f, "Static string {} was not created with c_str!() macro", s)
write!(f, "Static string {s} was not created with c_str!() macro")
}
LibcryptErr::Other(ref s) => write!(f, "Failed with error: {}", s),
LibcryptErr::Other(ref s) => write!(f, "Failed with error: {s}"),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/encrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ fn activate_null_cipher(dev_path: &Path, device_name: &'static str) -> Result<()
}

fn write_random(device_name: &str) -> Result<Box<[u8]>, io::Error> {
let mapped_device_path = PathBuf::from(format!("/dev/mapper/{}", device_name));
let mapped_device_path = PathBuf::from(format!("/dev/mapper/{device_name}"));
let mut random_buffer = Box::new([0; WINDOW_SIZE]);
File::open("/dev/urandom")?.read_exact(&mut (*random_buffer))?;
let mut device = OpenOptions::new().write(true).open(mapped_device_path)?;
Expand Down

0 comments on commit 64bdcb2

Please sign in to comment.