Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions examples/more/src/org_example_more.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
4 changes: 1 addition & 3 deletions examples/ping/src/org_example_ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
..
Expand Down
33 changes: 8 additions & 25 deletions varlink/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
_ => {
Expand All @@ -1158,18 +1144,15 @@ 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 {
parameters: None, ..
} => {
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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion varlink_generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
8 changes: 2 additions & 6 deletions varlink_generator/tests/org.example.complex.rs_out
Original file line number Diff line number Diff line change
Expand Up @@ -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),
..
Expand All @@ -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),
..
Expand Down
Loading