diff --git a/Cargo.toml b/Cargo.toml index e5b12e8..854fe1e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ readme = "README.md" [dependencies] failure = "0.1.1" -random-access-storage = "0.6.0" +random-access-storage = "2.0.0" [dev-dependencies] quickcheck = "0.8.1" diff --git a/src/lib.rs b/src/lib.rs index 53bba53..b28df66 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -188,4 +188,16 @@ impl RandomAccess for RandomAccessMemory { Ok(()) } + + fn truncate(&mut self, _length: usize) -> Result<(), Self::Error> { + unimplemented!() + } + + fn len(&mut self) -> Result { + Ok(self.length) + } + + fn is_empty(&mut self) -> Result { + Ok(self.length == 0) + } } diff --git a/tests/test.rs b/tests/test.rs index d874400..694e6ad 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -30,3 +30,21 @@ fn can_read() { let text = String::from_utf8(text.to_vec()).unwrap(); assert_eq!(text, "hello world"); } + +#[test] +fn can_len() { + let mut file = ram::RandomAccessMemory::default(); + assert_eq!(file.len().unwrap(), 0); + file.write(0, b"hello").unwrap(); + assert_eq!(file.len().unwrap(), 5); + file.write(5, b" world").unwrap(); + assert_eq!(file.len().unwrap(), 11); +} + +#[test] +fn can_is_empty() { + let mut file = ram::RandomAccessMemory::default(); + assert_eq!(file.is_empty().unwrap(), true); + file.write(0, b"hello").unwrap(); + assert_eq!(file.is_empty().unwrap(), false); +}