Skip to content

Commit

Permalink
[Rust] Resolve Clippy warnings (#80)
Browse files Browse the repository at this point in the history
* fix: struct `AsPath` is never constructed

Signed-off-by: jaudiger <[email protected]>

* fix: assigning the result of `ToOwned::to_owned()` may be inefficient

Signed-off-by: jaudiger <[email protected]>

---------

Signed-off-by: jaudiger <[email protected]>
  • Loading branch information
jaudiger authored Jul 6, 2024
1 parent 79e3211 commit c1c27e0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 36 deletions.
2 changes: 1 addition & 1 deletion crates/brioche-core/src/script/compiler_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl BriocheCompilerHost {
doc.version += 1;

let doc_contents = Arc::make_mut(&mut doc.contents);
*doc_contents = contents.to_owned();
contents.clone_into(doc_contents);
}
})
.or_insert_with(|| {
Expand Down
36 changes: 1 addition & 35 deletions crates/brioche-pack/src/encoding.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::{borrow::Cow, path::PathBuf};

use bstr::{ByteSlice, ByteVec as _};
use std::borrow::Cow;

pub enum TickEncoded {}

Expand Down Expand Up @@ -33,35 +31,3 @@ where
Ok(deserialized)
}
}

pub struct AsPath<T>(std::marker::PhantomData<T>);

impl<T> serde_with::SerializeAs<PathBuf> for AsPath<T>
where
T: serde_with::SerializeAs<Vec<u8>>,
{
fn serialize_as<S>(source: &PathBuf, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let bytes = Vec::<u8>::from_path_buf(source.clone())
.map_err(|_| serde::ser::Error::custom("invalid path"))?;
T::serialize_as(&bytes, serializer)
}
}

impl<'de, T> serde_with::DeserializeAs<'de, PathBuf> for AsPath<T>
where
T: serde_with::DeserializeAs<'de, Vec<u8>>,
{
fn deserialize_as<D>(deserializer: D) -> Result<PathBuf, D::Error>
where
D: serde::Deserializer<'de>,
{
let bytes: Vec<u8> = T::deserialize_as(deserializer)?;
let path = bytes
.to_path()
.map_err(|_| serde::de::Error::custom("invalid path"))?;
Ok(path.to_owned())
}
}

0 comments on commit c1c27e0

Please sign in to comment.