Skip to content

Commit

Permalink
Closes #2 Implement Clone and adds len() to MmapReadOnly
Browse files Browse the repository at this point in the history
  • Loading branch information
fulmicoton committed Jan 20, 2016
1 parent 82f3558 commit 068a853
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/raw/mmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ impl MmapReadOnly {
MmapReadOnly::open(&try!(fs::File::open(path)))
}

/// Returns the size in byte of the memory map.
///
/// If it is a range, the size is the size of the range.
pub fn len(&self,) -> usize {
self.len
}

/// Slice this memory map to a new `offset` and `len`.
///
/// If the new range is outside the bounds of `self`, then this method
Expand All @@ -50,6 +57,16 @@ impl MmapReadOnly {
}
}

impl Clone for MmapReadOnly {
fn clone(&self) -> MmapReadOnly {
MmapReadOnly{
map: self.map.clone(),
offset: self.offset,
len: self.len,
}
}
}

impl From<Mmap> for MmapReadOnly {
fn from(mmap: Mmap) -> MmapReadOnly {
let len = mmap.len();
Expand Down

0 comments on commit 068a853

Please sign in to comment.