protocols/kad: Add From impl for kbucket::Key
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.
@@ -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
