aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/device.rs20
2 files changed, 15 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 92a4dac..6305ebe 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@
- Refactor and clean up internal code:
- Prefer using the `Into` trait over numeric casting.
- Add `Pro::new` and `Storage::new` functions.
+- Implement `From<Pro>` and `From<Storage>` for `DeviceWrapper`.
# v0.3.4 (2019-01-20)
- Fix authentication methods that assumed that `char` is signed.
diff --git a/src/device.rs b/src/device.rs
index 2abf801..ad75a44 100644
--- a/src/device.rs
+++ b/src/device.rs
@@ -707,12 +707,8 @@ fn get_connected_model() -> Option<Model> {
fn create_device_wrapper(model: Model) -> DeviceWrapper {
match model {
- Model::Pro => DeviceWrapper::Pro(Pro {
- marker: marker::PhantomData,
- }),
- Model::Storage => DeviceWrapper::Storage(Storage {
- marker: marker::PhantomData,
- }),
+ Model::Pro => Pro::new().into(),
+ Model::Storage => Storage::new().into(),
}
}
@@ -737,6 +733,18 @@ impl DeviceWrapper {
}
}
+impl From<Pro> for DeviceWrapper {
+ fn from(device: Pro) -> Self {
+ DeviceWrapper::Pro(device)
+ }
+}
+
+impl From<Storage> for DeviceWrapper {
+ fn from(device: Storage) -> Self {
+ DeviceWrapper::Storage(device)
+ }
+}
+
impl GenerateOtp for DeviceWrapper {
fn get_hotp_slot_name(&self, slot: u8) -> Result<String, Error> {
self.device().get_hotp_slot_name(slot)