mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-07-04 04:01:33 +00:00
refactor(identity): follow naming conventions for conversion methods
This PR renames some method names that don't follow Rust naming conventions or behave differently from what the name suggests: - Enforce "try" prefix on all methods that return `Result`. - Enforce "encode" method name for methods that return encoded bytes. - Enforce "to_bytes" method name for methods that return raw bytes. - Enforce "decode" method name for methods that convert encoded key. - Enforce "from_bytes" method name for methods that convert raw bytes. Pull-Request: #3775.
This commit is contained in:
@ -23,6 +23,8 @@
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
|
||||
use crate::KeyType;
|
||||
|
||||
/// An error during decoding of key material.
|
||||
#[derive(Debug)]
|
||||
pub struct DecodingError {
|
||||
@ -156,3 +158,26 @@ impl Error for SigningError {
|
||||
self.source.as_ref().map(|s| &**s as &dyn Error)
|
||||
}
|
||||
}
|
||||
|
||||
/// Error produced when failing to convert [`Keypair`](crate::Keypair) to a more concrete keypair.
|
||||
#[derive(Debug)]
|
||||
pub struct OtherVariantError {
|
||||
actual: KeyType,
|
||||
}
|
||||
|
||||
impl OtherVariantError {
|
||||
pub(crate) fn new(actual: KeyType) -> OtherVariantError {
|
||||
OtherVariantError { actual }
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for OtherVariantError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str(&format!(
|
||||
"Cannot convert to the given type, the actual key type inside is {}",
|
||||
self.actual
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for OtherVariantError {}
|
||||
|
Reference in New Issue
Block a user