pub fn with_device<F>(n: usize, target: Target, f: F) -> Result<(), DownloadError>
where
    for<'a> F: FnOnce(Session) -> Result<(), DownloadError>,
{
    let device = {
        let mut list = daplink::tools::list_daplink_devices();
        list.extend(stlink::tools::list_stlink_devices());

        list.remove(n)
    };

    let probe = match device.probe_type {
        DebugProbeType::DAPLink => {
            let mut link = daplink::DAPLink::new_from_probe_info(&device)?;

            link.attach(Some(WireProtocol::Swd))?;

            MasterProbe::from_specific_probe(link)
        }
        DebugProbeType::STLink => {
            let mut link = stlink::STLink::new_from_probe_info(&device)?;

            link.attach(Some(WireProtocol::Swd))?;

            MasterProbe::from_specific_probe(link)
        }
    };

    let flash_algorithm = match target.flash_algorithm.clone() {
        Some(name) => select_algorithm(name)?,
        None => return Err(AlgorithmSelectionError::NoAlgorithmSuggested.into()),
    };

    let session = Session::new(target, probe, Some(flash_algorithm));

    f(session)
}
/// Takes a closure that is handed an `DAPLink` instance and then executed.
/// After the closure is done, the USB device is always closed,
/// even in an error case inside the closure!
Takes a closure that is handed an `DAPLink` instance and then executed.
After the closure is done, the USB device is always closed,
even in an error case inside the closure!
Takes a closure that is handed an ` DAPLink ` instance and then executed . After the closure is done the USB device is always closed even in an error case inside the closure!
pub fn with_device<F>(n: usize, target: Target, f: F) -> Result<(), DownloadError>
where
    for<'a> F: FnOnce(Session) -> Result<(), DownloadError>,
{
    let device = {
        let mut list = daplink::tools::list_daplink_devices();
        list.extend(stlink::tools::list_stlink_devices());
        list.remove(n)
    };
    let probe = match device.probe_type {
        DebugProbeType::DAPLink => {
            let mut link = daplink::DAPLink::new_from_probe_info(&device)?;
            link.attach(Some(WireProtocol::Swd))?;
            MasterProbe::from_specific_probe(link)
        }
        DebugProbeType::STLink => {
            let mut link = stlink::STLink::new_from_probe_info(&device)?;
            link.attach(Some(WireProtocol::Swd))?;
            MasterProbe::from_specific_probe(link)
        }
    };
    let flash_algorithm = match target.flash_algorithm.clone() {
        Some(name) => select_algorithm(name)?,
        None => return Err(AlgorithmSelectionError::NoAlgorithmSuggested.into()),
    };
    let session = Session::new(target, probe, Some(flash_algorithm));
    f(session)
}
pub fn with_device < F > ( n : usize , target : Target , f : F ) -> Result < ( ) , DownloadError > where for < ' a > F : FnOnce ( Session ) -> Result < ( ) , DownloadError > , { let device = { let mut list = daplink :: tools :: list_daplink_devices ( ) ; list . extend ( stlink :: tools :: list_stlink_devices ( ) ) ; list . remove ( n ) } ; let probe = match device . probe_type { DebugProbeType :: DAPLink => { let mut link = daplink :: DAPLink :: new_from_probe_info ( & device ) ? ; link . attach ( Some ( WireProtocol :: Swd ) ) ? ; MasterProbe :: from_specific_probe ( link ) } DebugProbeType :: STLink => { let mut link = stlink :: STLink :: new_from_probe_info ( & device ) ? ; link . attach ( Some ( WireProtocol :: Swd ) ) ? ; MasterProbe :: from_specific_probe ( link ) } } ; let flash_algorithm = match target . flash_algorithm . clone ( ) { Some ( name ) => select_algorithm ( name ) ? , None => return Err ( AlgorithmSelectionError :: NoAlgorithmSuggested . into ( ) ) , } ; let session = Session :: new ( target , probe , Some ( flash_algorithm ) ) ; f ( session ) }
Takes a closure that is handed an `DAPLink` instance and then executed.
Takes a closure that is handed an ` DAPLink ` instance and then executed .
n
usize
target
Target
f
F