mirror of
https://github.com/chatmail/core.git
synced 2026-05-20 15:26:30 +03:00
Implement TryFrom instead of TryInto
TryInto is derived automatically and its documentation recommends implementing TryFrom.
This commit is contained in:
24
src/key.rs
24
src/key.rs
@@ -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(()),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user