pub struct Key {
pub topic: String,
pub key: Vec<u8>,
}Fields§
§topic: String§key: Vec<u8>Implementations§
Source§impl Key
impl Key
Sourcepub fn into_bytes(self) -> Result<Vec<u8>>
pub fn into_bytes(self) -> Result<Vec<u8>>
Create a vector of bytes from the key.
The key is a concatenation of the topic and the key, separated by a slash.
§Errors
Returns an error if the topic contains a slash.
§Example
use hyveos_core::dht::Key;
let key = Key {
topic: "topic".to_string(),
key: "key".into(),
};
let bytes = key.into_bytes().unwrap();
assert_eq!(bytes, b"topic/key");Sourcepub fn from_bytes(bytes: Vec<u8>) -> Result<Self>
pub fn from_bytes(bytes: Vec<u8>) -> Result<Self>
Create a key from a vector of bytes.
The bytes should be a concatenation of the topic and the key, separated by a slash.
§Errors
Returns an error if the bytes do not contain a slash or if the topic is not valid UTF-8.
§Example
use hyveos_core::dht::Key;
let bytes = b"topic/key".to_vec();
let key = Key::from_bytes(bytes).unwrap();
assert_eq!(key.topic, "topic");
assert_eq!(&key.key, b"key");Trait Implementations§
Source§impl<'de> Deserialize<'de> for Key
impl<'de> Deserialize<'de> for Key
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Key
impl StructuralPartialEq for Key
Auto Trait Implementations§
impl Freeze for Key
impl RefUnwindSafe for Key
impl Send for Key
impl Sync for Key
impl Unpin for Key
impl UnwindSafe for Key
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request