Implement TryFrom instead of TryInto

TryInto is derived automatically and its documentation recommends implementing TryFrom.
This commit is contained in:
Alexander Krotov
2019-11-10 05:17:51 +03:00
parent bfa0f9d911
commit c6369b1c5a

View File

@@ -29,44 +29,44 @@ impl From<SignedSecretKey> for Key {
} }
} }
impl std::convert::TryInto<SignedSecretKey> for Key { impl std::convert::TryFrom<Key> for SignedSecretKey {
type Error = (); type Error = ();
fn try_into(self) -> Result<SignedSecretKey, Self::Error> { fn try_from(value: Key) -> Result<Self, Self::Error> {
match self { match value {
Key::Public(_) => Err(()), Key::Public(_) => Err(()),
Key::Secret(key) => Ok(key), 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 = (); type Error = ();
fn try_into(self) -> Result<&'a SignedSecretKey, Self::Error> { fn try_from(value: &'a Key) -> Result<Self, Self::Error> {
match self { match value {
Key::Public(_) => Err(()), Key::Public(_) => Err(()),
Key::Secret(key) => Ok(key), Key::Secret(key) => Ok(key),
} }
} }
} }
impl std::convert::TryInto<SignedPublicKey> for Key { impl std::convert::TryFrom<Key> for SignedPublicKey {
type Error = (); type Error = ();
fn try_into(self) -> Result<SignedPublicKey, Self::Error> { fn try_from(value: Key) -> Result<Self, Self::Error> {
match self { match value {
Key::Public(key) => Ok(key), Key::Public(key) => Ok(key),
Key::Secret(_) => Err(()), 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 = (); type Error = ();
fn try_into(self) -> Result<&'a SignedPublicKey, Self::Error> { fn try_from(value: &'a Key) -> Result<Self, Self::Error> {
match self { match value {
Key::Public(key) => Ok(key), Key::Public(key) => Ok(key),
Key::Secret(_) => Err(()), Key::Secret(_) => Err(()),
} }