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:
Ivan Zderadicka 2021-01-11 12:23:36 +01:00 committed by GitHub
parent df7e73ec47
commit 6538745b64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,6 +24,7 @@ use sha2::{Digest, Sha256};
use sha2::digest::generic_array::{GenericArray, typenum::U32};
use std::borrow::Borrow;
use std::hash::{Hash, Hasher};
use crate::record;
construct_uint! {
/// 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> {
fn as_ref(&self) -> &KeyBytes {
&self.bytes