mirror of
https://github.com/deuxfleurs-org/garage.git
synced 2026-08-06 04:47:42 +00:00
style: improve use of std api
- replace get(0) by first() lint message: accessing first element with `objs.get(0)` help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#get_first - use io::Error::other method available since Rust 1.87 lint message: this can be `std::io::Error::other(_)` help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#io_other_error - implement From<_> instead of Into<_> lint message: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true help: `impl From<Local> for Foreign` is allowed by the orphan rules, for more information see https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#from_over_into - use next_back instead of rev + next lint message: manual backwards iteration help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#manual_next_back - use saturating_sub instead of manual implement it lint message: manual arithmetic check found help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#implicit_saturating_sub - add Default implementation for Checksummer use derived Default ans use it in new, as new set all value to None lint message: you should consider adding a `Default` implementation for `Checksummer` help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#new_without_default - use `any` instead of `find` + `is_some` lint message: called `is_some()` after searching an `Iterator` with `find` help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#search_is_some - replace `and_then` + `Some(_)` with `map` lint message: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)` help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#bind_instead_of_map - replace `skip_while` + `next` with `find` lint message: called `skip_while(<p>).next()` on an `Iterator` help: this is more succinctly expressed by calling `.find(!<p>)` instead help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#skip_while_next - use `matches!` instead of manual implementation lint message: match expression looks like `matches!` macro help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#match_like_matches_macro - use `keys` and `values methods insteads of iterating and ignoring either the keys or values. help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#iter_kv_map
This commit is contained in:
@@ -380,9 +380,9 @@ impl From<layout::ZoneRedundancy> for ZoneRedundancy {
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<layout::ZoneRedundancy> for ZoneRedundancy {
|
||||
fn into(self) -> layout::ZoneRedundancy {
|
||||
match self {
|
||||
impl From<ZoneRedundancy> for layout::ZoneRedundancy {
|
||||
fn from(val: ZoneRedundancy) -> Self {
|
||||
match val {
|
||||
ZoneRedundancy::Maximum => layout::ZoneRedundancy::Maximum,
|
||||
ZoneRedundancy::AtLeast(x) => layout::ZoneRedundancy::AtLeast(x),
|
||||
}
|
||||
@@ -397,10 +397,10 @@ impl From<layout::LayoutParameters> for LayoutParameters {
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<layout::LayoutParameters> for LayoutParameters {
|
||||
fn into(self) -> layout::LayoutParameters {
|
||||
impl From<LayoutParameters> for layout::LayoutParameters {
|
||||
fn from(val: LayoutParameters) -> Self {
|
||||
layout::LayoutParameters {
|
||||
zone_redundancy: self.zone_redundancy.into(),
|
||||
zone_redundancy: val.zone_redundancy.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ pub struct ExpectedChecksums {
|
||||
pub extra: Option<ChecksumValue>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Checksummer {
|
||||
pub crc32: Option<CrcDigest>,
|
||||
pub crc32c: Option<CrcDigest>,
|
||||
@@ -84,14 +85,7 @@ pub struct Checksums {
|
||||
|
||||
impl Checksummer {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
crc32: None,
|
||||
crc32c: None,
|
||||
crc64nvme: None,
|
||||
md5: None,
|
||||
sha1: None,
|
||||
sha256: None,
|
||||
}
|
||||
Default::default()
|
||||
}
|
||||
|
||||
pub fn init(expected: &ExpectedChecksums, add_md5: bool) -> Self {
|
||||
|
||||
@@ -29,7 +29,7 @@ async fn handle_delete_internal(ctx: &ReqCtx, key: &str) -> Result<(Uuid, Uuid),
|
||||
.iter()
|
||||
.rev()
|
||||
.find(|v| !matches!(&v.state, ObjectVersionState::Aborted))
|
||||
.or_else(|| object.versions().iter().rev().next());
|
||||
.or_else(|| object.versions().iter().next_back());
|
||||
let deleted_version = match deleted_version {
|
||||
Some(dv) => dv.uuid,
|
||||
None => {
|
||||
|
||||
@@ -94,10 +94,7 @@ impl EncryptionParams {
|
||||
// data blocks are reused as-is. Since Garage v2, we are using
|
||||
// object-specific encryption keys, so we know that if both source
|
||||
// and destination are encrypted, it can't be with the same key.
|
||||
match (a, b) {
|
||||
(Self::Plaintext, Self::Plaintext) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!((a, b), (Self::Plaintext, Self::Plaintext))
|
||||
}
|
||||
|
||||
pub fn new_from_headers(
|
||||
@@ -587,8 +584,7 @@ impl Stream for DecryptStream {
|
||||
|
||||
if matches!(this.state, DecryptStreamState::Done) {
|
||||
if !this.buf.is_empty() {
|
||||
return Poll::Ready(Some(Err(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
return Poll::Ready(Some(Err(std::io::Error::other(
|
||||
"Decrypt: unexpected bytes after last encrypted chunk",
|
||||
))));
|
||||
}
|
||||
@@ -622,10 +618,7 @@ impl Stream for DecryptStream {
|
||||
match res {
|
||||
Ok(bytes) if bytes.is_empty() => Poll::Ready(None),
|
||||
Ok(bytes) => Poll::Ready(Some(Ok(bytes.into()))),
|
||||
Err(_) => Poll::Ready(Some(Err(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
"Decryption failed",
|
||||
)))),
|
||||
Err(_) => Poll::Ready(Some(Err(std::io::Error::other("Decryption failed")))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-18
@@ -400,15 +400,10 @@ async fn handle_get_full(
|
||||
overrides: GetObjectOverrides,
|
||||
checksum_mode: ChecksumMode,
|
||||
) -> Result<Response<ResBody>, Error> {
|
||||
let mut resp_builder = object_headers(
|
||||
version,
|
||||
version_meta,
|
||||
meta_inner,
|
||||
encryption,
|
||||
checksum_mode,
|
||||
)
|
||||
.header(CONTENT_LENGTH, format!("{}", version_meta.size))
|
||||
.status(StatusCode::OK);
|
||||
let mut resp_builder =
|
||||
object_headers(version, version_meta, meta_inner, encryption, checksum_mode)
|
||||
.header(CONTENT_LENGTH, format!("{}", version_meta.size))
|
||||
.status(StatusCode::OK);
|
||||
getobject_override_headers(overrides, &mut resp_builder)?;
|
||||
|
||||
let stream = full_object_byte_stream(garage, version, version_data, encryption);
|
||||
@@ -708,11 +703,7 @@ fn body_from_blocks_range(
|
||||
Some(None)
|
||||
} else {
|
||||
// The chunk has an intersection with the requested range
|
||||
let start_in_chunk = if *chunk_offset > begin {
|
||||
0
|
||||
} else {
|
||||
begin - *chunk_offset
|
||||
};
|
||||
let start_in_chunk = begin.saturating_sub(*chunk_offset);
|
||||
let end_in_chunk = if *chunk_offset + chunk_len < end {
|
||||
chunk_len
|
||||
} else {
|
||||
@@ -773,10 +764,7 @@ fn error_stream_item<E: std::fmt::Display>(e: E) -> ByteStream {
|
||||
}
|
||||
|
||||
fn std_error_from_read_error<E: std::fmt::Display>(e: E) -> std::io::Error {
|
||||
std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
format!("Error while reading object data: {}", e),
|
||||
)
|
||||
std::io::Error::other(format!("Error while reading object data: {}", e))
|
||||
}
|
||||
|
||||
// ----
|
||||
|
||||
+2
-2
@@ -1014,12 +1014,12 @@ mod tests {
|
||||
|
||||
query.common.prefix = "a/".to_string();
|
||||
assert_eq!(
|
||||
common_prefix(objs.get(0).unwrap(), &query.common),
|
||||
common_prefix(objs.first().unwrap(), &query.common),
|
||||
Some("a/b/")
|
||||
);
|
||||
|
||||
query.common.prefix = "a/b/".to_string();
|
||||
assert_eq!(common_prefix(objs.get(0).unwrap(), &query.common), None);
|
||||
assert_eq!(common_prefix(objs.first().unwrap(), &query.common), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user