From 959572eca14a82070b6a20c0ac64bf24fb19aaca Mon Sep 17 00:00:00 2001 From: Szymon Walter Date: Mon, 19 Mar 2018 19:33:56 +0100 Subject: [PATCH] mark Superblock::find unsafe; add test --- src/sys/superblock.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/sys/superblock.rs b/src/sys/superblock.rs index d58d689..b18bd1e 100644 --- a/src/sys/superblock.rs +++ b/src/sys/superblock.rs @@ -145,7 +145,7 @@ pub struct Superblock { } impl Superblock { - pub fn find<'a, E>( + pub unsafe fn find<'a, E>( haystack: &'a Buffer, ) -> Result<(Superblock, usize), Error> where @@ -257,4 +257,19 @@ mod tests { 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!()), + ); + } }