Struct lancelot::pagemap::PageMap

source ·
pub struct PageMap<T: Default + Copy> { /* private fields */ }
Expand description

PageMap is a map-like data structure that stores Copy elements in pages of 0x1000.

Its a good choice when representing lots of small elements that are found at contiguous indices. At the moment, indices are RVA.

Lookups should be quick, as they boil down to just a couple dereferences.

Implementations§

map the given items at the given address.

error if rva or items are not in a valid page. panic due to:

  • rva must be page aligned.
  • must be multiple of PAGE_SIZE number of items.

see example under get.

map the default value (probably zero) at the given address for the given size.

same error conditions as map. see example under probe.

map the given items at the given address, padding with the default value until the next page. (map zero-extend).

same error conditions as map.

use lancelot::pagemap::PageMap;

let mut d: PageMap<u32> = PageMap::with_capacity(0x2000);
assert_eq!(d.get(0x0), None);
assert_eq!(d.get(0x1), None);

d.writezx(0x0, &[0x1, ]).expect("failed to write");
assert_eq!(d.get(0x0), Some(0x1));
assert_eq!(d.get(0x1), Some(0x0));

is the given address mapped?

use lancelot::pagemap::PageMap;

let mut d: PageMap<u32> = PageMap::with_capacity(0x2000);
assert_eq!(d.probe(0x0), false);
assert_eq!(d.probe(0x1000), false);

d.map_empty(0x0, 0x1000).expect("failed to map");
assert_eq!(d.probe(0x0), true);
assert_eq!(d.probe(0x1000), false);

fetch one item from the given address. if the address is not mapped, then the result is None.

use lancelot::pagemap::PageMap;

let mut d: PageMap<u32> = PageMap::with_capacity(0x2000);
assert_eq!(d.get(0x0), None);
assert_eq!(d.get(0x1000), None);

d.write(0x1000, &[0x1; 0x1000]).expect("failed to map");
assert_eq!(d.get(0x0), None);
assert_eq!(d.get(0x1000), Some(0x1));

d.write(0x0, &[0x2; 0x2000]).expect("failed to map");
 assert_eq!(d.get(0x0), Some(0x2));
 assert_eq!(d.get(0x1000), Some(0x2));

fetch one mutable item from the given address.

use lancelot::pagemap::PageMap;

let mut d: PageMap<u32> = PageMap::with_capacity(0x2000);
d.map_empty(0x0, 0x1000).expect("failed to map");

// address 0x0 starts at 0
assert_eq!(d.get(0x0), Some(0x0));

// set address 0x0 to 1
let v = d.get_mut(0x0).expect("should be mapped");
*v = 1;

// address 0x0 is 1
assert_eq!(d.get(0x0), Some(0x1));

fetch the items found in the given range, placing them into the given slice. compared with slice, this routine avoids an allocation.

errors:

  • PageMapError::NotMapped: if any requested address is not mapped

fetch the items found in the given range.

errors:

  • PageMapError::NotMapped: if any requested address is not mapped

panic if:

  • start > end
use lancelot::pagemap::PageMap;

let mut d: PageMap<u32> = PageMap::with_capacity(0x2000);
d.map_empty(0x0, 0x1000).expect("failed to map");

assert_eq!(d.slice(0x0, 0x2).unwrap(), [0x0, 0x0]);
assert!(d.slice(0x0, 0x1000).is_ok(), "read page");
assert!(d.slice(0x0, 0x1001).is_err(), "read more than a page");

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Converts self into T using Into<T>. Read more
Causes self to use its Binary implementation when Debug-formatted.
Causes self to use its Display implementation when Debug-formatted. Read more
Causes self to use its LowerExp implementation when Debug-formatted. Read more
Causes self to use its LowerHex implementation when Debug-formatted. Read more
Causes self to use its Octal implementation when Debug-formatted.
Causes self to use its Pointer implementation when Debug-formatted. Read more
Causes self to use its UpperExp implementation when Debug-formatted. Read more
Causes self to use its UpperHex implementation when Debug-formatted. Read more
Formats each item in a sequence. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Pipes by value. This is generally the method you want to use. Read more
Borrows self and passes that borrow into the pipe function. Read more
Mutably borrows self and passes that borrow into the pipe function. Read more
Borrows self, then passes self.borrow() into the pipe function. Read more
Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Borrows self, then passes self.as_ref() into the pipe function.
Mutably borrows self, then passes self.as_mut() into the pipe function. Read more
Borrows self, then passes self.deref() into the pipe function.
Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more
Immutable access to a value. Read more
Mutable access to a value. Read more
Immutable access to the Borrow<B> of a value. Read more
Mutable access to the BorrowMut<B> of a value. Read more
Immutable access to the AsRef<R> view of a value. Read more
Mutable access to the AsMut<R> view of a value. Read more
Immutable access to the Deref::Target of a value. Read more
Mutable access to the Deref::Target of a value. Read more
Calls .tap() only in debug builds, and is erased in release builds.
Calls .tap_mut() only in debug builds, and is erased in release builds. Read more
Calls .tap_borrow() only in debug builds, and is erased in release builds. Read more
Calls .tap_borrow_mut() only in debug builds, and is erased in release builds. Read more
Calls .tap_ref() only in debug builds, and is erased in release builds. Read more
Calls .tap_ref_mut() only in debug builds, and is erased in release builds. Read more
Calls .tap_deref() only in debug builds, and is erased in release builds. Read more
Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Attempts to convert self into T using TryInto<T>. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.