From c6369b1c5a9f101bb58de801c93f6dd93d9de58b Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Sun, 10 Nov 2019 05:17:51 +0300 Subject: [PATCH] Implement TryFrom instead of TryInto TryInto is derived automatically and its documentation recommends implementing TryFrom. --- src/key.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/key.rs b/src/key.rs index 12f10793a..0c0bb0a34 100644 --- a/src/key.rs +++ b/src/key.rs @@ -29,44 +29,44 @@ impl From for Key { } } -impl std::convert::TryInto for Key { +impl std::convert::TryFrom for SignedSecretKey { type Error = (); - fn try_into(self) -> Result { - match self { + fn try_from(value: Key) -> Result { + match value { Key::Public(_) => Err(()), Key::Secret(key) => Ok(key), } } } -impl<'a> std::convert::TryInto<&'a SignedSecretKey> for &'a Key { +impl<'a> std::convert::TryFrom<&'a Key> for &'a SignedSecretKey { type Error = (); - fn try_into(self) -> Result<&'a SignedSecretKey, Self::Error> { - match self { + fn try_from(value: &'a Key) -> Result { + match value { Key::Public(_) => Err(()), Key::Secret(key) => Ok(key), } } } -impl std::convert::TryInto for Key { +impl std::convert::TryFrom for SignedPublicKey { type Error = (); - fn try_into(self) -> Result { - match self { + fn try_from(value: Key) -> Result { + match value { Key::Public(key) => Ok(key), Key::Secret(_) => Err(()), } } } -impl<'a> std::convert::TryInto<&'a SignedPublicKey> for &'a Key { +impl<'a> std::convert::TryFrom<&'a Key> for &'a SignedPublicKey { type Error = (); - fn try_into(self) -> Result<&'a SignedPublicKey, Self::Error> { - match self { + fn try_from(value: &'a Key) -> Result { + match value { Key::Public(key) => Ok(key), Key::Secret(_) => Err(()), }