mark Superblock::find unsafe; add test

This commit is contained in:
Szymon Walter 2018-03-19 19:33:56 +01:00
parent 0fc2c934d9
commit 959572eca1

View file

@ -145,7 +145,7 @@ pub struct Superblock {
} }
impl Superblock { impl Superblock {
pub fn find<'a, E>( pub unsafe fn find<'a, E>(
haystack: &'a Buffer<u8, Error = E>, haystack: &'a Buffer<u8, Error = E>,
) -> Result<(Superblock, usize), Error> ) -> Result<(Superblock, usize), Error>
where where
@ -257,4 +257,19 @@ mod tests {
superblock.err().unwrap_or_else(|| unreachable!()), superblock.err().unwrap_or_else(|| unreachable!()),
); );
} }
#[test]
#[allow(unused_unsafe)]
fn superblock() {
use std::cell::RefCell;
use std::fs::File;
let file = RefCell::new(File::open("ext2.bin").unwrap());
let superblock = Superblock::find(&file);
assert!(
superblock.is_ok(),
"Err({:?})",
superblock.err().unwrap_or_else(|| unreachable!()),
);
}
} }