Skip to content

Commit

Permalink
some let ... else syntax where it makes code cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
Moritz Borcherding committed Mar 4, 2024
1 parent 00da7a9 commit 6086d52
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
17 changes: 7 additions & 10 deletions rustbus/fuzz/fuzz_targets/fuzz_unmarshal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,20 @@ extern crate rustbus;

fuzz_target!(|data: &[u8]| {
let mut cursor = rustbus::wire::unmarshal_context::Cursor::new(data);
let header = match rustbus::wire::unmarshal::unmarshal_header(&mut cursor) {
Ok(head) => head,
Err(_) => return,
let Ok(header) = rustbus::wire::unmarshal::unmarshal_header(&mut cursor) else {
return;
};
let dynheader = match rustbus::wire::unmarshal::unmarshal_dynamic_header(&header, &mut cursor) {
Ok(head) => head,
Err(_) => return,
let Ok(dynheader) = rustbus::wire::unmarshal::unmarshal_dynamic_header(&header, &mut cursor) else {
return;
};

let msg = match rustbus::wire::unmarshal::unmarshal_next_message(
let Ok(msg) = rustbus::wire::unmarshal::unmarshal_next_message(
&header,
dynheader,
data.to_vec(),
cursor.consumed(),
) {
Ok(msg) => msg,
Err(_) => return,
) else {
return;
};
try_unmarhal_traits(&msg);
msg.unmarshall_all().ok();
Expand Down
18 changes: 8 additions & 10 deletions rustbus/src/bin/fuzz_artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,26 @@ fn run_artifact(path: &str) {
let data = &data;

let mut cursor = Cursor::new(data);
let header = match rustbus::wire::unmarshal::unmarshal_header(&mut cursor) {
Ok(head) => head,
Err(_) => return,
let Ok(header) = rustbus::wire::unmarshal::unmarshal_header(&mut cursor) else {
return;
};

println!("Header: {:?}", header);

let dynheader = match rustbus::wire::unmarshal::unmarshal_dynamic_header(&header, &mut cursor) {
Ok(head) => head,
Err(_) => return,
let Ok(dynheader) = rustbus::wire::unmarshal::unmarshal_dynamic_header(&header, &mut cursor)
else {
return;
};

println!("Dynheader: {:?}", dynheader);

let msg = match rustbus::wire::unmarshal::unmarshal_next_message(
let Ok(msg) = rustbus::wire::unmarshal::unmarshal_next_message(
&header,
dynheader,
data.clone(),
cursor.consumed(),
) {
Ok(msg) => msg,
Err(_) => return,
) else {
return;
};

println!("Message: {:?}", msg);
Expand Down
5 changes: 2 additions & 3 deletions rustbus/src/wire/unmarshal/traits/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,8 @@ impl<'buf, 'fds> Unmarshal<'buf, 'fds> for Variant<'fds, 'buf> {
fn unmarshal(ctx: &mut UnmarshalContext<'fds, 'buf>) -> unmarshal::UnmarshalResult<Self> {
let desc = ctx.read_signature()?;

let mut sigs = match signature::Type::parse_description(desc) {
Ok(sigs) => sigs,
Err(_) => return Err(UnmarshalError::WrongSignature),
let Ok(mut sigs) = signature::Type::parse_description(desc) else {
return Err(UnmarshalError::WrongSignature);
};
if sigs.len() != 1 {
return Err(UnmarshalError::WrongSignature);
Expand Down

0 comments on commit 6086d52

Please sign in to comment.