Struct memoverlay::Patch
source · pub struct Patch { /* private fields */ }Expand description
represents a memory patch. It is not allowed to create an empty patch
Example
use memoverlay::{SolidPatch, Patch};
assert!(Patch::new(10, &[0,1,2,3,4,5,6,7,8,9][..]).is_ok());
assert!(Patch::new(10, &[][..]).is_err());
assert!(Patch::new(10, &[0,1,2,3,4,5,6,7,8,9][3..3]).is_err());Implementations§
source§impl Patch
impl Patch
sourcepub fn id(&self) -> u128
pub fn id(&self) -> u128
returns a unique id of this patch. Two patches have the same id if they have the same position and the same length. If two patches have the same offset, than the patch with the greater length has te greater id
sourcepub fn first_byte_offset(&self) -> u64
pub fn first_byte_offset(&self) -> u64
returns the offset of the first byte of this patch
sourcepub fn last_byte_offset(&self) -> u64
pub fn last_byte_offset(&self) -> u64
returns the offset of the last byte of this patch, or None if the patch
has a length of zero
sourcepub fn overlaps(&self, other: &Self) -> bool
pub fn overlaps(&self, other: &Self) -> bool
checks if two patches overlap each other
Example
use memoverlay::{SolidPatch, Patch};
let patch1 = Patch::new(10, &[0,1,2,3,4,5,6,7,8,9][..]).unwrap();
assert!(patch1.overlaps(&patch1));
let patch2 = Patch::new(12, &[1,2,3][..]).unwrap();
assert!(patch1.overlaps(&patch2));
assert!(patch2.overlaps(&patch1));
let patch3 = Patch::new(15, &[1,2,3,4,5][..]).unwrap();
assert!(patch1.overlaps(&patch3));
assert!(! patch2.overlaps(&patch3));
let patch4 = Patch::new(0, &[0,1,2,3,4,5,6,7,8,9][..]).unwrap();
assert!(! patch1.overlaps(&patch4));pub fn read(&self, offset: u64, buf: &mut [u8]) -> Result<usize>
Trait Implementations§
source§impl Ord for Patch
impl Ord for Patch
source§impl PartialEq<Patch> for Patch
impl PartialEq<Patch> for Patch
source§impl PartialOrd<Patch> for Patch
impl PartialOrd<Patch> for Patch
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read more