[][src]Struct checkers::Machine

pub struct Machine {
    pub memory_used: usize,
    // some fields omitted
}

Fake machine implementation to validate an allocation history.

Fields

memory_used: usize

Current memory used according to allocations.

Methods

impl Machine[src]

pub fn push(&mut self, event: Event) -> Result<(), Violation>[src]

Push an event into the machine.

Examples

Checks for a double-free:

use checkers::{Event::*, Region, Machine};

let mut machine = Machine::default();

assert!(machine.push(Alloc(Region::new(0.into(), 2, 1))).is_ok());
assert!(machine.push(Free(Region::new(0.into(), 2, 1))).is_ok());
assert!(machine.push(Free(Region::new(0.into(), 2, 1))).is_err());

Check for a misaligned allocation:

use checkers::{Event::*, Region, Machine, Violation};

let mut machine = Machine::default();
let requested = Region::new(5.into(), 2, 4);

assert_eq!(
    Err(Violation::MisalignedAlloc { requested }),
    machine.push(Alloc(requested))
);

Tries to deallocate part of other region:

use checkers::{Event::*, Region, Machine, Violation};

let mut machine = Machine::default();
let existing = Region::new(100.into(), 100, 1);

assert!(machine.push(Alloc(existing)).is_ok());

let requested = Region::new(150.into(), 50, 1);
assert_eq!(
    Err(Violation::MissingFree { requested }),
    machine.push(Free(requested))
);

let requested = Region::new(100.into(), 50, 1);
assert_eq!(
    Err(Violation::IncompleteFree { requested, existing }),
    machine.push(Free(requested))
);

pub fn trailing_regions(&self) -> Vec<Region>[src]

Access all trailing regions (ones which have not been deallocated).

Trait Implementations

impl Default for Machine[src]

Auto Trait Implementations

impl RefUnwindSafe for Machine

impl Send for Machine

impl Sync for Machine

impl Unpin for Machine

impl UnwindSafe for Machine

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.