summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2018-07-10 13:08:56 +0200
committerRobin Krahl <robin.krahl@ireas.org>2018-12-10 14:36:50 +0100
commit1e9556903dffaf77006ba10bba806114428cd53f (patch)
tree4ca96da83dceeb54ec09b4f94fb61a249309f4c1
parent99e417b8b5ca921f45f59f85b887f9bf6f03a267 (diff)
downloadnitrokey-rs-1e9556903dffaf77006ba10bba806114428cd53f.tar.gz
nitrokey-rs-1e9556903dffaf77006ba10bba806114428cd53f.tar.bz2
Add a Storage-only example to the DeviceWrapper documentation
As connect() now returns DeviceWrappers of the correct type, this patch adds an example to the DeviceWrapper documentation that shows how to use type conditions, i. e. how to execute a command only for Nitrokey Storage devices.
-rw-r--r--TODO.md1
-rw-r--r--src/device.rs20
2 files changed, 20 insertions, 1 deletions
diff --git a/TODO.md b/TODO.md
index 38044ae..2d865a4 100644
--- a/TODO.md
+++ b/TODO.md
@@ -35,7 +35,6 @@
- Clear passwords from memory.
- Find a nicer syntax for the `write_config` test.
- Prevent construction of internal types.
-- Add Storage-only examples to the `DeviceWrapper` documentation.
- More specific error checking in the tests.
- Differentiate empty strings and errors (see `result_from_string`).
- Check integer conversions.
diff --git a/src/device.rs b/src/device.rs
index 4f96860..843b41d 100644
--- a/src/device.rs
+++ b/src/device.rs
@@ -50,6 +50,26 @@ enum Model {
/// # }
/// ```
///
+/// Device-specific commands:
+///
+/// ```no_run
+/// use nitrokey::{DeviceWrapper, Storage};
+/// # use nitrokey::CommandError;
+///
+/// fn perform_common_task(device: &DeviceWrapper) {}
+/// fn perform_storage_task(device: &Storage) {}
+///
+/// # fn try_main() -> Result<(), CommandError> {
+/// let device = nitrokey::connect()?;
+/// perform_common_task(&device);
+/// match device {
+/// DeviceWrapper::Storage(storage) => perform_storage_task(&storage),
+/// _ => (),
+/// };
+/// # Ok(())
+/// # }
+/// ```
+///
/// [`connect`]: fn.connect.html
// TODO: add example for Storage-specific code
#[derive(Debug)]