diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2019-12-27 23:07:56 +0100 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2019-12-27 23:07:56 +0100 |
commit | c35a20f6c034e4d8aa1eeba3eef85429e09d95dc (patch) | |
tree | 03ca7cd05da6c7b8405115e89ae6e7503604f703 /src | |
parent | 0bffc7931e011b4c0c046ed7608fbe9b7a1ffd19 (diff) | |
download | nitrokey-rs-c35a20f6c034e4d8aa1eeba3eef85429e09d95dc.tar.gz nitrokey-rs-c35a20f6c034e4d8aa1eeba3eef85429e09d95dc.tar.bz2 |
Implement std::convert::TryFrom<Config> for RawConfig
Previously, the RawConfig struct had a try_from function. As the
TryFrom trait has been stabilized with Rust 1.34.0, we can use it
instead.
Diffstat (limited to 'src')
-rw-r--r-- | src/auth.rs | 1 | ||||
-rw-r--r-- | src/config.rs | 8 |
2 files changed, 7 insertions, 2 deletions
diff --git a/src/auth.rs b/src/auth.rs index 0b000f7..cab1021 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -1,6 +1,7 @@ // Copyright (C) 2018-2019 Robin Krahl <robin.krahl@ireas.org> // SPDX-License-Identifier: MIT +use std::convert::TryFrom as _; use std::marker; use std::ops; use std::os::raw::c_char; diff --git a/src/config.rs b/src/config.rs index c273792..cb678d7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,6 +1,8 @@ // Copyright (C) 2018-2019 Robin Krahl <robin.krahl@ireas.org> // SPDX-License-Identifier: MIT +use std::convert; + use crate::error::{Error, LibraryError}; /// The configuration for a Nitrokey. @@ -68,8 +70,10 @@ impl Config { } } -impl RawConfig { - pub fn try_from(config: Config) -> Result<RawConfig, Error> { +impl convert::TryFrom<Config> for RawConfig { + type Error = Error; + + fn try_from(config: Config) -> Result<RawConfig, Error> { Ok(RawConfig { numlock: option_to_config_otp_slot(config.numlock)?, capslock: option_to_config_otp_slot(config.capslock)?, |