Skip to content

Commit

Permalink
Merge pull request #123 from saschagrunert/clippy
Browse files Browse the repository at this point in the history
Fix clippy lints
  • Loading branch information
utam0k authored Feb 9, 2023
2 parents a87a74a + 74eaabe commit 560b9aa
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "oci-spec"
version = "0.6.0"
edition = "2018"
edition = "2021"
authors = [
"Furisto",
"Sascha Grunert <sgrunert@redhat.com>",
Expand Down
4 changes: 2 additions & 2 deletions src/distribution/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub struct ErrorResponse {

impl Display for ErrorResponse {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "{}", ERR_REGISTRY)
write!(f, "{ERR_REGISTRY}")
}
}

Expand Down Expand Up @@ -204,7 +204,7 @@ mod tests {
}
}"#;

let error_info: ErrorInfo = serde_json::from_str(&error_info_str)?;
let error_info: ErrorInfo = serde_json::from_str(error_info_str)?;
assert_eq!(error_info.detail().as_ref().unwrap(), "{\"Tag\":\"lates\"}");

Ok(())
Expand Down
5 changes: 1 addition & 4 deletions src/distribution/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ pub const VERSION_DEV: &str = "-dev";

/// Retrieve the version as string representation.
pub fn version() -> String {
format!(
"{}.{}.{}{}",
VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_DEV
)
format!("{VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_PATCH}{VERSION_DEV}")
}

#[cfg(test)]
Expand Down
10 changes: 4 additions & 6 deletions src/image/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ mod tests {
use crate::image::Os;

fn create_config() -> ImageConfiguration {
let configuration = ImageConfigurationBuilder::default()
ImageConfigurationBuilder::default()
.created("2015-10-31T22:22:56.015925234Z".to_owned())
.author("Alyssa P. Hacker <alyspdev@example.com>".to_owned())
.architecture(Arch::Amd64)
Expand Down Expand Up @@ -530,9 +530,7 @@ mod tests {
.expect("build history"),
])
.build()
.expect("build configuration");

configuration
.expect("build configuration")
}

fn get_config_path() -> PathBuf {
Expand All @@ -559,11 +557,11 @@ mod tests {

// act
let actual = ImageConfiguration::from_reader(&*reader).expect("from reader");
println!("{:#?}", actual);
println!("{actual:#?}");

// assert
let expected = create_config();
println!("{:#?}", expected);
println!("{expected:#?}");

assert_eq!(actual, expected);
}
Expand Down
6 changes: 2 additions & 4 deletions src/image/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,11 @@ mod tests {
.build()
.expect("build amd64 manifest descriptor");

let index = ImageIndexBuilder::default()
ImageIndexBuilder::default()
.schema_version(SCHEMA_VERSION)
.manifests(vec![ppc_manifest, amd64_manifest])
.build()
.expect("build image index");

index
.expect("build image index")
}

fn get_index_path() -> PathBuf {
Expand Down
6 changes: 2 additions & 4 deletions src/image/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,12 @@ mod tests {
})
.collect();

let manifest = ImageManifestBuilder::default()
ImageManifestBuilder::default()
.schema_version(SCHEMA_VERSION)
.config(config)
.layers(layers)
.build()
.expect("build image manifest");

manifest
.expect("build image manifest")
}

fn get_manifest_path() -> PathBuf {
Expand Down
19 changes: 9 additions & 10 deletions src/image/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl Display for MediaType {
),
Self::ImageConfig => write!(f, "application/vnd.oci.image.config.v1+json"),
Self::ArtifactManifest => write!(f, "application/vnd.oci.artifact.manifest.v1+json"),
Self::Other(media_type) => write!(f, "{}", media_type),
Self::Other(media_type) => write!(f, "{media_type}"),
}
}
}
Expand Down Expand Up @@ -146,7 +146,7 @@ impl Serialize for MediaType {
where
S: serde::Serializer,
{
let media_type = format!("{}", self);
let media_type = format!("{self}");
media_type.serialize(serializer)
}
}
Expand Down Expand Up @@ -235,7 +235,7 @@ impl Display for Os {
Os::Other(name) => name,
};

write!(f, "{}", print)
write!(f, "{print}")
}
}

Expand All @@ -244,7 +244,7 @@ impl Serialize for Os {
where
S: serde::Serializer,
{
let os = format!("{}", self);
let os = format!("{self}");
os.serialize(serializer)
}
}
Expand Down Expand Up @@ -353,7 +353,7 @@ impl Display for Arch {
Arch::Other(arch) => arch,
};

write!(f, "{}", print)
write!(f, "{print}")
}
}

Expand Down Expand Up @@ -394,7 +394,7 @@ impl Serialize for Arch {
where
S: serde::Serializer,
{
let arch = format!("{}", self);
let arch = format!("{self}");
arch.serialize(serializer)
}
}
Expand Down Expand Up @@ -433,10 +433,9 @@ mod tests {
#[test]
fn test_arch_translation() {
let a = Arch::default();
match a {
// If you hit this, please update the mapping above.
Arch::Other(o) => panic!("Architecture {} not mapped between Rust and OCI", o),
_ => {}
// If you hit this, please update the mapping above.
if let Arch::Other(o) = a {
panic!("Architecture {o} not mapped between Rust and OCI")
}
}
}
5 changes: 1 addition & 4 deletions src/image/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ pub const VERSION_DEV: &str = "-dev";

/// Retrieve the version as string representation.
pub fn version() -> String {
format!(
"{}.{}.{}{}",
VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_DEV
)
format!("{VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_PATCH}{VERSION_DEV}")
}

#[cfg(test)]
Expand Down
5 changes: 2 additions & 3 deletions src/runtime/capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,7 @@ impl<'de> Deserialize<'de> for Capability {
"SYSLOG" => Ok(Self::Syslog),
"WAKE_ALARM" => Ok(Self::WakeAlarm),
other => Err(Error::custom(format!(
"no variant for {} (converted to {})",
input, other,
"no variant for {input} (converted to {other})",
))),
}
}
Expand All @@ -589,7 +588,7 @@ mod tests {
#[test]
fn deserialize() -> Result<()> {
for case in &["SYSLOG", "CAP_SYSLOG", "cap_SYSLOG", "sySloG"] {
let res: Capability = serde_json::from_str(&format!("\"{}\"", case))?;
let res: Capability = serde_json::from_str(&format!("\"{case}\""))?;
assert_eq!(Capability::Syslog, res);
}
Ok(())
Expand Down
3 changes: 1 addition & 2 deletions src/runtime/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,8 +767,7 @@ impl TryFrom<&str> for LinuxNamespaceType {
"pid" => Ok(LinuxNamespaceType::Pid),
"net" => Ok(LinuxNamespaceType::Network),
_ => Err(oci_error(format!(
"unknown namespace {}, could not convert",
namespace
"unknown namespace {namespace}, could not convert"
))),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ fn test_load_sample_spec() {
let fixture_path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("src/runtime/test/fixture/sample.json");
let err = Spec::load(fixture_path);
assert!(err.is_ok(), "failed to load spec: {:?}", err);
assert!(err.is_ok(), "failed to load spec: {err:?}");
}
5 changes: 1 addition & 4 deletions src/runtime/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ pub const VERSION_DEV: &str = "-dev";

/// Retrieve the version as string representation.
pub fn version() -> String {
format!(
"{}.{}.{}{}",
VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_DEV
)
format!("{VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_PATCH}{VERSION_DEV}")
}

#[cfg(test)]
Expand Down

0 comments on commit 560b9aa

Please sign in to comment.