diff --git a/examples/more/src/org_example_more.rs b/examples/more/src/org_example_more.rs index f8641a6..d6167e3 100644 --- a/examples/more/src/org_example_more.rs +++ b/examples/more/src/org_example_more.rs @@ -104,18 +104,18 @@ impl From<&varlink::Reply> for ErrorKind { #[allow(unused_variables)] fn from(e: &varlink::Reply) -> Self { match e { - varlink::Reply { - error: Some(ref t), .. - } if t == "org.example.more.TestMoreError" => match e { - varlink::Reply { - parameters: Some(p), - .. - } => match serde_json::from_value(p.clone()) { - Ok(v) => ErrorKind::TestMoreError(v), - Err(_) => ErrorKind::TestMoreError(None), - }, - _ => ErrorKind::TestMoreError(None), - }, + varlink::Reply { error: Some(t), .. } if t == "org.example.more.TestMoreError" => { + match e { + varlink::Reply { + parameters: Some(p), + .. + } => match serde_json::from_value(p.clone()) { + Ok(v) => ErrorKind::TestMoreError(v), + Err(_) => ErrorKind::TestMoreError(None), + }, + _ => ErrorKind::TestMoreError(None), + } + } _ => ErrorKind::VarlinkReply_Error, } } diff --git a/examples/ping/src/org_example_ping.rs b/examples/ping/src/org_example_ping.rs index 6266578..dff802f 100644 --- a/examples/ping/src/org_example_ping.rs +++ b/examples/ping/src/org_example_ping.rs @@ -104,9 +104,7 @@ impl From<&varlink::Reply> for ErrorKind { #[allow(unused_variables)] fn from(e: &varlink::Reply) -> Self { match e { - varlink::Reply { - error: Some(ref t), .. - } if t == "org.example.ping.PingError" => match e { + varlink::Reply { error: Some(t), .. } if t == "org.example.ping.PingError" => match e { varlink::Reply { parameters: Some(p), .. diff --git a/varlink/src/lib.rs b/varlink/src/lib.rs index 069b42a..d188f68 100644 --- a/varlink/src/lib.rs +++ b/varlink/src/lib.rs @@ -1051,11 +1051,7 @@ where let mut req = match (self.method.take(), self.request.take()) { (Some(method), Some(request)) => Request::create( method, - Some( - serde_json::to_value(request) - .map_err(map_context!()) - .map_err(Error::from)?, - ), + Some(serde_json::to_value(request).map_err(map_context!())?), ), _ => { return Err(MError::from(context!(ErrorKind::MethodCalledAlready))); @@ -1082,15 +1078,10 @@ where let mut w = conn.writer.take().unwrap(); - let b = serde_json::to_string(&req) - .map_err(map_context!()) - .map_err(Error::from)? - + "\0"; + let b = serde_json::to_string(&req).map_err(map_context!())? + "\0"; - w.write_all(b.as_bytes()) - .map_err(map_context!()) - .map_err(Error::from)?; - w.flush().map_err(map_context!()).map_err(Error::from)?; + w.write_all(b.as_bytes()).map_err(map_context!())?; + w.flush().map_err(map_context!())?; if oneway { conn.writer = Some(w); } else { @@ -1128,18 +1119,13 @@ where let mut buf = Vec::new(); let mut reader = self.reader.take().unwrap(); - reader - .read_until(0, &mut buf) - .map_err(map_context!()) - .map_err(Error::from)?; + reader.read_until(0, &mut buf).map_err(map_context!())?; self.reader = Some(reader); if buf.is_empty() { return Err(context!(ErrorKind::ConnectionClosed).into()); } buf.pop(); - let reply: Reply = serde_json::from_slice(&buf) - .map_err(map_context!()) - .map_err(Error::from)?; + let reply: Reply = serde_json::from_slice(&buf).map_err(map_context!())?; match reply.continues { Some(true) => self.continues = true, _ => { @@ -1158,9 +1144,7 @@ where parameters: Some(p), .. } => { - let mreply: MReply = serde_json::from_value(p) - .map_err(map_context!()) - .map_err(Error::from)?; + let mreply: MReply = serde_json::from_value(p).map_err(map_context!())?; Ok(mreply) } Reply { @@ -1168,8 +1152,7 @@ where } => { let mreply: MReply = serde_json::from_value(serde_json::Value::Object(serde_json::Map::new())) - .map_err(map_context!()) - .map_err(Error::from)?; + .map_err(map_context!())?; Ok(mreply) } } diff --git a/varlink_generator/src/lib.rs b/varlink_generator/src/lib.rs index b17fb63..626c15c 100644 --- a/varlink_generator/src/lib.rs +++ b/varlink_generator/src/lib.rs @@ -713,7 +713,7 @@ fn generate_error_code( let error_name = format!("{iname}.{ename}", iname = idl.name, ename = t.name); let ename = TokenStream::from_str(&format!("ErrorKind::{}", t.name)).unwrap(); arms.extend(quote!( - varlink::Reply { error: Some(ref t), .. } if t == #error_name => { + varlink::Reply { error: Some(t), .. } if t == #error_name => { match e { varlink::Reply { parameters: Some(p), diff --git a/varlink_generator/tests/org.example.complex.rs_out b/varlink_generator/tests/org.example.complex.rs_out index 339c314..c60c398 100644 --- a/varlink_generator/tests/org.example.complex.rs_out +++ b/varlink_generator/tests/org.example.complex.rs_out @@ -103,9 +103,7 @@ impl From<&varlink::Reply> for ErrorKind { #[allow(unused_variables)] fn from(e: &varlink::Reply) -> Self { match e { - varlink::Reply { - error: Some(ref t), .. - } if t == "org.example.complex.ErrorBar" => match e { + varlink::Reply { error: Some(t), .. } if t == "org.example.complex.ErrorBar" => match e { varlink::Reply { parameters: Some(p), .. @@ -115,9 +113,7 @@ impl From<&varlink::Reply> for ErrorKind { }, _ => ErrorKind::ErrorBar(None), }, - varlink::Reply { - error: Some(ref t), .. - } if t == "org.example.complex.ErrorFoo" => match e { + varlink::Reply { error: Some(t), .. } if t == "org.example.complex.ErrorFoo" => match e { varlink::Reply { parameters: Some(p), ..