pub fn download_file_with_options<P: AsRef<Path>>(
    session: &mut Session,
    path: &P,
    format: Format,
    options: DownloadOptions<'_>,
) -> Result<(), FileDownloadError> {
    let mut file = match File::open(path.as_ref()) {
        Ok(file) => file,
        Err(e) => return Err(FileDownloadError::IO(e)),
    };
    let mut buffer = vec![];
    // IMPORTANT: Change this to an actual memory map of a real chip
    let memory_map = session.target().memory_map.clone();

    let mut loader = FlashLoader::new(
        memory_map,
        options.keep_unwritten_bytes,
        session.target().source.clone(),
    );

    match format {
        Format::Bin(options) => loader.load_bin_data(&mut buffer, &mut file, options),
        Format::Elf => loader.load_elf_data(&mut buffer, &mut file),
        Format::Hex => loader.load_hex_data(&mut buffer, &mut file),
    }?;

    loader
        // TODO: hand out chip erase flag
        .commit(
            session,
            options.progress.unwrap_or(&FlashProgress::new(|_| {})),
            options.do_chip_erase,
            options.dry_run,
        )
        .map_err(FileDownloadError::Flash)
}
/// Downloads a file of given `format` at `path` to the flash of the target given in `session`.
///
/// This will ensure that memory bounderies are honored and does unlocking, erasing and programming of the flash for you.
///
/// If you are looking for a simple version without many options, have a look at [download_file].


If you are looking for a simple version without many options, have a look at [download_file].
If you are looking for a simple version without many options have a look at [ download_file ] .
pub fn download_file_with_options<P: AsRef<Path>>(
    session: &mut Session,
    path: &P,
    format: Format,
    options: DownloadOptions<'_>,
) -> Result<(), FileDownloadError> {
    let mut file = match File::open(path.as_ref()) {
        Ok(file) => file,
        Err(e) => return Err(FileDownloadError::IO(e)),
    };
    let mut buffer = vec![];
    // IMPORTANT: Change this to an actual memory map of a real chip
    let memory_map = session.target().memory_map.clone();
    let mut loader = FlashLoader::new(
        memory_map,
        options.keep_unwritten_bytes,
        session.target().source.clone(),
    );
    match format {
        Format::Bin(options) => loader.load_bin_data(&mut buffer, &mut file, options),
        Format::Elf => loader.load_elf_data(&mut buffer, &mut file),
        Format::Hex => loader.load_hex_data(&mut buffer, &mut file),
    }?;
    loader
        // TODO: hand out chip erase flag
        .commit(
            session,
            options.progress.unwrap_or(&FlashProgress::new(|_| {})),
            options.do_chip_erase,
            options.dry_run,
        )
        .map_err(FileDownloadError::Flash)
}
pub fn download_file_with_options < P : AsRef < Path > > ( session : & mut Session , path : & P , format : Format , options : DownloadOptions < ' _ > , ) -> Result < ( ) , FileDownloadError > { let mut file = match File :: open ( path . as_ref ( ) ) { Ok ( file ) => file , Err ( e ) => return Err ( FileDownloadError :: IO ( e ) ) , } ; let mut buffer = vec ! [ ] ; // IMPORTANT: Change this to an actual memory map of a real chip let memory_map = session . target ( ) . memory_map . clone ( ) ; let mut loader = FlashLoader :: new ( memory_map , options . keep_unwritten_bytes , session . target ( ) . source . clone ( ) , ) ; match format { Format :: Bin ( options ) => loader . load_bin_data ( & mut buffer , & mut file , options ) , Format :: Elf => loader . load_elf_data ( & mut buffer , & mut file ) , Format :: Hex => loader . load_hex_data ( & mut buffer , & mut file ) , } ? ; loader // TODO: hand out chip erase flag . commit ( session , options . progress . unwrap_or ( & FlashProgress :: new ( | _ | { } ) ) , options . do_chip_erase , options . dry_run , ) . map_err ( FileDownloadError :: Flash ) }
Downloads a file of given `format` at `path` to the flash of the target given in `session`.
Downloads a file of given ` format ` at ` path ` to the flash of the target given in ` session ` .
session
&mut Session
path
&P
format
Format
options
DownloadOptions<'_>
session
&mut Session
path
&P
format
Format
options
DownloadOptions<'_>