diff --git a/watchman/rust/serde_bser/src/bytestring.rs b/watchman/rust/serde_bser/src/bytestring.rs index 4b0fb9c6601d..3567f1267073 100644 --- a/watchman/rust/serde_bser/src/bytestring.rs +++ b/watchman/rust/serde_bser/src/bytestring.rs @@ -189,7 +189,7 @@ impl TryInto for PathBuf { type Error = &'static str; fn try_into(self) -> Result { - Ok(self.into_os_string().try_into()?) + self.into_os_string().try_into() } } diff --git a/watchman/rust/serde_bser/src/de/bunser.rs b/watchman/rust/serde_bser/src/de/bunser.rs index 3f1690154b8b..d42fb634663a 100644 --- a/watchman/rust/serde_bser/src/de/bunser.rs +++ b/watchman/rust/serde_bser/src/de/bunser.rs @@ -151,7 +151,7 @@ where BSER_INT8 => self.next_i8()? as i64, BSER_INT16 => self.next_i16()? as i64, BSER_INT32 => self.next_i32()? as i64, - BSER_INT64 => self.next_i64()? as i64, + BSER_INT64 => self.next_i64()?, ch => { return Err(Error::DeInvalidStartByte { kind: "integer".into(), diff --git a/watchman/rust/serde_bser/src/de/mod.rs b/watchman/rust/serde_bser/src/de/mod.rs index f51b240d1962..cb68b1f7082d 100644 --- a/watchman/rust/serde_bser/src/de/mod.rs +++ b/watchman/rust/serde_bser/src/de/mod.rs @@ -180,7 +180,7 @@ where match self .bunser .read_bytes(len)? - .map_result(|x| str::from_utf8(x)) + .map_result(str::from_utf8) .map_err(Error::de_reader_error)? { Reference::Borrowed(s) => visitor.visit_borrowed_str(s), @@ -277,12 +277,10 @@ where } visitor.visit_enum(variant::VariantAccess::new(self, &guard)) } - ch => { - return Err(Error::DeInvalidStartByte { - kind: format!("enum '{}'", name), - byte: ch, - }); - } + ch => Err(Error::DeInvalidStartByte { + kind: format!("enum '{}'", name), + byte: ch, + }), } } diff --git a/watchman/rust/watchman_client/src/expr.rs b/watchman/rust/watchman_client/src/expr.rs index 241f17553faa..4ba6300ebebe 100644 --- a/watchman/rust/watchman_client/src/expr.rs +++ b/watchman/rust/watchman_client/src/expr.rs @@ -85,32 +85,32 @@ pub enum Expr { FileType(FileType), } -impl Into for Expr { - fn into(self) -> Value { - match self { - Self::True => "true".into(), - Self::False => "false".into(), - Self::Not(expr) => Value::Array(vec!["not".into(), (*expr).into()]), - Self::All(expr) => { +impl From for Value { + fn from(val: Expr) -> Self { + match val { + Expr::True => "true".into(), + Expr::False => "false".into(), + Expr::Not(expr) => Value::Array(vec!["not".into(), (*expr).into()]), + Expr::All(expr) => { let mut expr: Vec = expr.into_iter().map(Into::into).collect(); expr.insert(0, "allof".into()); Value::Array(expr) } - Self::Any(expr) => { + Expr::Any(expr) => { let mut expr: Vec = expr.into_iter().map(Into::into).collect(); expr.insert(0, "anyof".into()); Value::Array(expr) } - Self::DirName(term) => { + Expr::DirName(term) => { let mut expr: Vec = vec!["dirname".into(), term.path.try_into().unwrap()]; if let Some(depth) = term.depth { expr.push(depth.into_term("depth")); } expr.into() } - Self::Empty => "empty".into(), - Self::Exists => "exists".into(), - Self::Match(term) => vec![ + Expr::Empty => "empty".into(), + Expr::Exists => "exists".into(), + Expr::Match(term) => vec![ "match".into(), term.glob.into(), if term.wholename { @@ -125,7 +125,7 @@ impl Into for Expr { }), ] .into(), - Self::Name(term) => vec![ + Expr::Name(term) => vec![ "name".into(), Value::Array( term.paths @@ -141,7 +141,7 @@ impl Into for Expr { .into(), ] .into(), - Self::Pcre(term) => vec![ + Expr::Pcre(term) => vec![ "pcre".into(), term.pattern.into(), if term.wholename { @@ -152,7 +152,7 @@ impl Into for Expr { .into(), ] .into(), - Self::Since(term) => match term { + Expr::Since(term) => match term { SinceTerm::ObservedClock(c) => { vec!["since".into(), c.into(), "oclock".into()].into() } @@ -166,13 +166,13 @@ impl Into for Expr { vec!["since".into(), c.to_string().into(), "ctime".into()].into() } }, - Self::Size(term) => term.into_term("size"), - Self::Suffix(term) => vec![ + Expr::Size(term) => term.into_term("size"), + Expr::Suffix(term) => vec![ "suffix".into(), Value::Array(term.into_iter().map(|p| p.try_into().unwrap()).collect()), ] .into(), - Self::FileType(term) => vec!["type".into(), term.to_string().into()].into(), + Expr::FileType(term) => vec!["type".into(), term.to_string().into()].into(), } } } diff --git a/watchman/rust/watchman_client/src/lib.rs b/watchman/rust/watchman_client/src/lib.rs index a53e60a48cbe..7cdc1828a37c 100644 --- a/watchman/rust/watchman_client/src/lib.rs +++ b/watchman/rust/watchman_client/src/lib.rs @@ -220,11 +220,10 @@ impl Connector { let watchman_path = self .watchman_cli_path .as_ref() - .map(|p| p.as_ref()) - .unwrap_or_else(|| Path::new("watchman")); + .map_or_else(|| Path::new("watchman"), |p| p.as_ref()); let mut cmd = Command::new(watchman_path); - cmd.args(&["--output-encoding", "bser-v2", "get-sockname"]); + cmd.args(["--output-encoding", "bser-v2", "get-sockname"]); #[cfg(windows)] cmd.creation_flags(winapi::um::winbase::CREATE_NO_WINDOW); @@ -630,7 +629,7 @@ fn bunser(buf: &[u8]) -> Result where T: serde::de::DeserializeOwned, { - let response: T = serde_bser::from_slice(&buf).map_err(|source| Error::Deserialize { + let response: T = serde_bser::from_slice(buf).map_err(|source| Error::Deserialize { source: source.into(), data: buf.to_vec(), })?; @@ -1191,7 +1190,7 @@ mod tests { let reader = StreamReader::new(stream::iter(chunks)); - let decoded = FramedRead::new(reader, BserSplitter) + FramedRead::new(reader, BserSplitter) .map_err(TaskError::from) .and_then(|bytes| async move { // We unwrap this since a) this is a test and b) serde_bser's errors aren't @@ -1201,9 +1200,7 @@ mod tests { }) .try_collect() .await - .unwrap(); - - decoded + .unwrap() } let msgs = vec![ diff --git a/watchman/rust/watchman_client/src/pdu.rs b/watchman/rust/watchman_client/src/pdu.rs index f4a2a4df2c4e..3fe3db4af3b1 100644 --- a/watchman/rust/watchman_client/src/pdu.rs +++ b/watchman/rust/watchman_client/src/pdu.rs @@ -8,6 +8,7 @@ //! This module defines the request and response PDU types used by the //! watchman protocol. +use std::fmt; use std::path::PathBuf; use serde::Deserialize; @@ -144,9 +145,9 @@ impl From for SettleDurationMs { } } -impl Into for SettleDurationMs { - fn into(self) -> i64 { - self.0.as_millis() as i64 +impl From for i64 { + fn from(val: SettleDurationMs) -> Self { + val.0.as_millis() as i64 } } @@ -203,9 +204,9 @@ impl From for SyncTimeout { } } -impl Into for SyncTimeout { - fn into(self) -> i64 { - match self { +impl From for i64 { + fn from(val: SyncTimeout) -> Self { + match val { // This is only really here because the `ClockRequestParams` PDU // treats a missing sync_timeout as `DisableCookie`, whereas // the `QueryRequestCommon` PDU treats it as `Default`. @@ -215,9 +216,9 @@ impl Into for SyncTimeout { // default behavior, we use the current default sync timeout here. // We're honestly not likely to change this, so this should be fine. // The server uses 1 minute; the value here is expressed in milliseconds. - Self::Default => 60_000, - Self::DisableCookie => 0, - Self::Duration(d) => d.as_millis() as i64, + SyncTimeout::Default => 60_000, + SyncTimeout::DisableCookie => 0, + SyncTimeout::Duration(d) => d.as_millis() as i64, } } } @@ -657,11 +658,11 @@ impl ClockSpec { } } -impl Into for ClockSpec { - fn into(self) -> Value { - match self { - Self::StringClock(st) => Value::Utf8String(st), - Self::UnixTimestamp(ts) => Value::Integer(ts), +impl From for Value { + fn from(val: ClockSpec) -> Self { + match val { + ClockSpec::StringClock(st) => Value::Utf8String(st), + ClockSpec::UnixTimestamp(ts) => Value::Integer(ts), } } } @@ -755,9 +756,9 @@ pub enum FileType { Unknown, } -impl std::string::ToString for FileType { - fn to_string(&self) -> String { - (*self).into() +impl fmt::Display for FileType { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + f.write_str(&String::from(*self)) } } @@ -778,18 +779,18 @@ impl From for FileType { } } -impl Into for FileType { - fn into(self) -> String { - match self { - Self::BlockSpecial => "b", - Self::CharSpecial => "c", - Self::Directory => "d", - Self::Regular => "f", - Self::Fifo => "p", - Self::Symlink => "l", - Self::Socket => "s", - Self::SolarisDoor => "D", - Self::Unknown => "?", +impl From for String { + fn from(val: FileType) -> Self { + match val { + FileType::BlockSpecial => "b", + FileType::CharSpecial => "c", + FileType::Directory => "d", + FileType::Regular => "f", + FileType::Fifo => "p", + FileType::Symlink => "l", + FileType::Socket => "s", + FileType::SolarisDoor => "D", + FileType::Unknown => "?", } .to_string() }