Skip to content

Commit

Permalink
Add AsRef implem to Api
Browse files Browse the repository at this point in the history
  • Loading branch information
edouardparis committed Nov 17, 2023
1 parent 520bf69 commit 8a4353e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions coldcard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ impl Api {
}
}

impl AsRef<hidapi::HidApi> for Api {
fn as_ref(&self) -> &hidapi::HidApi {
&self.0
}
}

/// Specifies various options that a Coldcard can be opened with.
#[derive(Debug)]
pub struct Options {
Expand Down Expand Up @@ -181,11 +187,13 @@ impl Coldcard {
/// Coldcard devices. Returns an optional `XpubInfo` in case the device is
/// already initialized with a secret.
pub fn open(
api: &Api,
api: impl AsRef<hidapi::HidApi>,
sn: impl AsRef<str>,
opts: Option<Options>,
) -> Result<(Self, Option<XpubInfo>), Error> {
let mut cc = api.0.open_serial(COINKITE_VID, CKCC_PID, sn.as_ref())?;
let mut cc = api
.as_ref()
.open_serial(COINKITE_VID, CKCC_PID, sn.as_ref())?;

#[cfg(feature = "log")]
log::info!("opened SN {} with opts: {:?}", sn.as_ref(), opts);
Expand Down

0 comments on commit 8a4353e

Please sign in to comment.