[−][src]Trait punt::operation::Operation
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.
Provided methods
fn execute(&mut self) -> Result<()>
Consumes the iterator to execute the operation. Returns on the first error to occur.