Genericize StateCallback for MacOS
This commit is contained in:
Родитель
c67bdd9e98
Коммит
d5d1a49424
|
@ -24,7 +24,7 @@ pub struct Transaction {
|
|||
impl Transaction {
|
||||
pub fn new<F, T>(
|
||||
timeout: u64,
|
||||
callback: StateCallback<T>,
|
||||
callback: StateCallback<Result<T, ::Error>>,
|
||||
new_device_cb: F,
|
||||
) -> Result<Self, ::Error>
|
||||
where
|
||||
|
|
|
@ -18,7 +18,7 @@ enum QueueAction {
|
|||
challenge: Vec<u8>,
|
||||
application: ::AppId,
|
||||
key_handles: Vec<::KeyHandle>,
|
||||
callback: StateCallback<::RegisterResult>,
|
||||
callback: StateCallback<Result<::RegisterResult, ::Error>>,
|
||||
},
|
||||
Sign {
|
||||
flags: ::SignFlags,
|
||||
|
@ -26,7 +26,7 @@ enum QueueAction {
|
|||
challenge: Vec<u8>,
|
||||
app_ids: Vec<::AppId>,
|
||||
key_handles: Vec<::KeyHandle>,
|
||||
callback: StateCallback<::SignResult>,
|
||||
callback: StateCallback<Result<::SignResult, ::Error>>,
|
||||
},
|
||||
Cancel,
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ impl StateMachine {
|
|||
challenge: Vec<u8>,
|
||||
application: ::AppId,
|
||||
key_handles: Vec<::KeyHandle>,
|
||||
callback: StateCallback<::RegisterResult>,
|
||||
callback: StateCallback<Result<::RegisterResult, ::Error>>,
|
||||
) {
|
||||
// Abort any prior register/sign calls.
|
||||
self.cancel();
|
||||
|
@ -122,7 +122,7 @@ impl StateMachine {
|
|||
challenge: Vec<u8>,
|
||||
app_ids: Vec<::AppId>,
|
||||
key_handles: Vec<::KeyHandle>,
|
||||
callback: StateCallback<::SignResult>,
|
||||
callback: StateCallback<Result<::SignResult, ::Error>>,
|
||||
) {
|
||||
// Abort any prior register/sign calls.
|
||||
self.cancel();
|
||||
|
|
|
@ -68,18 +68,17 @@ pub fn io_err(msg: &str) -> io::Error {
|
|||
}
|
||||
|
||||
pub struct StateCallback<T> {
|
||||
callback: Arc<Mutex<Option<Box<dyn Fn(Result<T, ::Error>,) + Send>>>>,
|
||||
callback: Arc<Mutex<Option<Box<dyn Fn(T) + Send>>>>,
|
||||
}
|
||||
|
||||
impl<T> StateCallback<T> {
|
||||
pub fn new(cb: Box<dyn Fn(Result<T, ::Error>) + Send + 'static>) -> Self
|
||||
{
|
||||
pub fn new(cb: Box<dyn Fn(T) + Send + 'static>) -> Self {
|
||||
Self {
|
||||
callback: Arc::new(Mutex::new(Some(cb))),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn call(&self, rv: Result<T, ::Error>) {
|
||||
pub fn call(&self, rv: T) {
|
||||
if let Ok(mut cb) = self.callback.lock() {
|
||||
if let Some(cb) = cb.take() {
|
||||
cb(rv);
|
||||
|
|
Загрузка…
Ссылка в новой задаче