Skip to content

Commit

Permalink
Fix a few clippy warnings (#226)
Browse files Browse the repository at this point in the history
* Elide lifetimes

* Use one more implicit return

* Reorder some trait impls according to their trait definition order

* Use is_ok_and over map_or

* Move to conditional import
  • Loading branch information
knutwalker authored Feb 12, 2025
1 parent 9c67cd4 commit 4050a43
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 69 deletions.
8 changes: 4 additions & 4 deletions lib/src/bolt/request/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ enum ServerRouting<'a> {
WithContext { context: Box<[(&'a str, &'a str)]> },
}

impl<'a> ServerRouting<'a> {
impl ServerRouting<'_> {
fn is_none(&self) -> bool {
matches!(self, ServerRouting::No)
}
}

impl<'a> Serialize for ServerRouting<'a> {
impl Serialize for ServerRouting<'_> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
Expand All @@ -121,11 +121,11 @@ pub struct Response {
pub(crate) connection_id: String,
}

impl<'a> ExpectedResponse for Hello<'a> {
impl ExpectedResponse for Hello<'_> {
type Response = Summary<Response>;
}

impl<'a> Serialize for Hello<'a> {
impl Serialize for Hello<'_> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/bolt/request/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct Response {
pub rt: RoutingTable,
}

impl<'a> ExpectedResponse for Route<'a> {
impl ExpectedResponse for Route<'_> {
type Response = Summary<Response>;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/src/bolt/structs/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ impl<'a, T> Single<'a, T> {
}
}

impl<'a, 'de, T: Deserialize<'de> + 'de> DeserializeSeed<'de> for Single<'a, T> {
impl<'de, T: Deserialize<'de> + 'de> DeserializeSeed<'de> for Single<'_, T> {
type Value = Option<T>;

fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
Expand All @@ -377,7 +377,7 @@ impl<'a, 'de, T: Deserialize<'de> + 'de> DeserializeSeed<'de> for Single<'a, T>

struct Filter<'a>(&'a str);

impl<'a, 'de> Visitor<'de> for Filter<'a> {
impl<'de> Visitor<'de> for Filter<'_> {
type Value = Key;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
Expand Down Expand Up @@ -435,7 +435,7 @@ impl<'a, 'de, T: Deserialize<'de> + 'de> DeserializeSeed<'de> for Single<'a, T>
}
}

impl<'a, 'de> DeserializeSeed<'de> for Filter<'a> {
impl<'de> DeserializeSeed<'de> for Filter<'_> {
type Value = Key;

fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
Expand All @@ -448,7 +448,7 @@ impl<'a, 'de, T: Deserialize<'de> + 'de> DeserializeSeed<'de> for Single<'a, T>

struct Vis<'a, 'de, T>(&'a str, PhantomData<&'de T>);

impl<'a, 'de, T: Deserialize<'de> + 'de> Visitor<'de> for Vis<'a, 'de, T> {
impl<'de, T: Deserialize<'de> + 'de> Visitor<'de> for Vis<'_, 'de, T> {
type Value = Option<T>;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/bolt/structs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub enum BoltRef<'de> {
LegacyDateTimeZoneId(LegacyDateTimeZoneIdRef<'de>),
}

impl<'de> From<()> for BoltRef<'de> {
impl From<()> for BoltRef<'_> {
fn from(_: ()) -> Self {
Self::Null
}
Expand Down
12 changes: 5 additions & 7 deletions lib/src/bolt/structs/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ impl<'de> Deserialize<'de> for Crs {
{
struct Vis;

impl<'de> serde::de::Visitor<'de> for Vis {
impl serde::de::Visitor<'_> for Vis {
type Value = Crs;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
Expand Down Expand Up @@ -418,12 +418,10 @@ impl<'de> Deserialize<'de> for Point {
match tag {
Some(0x58) => map.next_value::<Point2D>().map(|p| p.to_point()),
Some(0x59) => map.next_value::<Point3D>().map(|p| p.to_point()),
Some(tag) => {
return Err(serde::de::Error::invalid_type(
serde::de::Unexpected::Other(&format!("struct with tag {:02X}", tag)),
&"a Bolt struct (tag {:02X})",
))
}
Some(tag) => Err(serde::de::Error::invalid_type(
serde::de::Unexpected::Other(&format!("struct with tag {:02X}", tag)),
&"a Bolt struct (tag {:02X})",
)),
None => Err(serde::de::Error::missing_field("tag")),
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/packstream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<'de> Deserialize<'de> for RawBytes {
{
struct RawBytesVisitor;

impl<'de> serde::de::Visitor<'de> for RawBytesVisitor {
impl serde::de::Visitor<'_> for RawBytesVisitor {
type Value = Bytes;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
Expand Down
30 changes: 15 additions & 15 deletions lib/src/packstream/ser/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ use ::serde::ser::{
#[derive(Debug, PartialEq, Eq)]
pub struct AsMap<'a, T: ?Sized>(pub &'a T);

impl<'a, T: ?Sized> Copy for AsMap<'a, T> {}
impl<T: ?Sized> Copy for AsMap<'_, T> {}

impl<'a, T: ?Sized> Clone for AsMap<'a, T> {
impl<T: ?Sized> Clone for AsMap<'_, T> {
fn clone(&self) -> Self {
*self
}
}

impl<'a, T: ?Sized + Serialize> Serialize for AsMap<'a, T> {
impl<T: ?Sized + Serialize> Serialize for AsMap<'_, T> {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
as_map(serializer, self.0)
}
Expand Down Expand Up @@ -375,7 +375,7 @@ impl<S: SerializeMap> InnerMapSerializer<S> {
}
}

impl<'a, S: SerializeMap> Serializer for &'a mut InnerMapSerializer<S> {
impl<S: SerializeMap> Serializer for &mut InnerMapSerializer<S> {
type Ok = ();
type Error = S::Error;

Expand Down Expand Up @@ -443,17 +443,17 @@ impl<'a, S: SerializeMap> Serializer for &'a mut InnerMapSerializer<S> {
self.value(v)
}

fn serialize_none(self) -> Result<Self::Ok, Self::Error> {
Ok(())
}

fn serialize_some<T>(self, value: &T) -> Result<Self::Ok, Self::Error>
where
T: Serialize + ?Sized,
{
value.serialize(self)
}

fn serialize_none(self) -> Result<Self::Ok, Self::Error> {
Ok(())
}

fn serialize_unit(self) -> Result<Self::Ok, Self::Error> {
Ok(())
}
Expand Down Expand Up @@ -572,7 +572,7 @@ impl<'a, S: SerializeMap> Serializer for &'a mut InnerMapSerializer<S> {
// }
// }

impl<'a, S: SerializeMap> SerializeSeq for &'a mut InnerMapSerializer<S> {
impl<S: SerializeMap> SerializeSeq for &mut InnerMapSerializer<S> {
type Ok = ();
type Error = S::Error;

Expand Down Expand Up @@ -606,7 +606,7 @@ impl<'a, S: SerializeMap> SerializeSeq for &'a mut InnerMapSerializer<S> {
// }
// }

impl<'a, S: SerializeMap> SerializeTuple for &'a mut InnerMapSerializer<S> {
impl<S: SerializeMap> SerializeTuple for &mut InnerMapSerializer<S> {
type Ok = ();
type Error = S::Error;

Expand Down Expand Up @@ -640,7 +640,7 @@ impl<'a, S: SerializeMap> SerializeTuple for &'a mut InnerMapSerializer<S> {
// }
// }

impl<'a, S: SerializeMap> SerializeTupleStruct for &'a mut InnerMapSerializer<S> {
impl<S: SerializeMap> SerializeTupleStruct for &mut InnerMapSerializer<S> {
type Ok = ();
type Error = S::Error;

Expand Down Expand Up @@ -682,7 +682,7 @@ impl<'a, S: SerializeMap> SerializeTupleStruct for &'a mut InnerMapSerializer<S>
// }
// }

impl<'a, S: SerializeMap> SerializeMap for &'a mut InnerMapSerializer<S> {
impl<S: SerializeMap> SerializeMap for &mut InnerMapSerializer<S> {
type Ok = ();
type Error = S::Error;

Expand Down Expand Up @@ -725,7 +725,7 @@ impl<'a, S: SerializeMap> SerializeMap for &'a mut InnerMapSerializer<S> {
// }
// }

impl<'a, S: SerializeMap> SerializeTupleVariant for &'a mut InnerMapSerializer<S> {
impl<S: SerializeMap> SerializeTupleVariant for &mut InnerMapSerializer<S> {
type Ok = ();
type Error = S::Error;

Expand Down Expand Up @@ -762,7 +762,7 @@ impl<'a, S: SerializeMap> SerializeTupleVariant for &'a mut InnerMapSerializer<S
// }
// }

impl<'a, S: SerializeMap> SerializeStruct for &'a mut InnerMapSerializer<S> {
impl<S: SerializeMap> SerializeStruct for &mut InnerMapSerializer<S> {
type Ok = ();
type Error = S::Error;

Expand Down Expand Up @@ -798,7 +798,7 @@ impl<'a, S: SerializeMap> SerializeStruct for &'a mut InnerMapSerializer<S> {
// }
// }

impl<'a, S: SerializeMap> SerializeStructVariant for &'a mut InnerMapSerializer<S> {
impl<S: SerializeMap> SerializeStructVariant for &mut InnerMapSerializer<S> {
type Ok = ();
type Error = S::Error;

Expand Down
68 changes: 34 additions & 34 deletions lib/src/packstream/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ impl<'a> ser::Serializer for &'a mut Serializer {
}
}

impl<'a> ser::SerializeSeq for &'a mut Serializer {
impl ser::SerializeSeq for &mut Serializer {
type Ok = ();
type Error = Error;

Expand All @@ -360,7 +360,7 @@ impl<'a> ser::SerializeSeq for &'a mut Serializer {
}
}

impl<'a> ser::SerializeTuple for &'a mut Serializer {
impl ser::SerializeTuple for &mut Serializer {
type Ok = ();
type Error = Error;

Expand All @@ -376,7 +376,7 @@ impl<'a> ser::SerializeTuple for &'a mut Serializer {
}
}

impl<'a> ser::SerializeTupleStruct for &'a mut Serializer {
impl ser::SerializeTupleStruct for &mut Serializer {
type Ok = ();
type Error = Error;

Expand All @@ -401,37 +401,10 @@ pub(super) enum MapSerializer<'a> {
},
}

impl<'a> ser::SerializeMap for MapSerializer<'a> {
impl ser::SerializeMap for MapSerializer<'_> {
type Ok = ();
type Error = Error;

fn serialize_entry<K, V>(&mut self, key: &K, value: &V) -> Result<(), Self::Error>
where
K: ser::Serialize + ?Sized,
V: ser::Serialize + ?Sized,
{
if key.serialize(SpecialKeySerializer).is_ok() {
match value.serialize(SpecialValueSerializer) {
Ok(map_size) => match self {
MapSerializer::Known(ser) => ser,
MapSerializer::Unknown { ser, len, .. } => {
let rhs = map_size as isize;
let (res, overflowed) = len.overflowing_sub(rhs);
let overflowed = overflowed ^ (rhs < 0);
let res = if overflowed { isize::MIN } else { res };
*len = res;
ser
}
}
.map_header(map_size),
Err(_) => Err(Error::LengthOverflow),
}
} else {
self.serialize_key(key)?;
self.serialize_value(value)
}
}

fn serialize_key<T>(&mut self, key: &T) -> Result<(), Self::Error>
where
T: ser::Serialize + ?Sized,
Expand Down Expand Up @@ -459,6 +432,33 @@ impl<'a> ser::SerializeMap for MapSerializer<'a> {
value.serialize(&mut **ser)
}

fn serialize_entry<K, V>(&mut self, key: &K, value: &V) -> Result<(), Self::Error>
where
K: ser::Serialize + ?Sized,
V: ser::Serialize + ?Sized,
{
if key.serialize(SpecialKeySerializer).is_ok() {
match value.serialize(SpecialValueSerializer) {
Ok(map_size) => match self {
MapSerializer::Known(ser) => ser,
MapSerializer::Unknown { ser, len, .. } => {
let rhs = map_size as isize;
let (res, overflowed) = len.overflowing_sub(rhs);
let overflowed = overflowed ^ (rhs < 0);
let res = if overflowed { isize::MIN } else { res };
*len = res;
ser
}
}
.map_header(map_size),
Err(_) => Err(Error::LengthOverflow),
}
} else {
self.serialize_key(key)?;
self.serialize_value(value)
}
}

fn end(self) -> Result<Self::Ok, Self::Error> {
if let MapSerializer::Unknown { ser, begin, len } = self {
let len = len.max(0) as usize;
Expand Down Expand Up @@ -495,7 +495,7 @@ impl<'a> ser::SerializeMap for MapSerializer<'a> {
}
}

impl<'a> ser::SerializeStruct for &'a mut Serializer {
impl ser::SerializeStruct for &mut Serializer {
type Ok = ();
type Error = Error;

Expand All @@ -512,7 +512,7 @@ impl<'a> ser::SerializeStruct for &'a mut Serializer {
}
}

impl<'a> ser::SerializeTupleVariant for &'a mut Serializer {
impl ser::SerializeTupleVariant for &mut Serializer {
type Ok = ();
type Error = Error;

Expand All @@ -528,7 +528,7 @@ impl<'a> ser::SerializeTupleVariant for &'a mut Serializer {
}
}

impl<'a> ser::SerializeStructVariant for &'a mut Serializer {
impl ser::SerializeStructVariant for &mut Serializer {
type Ok = ();
type Error = Error;

Expand Down
2 changes: 1 addition & 1 deletion lib/tests/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl Neo4jContainer {
.and_then(|o| std::fs::File::open(o).ok())
.into_iter()
.flat_map(|o| std::io::BufReader::new(o).lines())
.any(|o| o.map_or(false, |line| line.trim() == image_name));
.any(|o| o.is_ok_and(|line| line.trim() == image_name));

if !has_license_acceptance {
return Err(format!(
Expand Down
4 changes: 3 additions & 1 deletion lib/tests/use_default_db.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use futures::TryStreamExt;
use neo4rs::{query, Operation};
use neo4rs::query;
#[cfg(feature = "unstable-bolt-protocol-impl-v2")]
use neo4rs::Operation;

mod container;

Expand Down

0 comments on commit 4050a43

Please sign in to comment.