[][src]Trait punt::operation::Operation

pub trait Operation: Iterator<Item = Result<usize>> {
    fn total(&self) -> usize;

    fn execute(&mut self) -> Result<()> { ... }
}

General-purpose trait for operations which take multiple command transmissions via USB, e.g. reading or writing a larger section of memory in smaller blocks.

Examples

An Operation is an Iterator and thus evaluated lazily. This means it has, on the one hand, to be executed explicitly for it to take effect:

use punt::{Context, UsbContext, Operation};

// Find a bootloader target
let mut context = Context::new()?;
let mut target_handle = context.pick_target(None)?.open()?;

// Create an erase Operation
let mut erase = target_handle.erase_area(0x0800_0c00, 1024)?;

// Execute the erase and check its result
erase.execute()?;

… but on the other hand, this can be used to have progress feedback from the operation

use punt::{Context, UsbContext, Operation};

// Find a bootloader target
let mut context = Context::new()?;
let mut target_handle = context.pick_target(None)?.open()?;

// Create an Erase Operation
let mut erase = target_handle.erase_area(0x0800_0c00, 1024)?;

let total = erase.total();
for status in erase {
    println!("Successfully erased {} of {} pages.", status?, total);
}

Required methods

fn total(&self) -> usize

Returns the total value in terms of which the progress is expressed.

For example, for an erase operation it would be the total number of pages, while for a flash read it would be the total number of bytes to be read.

Loading content...

Provided methods

fn execute(&mut self) -> Result<()>

Consumes the iterator to execute the operation. Returns on the first error to occur.

Loading content...

Implementors

impl<'_, '_, T: UsbContext> Operation for Program<'_, '_, T>[src]

fn total(&self) -> usize[src]

Returns the total size in bytes.

impl<'_, '_, T: UsbContext> Operation for Read<'_, '_, T>[src]

fn total(&self) -> usize[src]

Returns the total size in bytes.

impl<'_, T: UsbContext> Operation for Erase<'_, T>[src]

fn total(&self) -> usize[src]

Returns the total number of pages.

Loading content...