-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix tests due to packed issue #24
Comments
E.g.: #[derive(Default, Copy, Clone)]
#[repr(packed)]
struct Foo {
foo: i64,
bar: u32,
}
impl scroll::ctx::FromCtx<scroll::Endian> for Foo {
fn from_ctx(bytes: &[u8], ctx: scroll::Endian) -> Self {
Foo { foo: bytes.cread_with::<i64>(0, ctx), bar: bytes.cread_with::<u32>(8, ctx) }
}
}
impl scroll::ctx::SizeWith<scroll::Endian> for Foo {
type Units = usize;
fn size_with(_: &scroll::Endian) -> Self::Units {
::std::mem::size_of::<Foo>()
}
}
#[test]
fn ioread_api() {
use std::io::Cursor;
use scroll::{LE, IOread};
let bytes_ = [0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0xef,0xbe,0x00,0x00,];
let mut bytes = Cursor::new(bytes_);
let foo = bytes.ioread_with::<i64>(LE).unwrap();
let bar = bytes.ioread_with::<u32>(LE).unwrap();
assert_eq!(foo, 1);
assert_eq!(bar, 0xbeef);
let error = bytes.ioread_with::<f64>(LE);
assert!(error.is_err());
let mut bytes = Cursor::new(bytes_);
let foo_ = bytes.ioread_with::<Foo>(LE).unwrap();
assert_eq!(foo_.foo, foo);
assert_eq!(foo_.bar, bar);
} |
hdhoang
added a commit
to hdhoang/scroll
that referenced
this issue
May 2, 2018
willglynn
pushed a commit
to willglynn/scroll
that referenced
this issue
Nov 2, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
assert_eq
borrows the packed structs which is now Against The Rulesref rust-lang/rust#46043
The text was updated successfully, but these errors were encountered: