Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
KillingSpark committed Feb 28, 2024
1 parent 6b30253 commit 13d306e
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 70 deletions.
2 changes: 1 addition & 1 deletion rustbus/src/wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
pub mod errors;
pub mod marshal;
pub mod unmarshal;
pub mod unmarshal_context;
pub mod util;
pub mod validate_raw;
pub mod variant_macros;
pub mod unmarshal_context;

mod wrapper_types;
pub use wrapper_types::unixfd::UnixFd;
Expand Down
15 changes: 3 additions & 12 deletions rustbus/src/wire/unmarshal/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,8 @@ impl<'a, 'parent> DictEntryIter<'a> {
let iter = if self.counter == 0 {
// read the key value

let mut ctx = UnmarshalContext::new(
&[],
self.byteorder,
self.source,
*self.current_offset,
);
let mut ctx =
UnmarshalContext::new(&[], self.byteorder, self.source, *self.current_offset);

match unmarshal_base(self.key_sig, &mut ctx) {
Ok((bytes, param)) => {
Expand Down Expand Up @@ -241,12 +237,7 @@ impl<'a, 'parent> ParamIter<'a> {

match new_sig {
signature::Type::Base(b) => {
let mut ctx = UnmarshalContext::new(
&[],
byteorder,
source,
*offset,
);
let mut ctx = UnmarshalContext::new(&[], byteorder, source, *offset);
match unmarshal_base(*b, &mut ctx) {
Ok((bytes, param)) => {
*offset += bytes;
Expand Down
7 changes: 3 additions & 4 deletions rustbus/src/wire/unmarshal/param/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::params;
use crate::signature;
use crate::wire::errors::UnmarshalError;
use crate::wire::unmarshal::base::unmarshal_base;
use crate::wire::unmarshal_context::UnmarshalContext;
use crate::wire::unmarshal::UnmarshalResult;
use crate::wire::unmarshal_context::UnmarshalContext;

pub fn unmarshal_with_sig(
sig: &signature::Type,
Expand Down Expand Up @@ -35,7 +35,7 @@ pub fn unmarshal_variant(
return Err(UnmarshalError::WrongSignature);
}
let sig = sig.remove(0);

let (param_bytes_used, param) = unmarshal_with_sig(&sig, ctx)?;
Ok((
sig_bytes_used + param_bytes_used,
Expand All @@ -52,7 +52,6 @@ pub fn unmarshal_container(
let start_len = ctx.remainder().len();

let (bytes_in_len, bytes_in_array) = ctx.read_u32()?;


ctx.align_to(elem_sig.get_alignment())?;

Expand Down Expand Up @@ -85,7 +84,7 @@ pub fn unmarshal_container(
let mut bytes_used_counter = 0;
while bytes_used_counter < bytes_in_dict as usize {
bytes_used_counter += ctx.align_to(8)?;

let (key_bytes, key) = unmarshal_base(*key_sig, ctx)?;
bytes_used_counter += key_bytes;

Expand Down
16 changes: 4 additions & 12 deletions rustbus/src/wire/unmarshal/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,9 @@ mod test {

original.marshal(ctx).unwrap();

let (_, map) = std::collections::HashMap::<u64, &str>::unmarshal(&mut UnmarshalContext::new(
ctx.fds,
ctx.byteorder,
ctx.buf,
0,
))
let (_, map) = std::collections::HashMap::<u64, &str>::unmarshal(
&mut UnmarshalContext::new(ctx.fds, ctx.byteorder, ctx.buf, 0),
)
.unwrap();
assert_eq!(original, map);

Expand Down Expand Up @@ -354,12 +351,7 @@ mod test {
);
let (_, (p, s, _fd)) =
<(ObjectPath<String>, SignatureWrapper<&str>, UnixFd) as Unmarshal>::unmarshal(
&mut UnmarshalContext::new(
ctx.fds,
ctx.byteorder,
ctx.buf,
0,
),
&mut UnmarshalContext::new(ctx.fds, ctx.byteorder, ctx.buf, 0),
)
.unwrap();

Expand Down
17 changes: 6 additions & 11 deletions rustbus/src/wire/unmarshal/traits/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ where

ctx.align_to(8)?;
let (_bytes, val1) = E1::unmarshal(ctx)?;

ctx.align_to(E2::alignment())?;
let (_bytes, val2) = E2::unmarshal(ctx)?;
eprintln!("C");

ctx.align_to(E3::alignment())?;
let (_bytes, val3) = E3::unmarshal(ctx)?;

let total_bytes = start_len - ctx.remainder().len();
Ok((total_bytes, (val1, val2, val3)))
}
Expand All @@ -82,7 +82,6 @@ where
ctx.align_to(E3::alignment())?;
let (_bytes, val3) = E3::unmarshal(ctx)?;


ctx.align_to(E4::alignment())?;
let (_bytes, val4) = E4::unmarshal(ctx)?;

Expand Down Expand Up @@ -301,13 +300,9 @@ impl<'buf, 'fds> Unmarshal<'buf, 'fds> for Variant<'fds, 'buf> {

ctx.align_to(sig.get_alignment())?;

let val_bytes = crate::wire::validate_raw::validate_marshalled(
ctx.byteorder,
0,
ctx.remainder(),
&sig,
)
.map_err(|e| e.1)?;
let val_bytes =
crate::wire::validate_raw::validate_marshalled(ctx.byteorder, 0, ctx.remainder(), &sig)
.map_err(|e| e.1)?;

let (_, raw_content) = ctx.read_raw(val_bytes)?;

Expand Down
4 changes: 2 additions & 2 deletions rustbus/src/wire/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ pub fn unmarshal_signature(buf: &[u8]) -> UnmarshalResult<&str> {
return Err(UnmarshalError::NotEnoughBytes);
}
let sig_buf = &buf[1..][..len];
let string = std::str::from_utf8(sig_buf)
.map_err(|_| crate::params::validation::Error::InvalidUtf8)?;
let string =
std::str::from_utf8(sig_buf).map_err(|_| crate::params::validation::Error::InvalidUtf8)?;
Ok((len + 2, string))
}

Expand Down
35 changes: 8 additions & 27 deletions rustbus/src/wire/variant_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,10 @@ fn test_variant_sig_macro() {
)
.unwrap();

let (bytes, (uv1, uv2, uv3)) =
<(MyVariant, MyVariant, MyVariant) as Unmarshal>::unmarshal(&mut UnmarshalContext::new(
ctx.fds,
ctx.byteorder,
ctx.buf,
0,
))
.unwrap();
let (bytes, (uv1, uv2, uv3)) = <(MyVariant, MyVariant, MyVariant) as Unmarshal>::unmarshal(
&mut UnmarshalContext::new(ctx.fds, ctx.byteorder, ctx.buf, 0),
)
.unwrap();
assert_eq!(uv1, v1);
assert_ne!(uv1, v2);
assert_ne!(uv1, v3);
Expand Down Expand Up @@ -209,12 +205,7 @@ fn test_variant_sig_macro() {
(&v1, &v2, &v3, &v4).marshal(ctx).unwrap();
let (_bytes, (uv1, uv2, uv3, uv4)) =
<(MyVariant2, MyVariant2, MyVariant2, MyVariant2) as Unmarshal>::unmarshal(
&mut UnmarshalContext::new(
ctx.fds,
ctx.byteorder,
ctx.buf,
0,
),
&mut UnmarshalContext::new(ctx.fds, ctx.byteorder, ctx.buf, 0),
)
.unwrap();
assert_eq!(uv1, v1);
Expand Down Expand Up @@ -419,12 +410,7 @@ fn test_variant_var_macro() {

let (bytes, (uv1, uv2, uv3, uv4)) =
<(MyVariant, MyVariant, MyVariant, MyVariant) as Unmarshal>::unmarshal(
&mut UnmarshalContext::new(
ctx.fds,
ctx.byteorder,
ctx.buf,
0,
),
&mut UnmarshalContext::new(ctx.fds, ctx.byteorder, ctx.buf, 0),
)
.unwrap();
assert!(match uv1 {
Expand All @@ -447,7 +433,7 @@ fn test_variant_var_macro() {
eprintln!("Buffer: {:?}", ctx.buf);
eprintln!("Buffer: {:?}", &ctx.buf[bytes..]);

let (_bytes, uv4) = MyVariant::unmarshal(&mut UnmarshalContext::new (
let (_bytes, uv4) = MyVariant::unmarshal(&mut UnmarshalContext::new(
ctx.fds,
ctx.byteorder,
ctx.buf,
Expand Down Expand Up @@ -480,12 +466,7 @@ fn test_variant_var_macro() {
(&v1, &v2, &v3, &v4).marshal(ctx).unwrap();
let (_bytes, (uv1, uv2, uv3, uv4)) =
<(MyVariant2, MyVariant2, MyVariant2, MyVariant2) as Unmarshal>::unmarshal(
&mut UnmarshalContext::new(
ctx.fds,
ctx.byteorder,
ctx.buf,
0,
),
&mut UnmarshalContext::new(ctx.fds, ctx.byteorder, ctx.buf, 0),
)
.unwrap();
assert!(match uv1 {
Expand Down
2 changes: 1 addition & 1 deletion rustbus_derive/src/variants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pub fn make_variant_unmarshal_impl(
fn unmarshal(ctx: &mut ::rustbus::wire::unmarshal_context::UnmarshalContext<'_,'__internal_buf>) -> Result<(usize,Self), ::rustbus::wire::errors::UnmarshalError> {
let start_len = ctx.remainder().len();
let (sig_bytes, sig) = ctx.read_signature()?;

#marshal
Err(::rustbus::wire::errors::UnmarshalError::NoMatchingVariantFound)
}
Expand Down

0 comments on commit 13d306e

Please sign in to comment.