mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-04-25 11:02:12 +00:00
protocols/kad: Add From impl for kbucket::Key (#1909)
- From<record::Key> - From<Vec<u8> This will enable to use additional types in kad.get_closest_peers as it was possible in pre 0.33 version. Co-authored-by: Max Inden <mail@max-inden.de>
This commit is contained in:
parent
df7e73ec47
commit
6538745b64
@ -24,6 +24,7 @@ use sha2::{Digest, Sha256};
|
|||||||
use sha2::digest::generic_array::{GenericArray, typenum::U32};
|
use sha2::digest::generic_array::{GenericArray, typenum::U32};
|
||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
use crate::record;
|
||||||
|
|
||||||
construct_uint! {
|
construct_uint! {
|
||||||
/// 256-bit unsigned integer.
|
/// 256-bit unsigned integer.
|
||||||
@ -111,6 +112,18 @@ impl From<PeerId> for Key<PeerId> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Vec<u8>> for Key<Vec<u8>> {
|
||||||
|
fn from(b: Vec<u8>) -> Self {
|
||||||
|
Key::new(b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<record::Key> for Key<record::Key> {
|
||||||
|
fn from(k: record::Key) -> Self {
|
||||||
|
Key::new(k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T> AsRef<KeyBytes> for Key<T> {
|
impl<T> AsRef<KeyBytes> for Key<T> {
|
||||||
fn as_ref(&self) -> &KeyBytes {
|
fn as_ref(&self) -> &KeyBytes {
|
||||||
&self.bytes
|
&self.bytes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user