aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-01-16 23:19:53 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-01-17 00:28:56 +0100
commitda2ac74281c4adf4dc10b55ec267d84a8a1502dc (patch)
tree3604e7d44ea2d240738ff8a433d91dd4cdefd5c3 /src
parentd18cb04ff4d201fe4532cedd22b9753e08385a7f (diff)
downloadnitrokey-rs-da2ac74281c4adf4dc10b55ec267d84a8a1502dc.tar.gz
nitrokey-rs-da2ac74281c4adf4dc10b55ec267d84a8a1502dc.tar.bz2
Implement Display for Version
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 02a622b..807a9ca 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -93,6 +93,8 @@ mod otp;
mod pws;
mod util;
+use std::fmt;
+
use nitrokey_sys;
pub use crate::auth::{Admin, Authenticate, User};
@@ -125,6 +127,16 @@ pub struct Version {
pub minor: u32,
}
+impl fmt::Display for Version {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ if self.git.is_empty() {
+ write!(f, "v{}.{}", self.major, self.minor)
+ } else {
+ f.write_str(&self.git)
+ }
+ }
+}
+
/// Enables or disables debug output. Calling this method with `true` is equivalent to setting the
/// log level to `Debug`; calling it with `false` is equivalent to the log level `Error` (see
/// [`set_log_level`][]).