Struct ruserf_types::Node
source · pub struct Node<I, A> { /* private fields */ }Expand description
Node is consist of id and address, which can be used as a identifier in a distributed system.
Implementations§
source§impl<I, A> Node<I, A>
impl<I, A> Node<I, A>
sourcepub fn set_address(&mut self, address: A) -> &mut Node<I, A>
pub fn set_address(&mut self, address: A) -> &mut Node<I, A>
Set the address of the node.
sourcepub fn with_address(self, address: A) -> Node<I, A>
pub fn with_address(self, address: A) -> Node<I, A>
Set the address of the node. (Builder pattern)
sourcepub fn into_components(self) -> (I, A)
pub fn into_components(self) -> (I, A)
Consumes the node and returns the id and address of the node.
sourcepub fn map_address<U>(self, f: impl FnOnce(A) -> U) -> Node<I, U>
pub fn map_address<U>(self, f: impl FnOnce(A) -> U) -> Node<I, U>
Maps an Node<I, A> to Node<I, U> by applying a function to the current node.
§Example
use nodecraft::Node;
let node = Node::new("test", 100u64);
let node = node.map_address(|address| address.to_string());
assert_eq!(node.address(), "100");sourcepub fn map_id<U>(self, f: impl FnOnce(I) -> U) -> Node<U, A>
pub fn map_id<U>(self, f: impl FnOnce(I) -> U) -> Node<U, A>
Maps an Node<I, A> to Node<U, A> by applying a function to the current node.
§Example
use nodecraft::Node;
let node = Node::new(1u64, 100u64);
let node = node.map_id(|id| id.to_string());
assert_eq!(node.id(), "1");sourcepub fn map<U, V>(self, f: impl FnOnce(I, A) -> (U, V)) -> Node<U, V>
pub fn map<U, V>(self, f: impl FnOnce(I, A) -> (U, V)) -> Node<U, V>
Maps an Node<I, A> to Node<U, V> by applying a function to the current node.
§Example
use nodecraft::Node;
let node = Node::new(1u64, 100u64);
let node = node.map(|id, address| (id.to_string(), address.to_string()));
assert_eq!(node.id(), "1");
assert_eq!(node.address(), "100");Trait Implementations§
source§impl<I, A> CheapClone for Node<I, A>where
I: CheapClone,
A: CheapClone,
impl<I, A> CheapClone for Node<I, A>where
I: CheapClone,
A: CheapClone,
source§fn cheap_clone(&self) -> Node<I, A>
fn cheap_clone(&self) -> Node<I, A>
Returns a copy of the value.
source§impl<'de, I, A> Deserialize<'de> for Node<I, A>where
I: Deserialize<'de>,
A: Deserialize<'de>,
impl<'de, I, A> Deserialize<'de> for Node<I, A>where
I: Deserialize<'de>,
A: Deserialize<'de>,
source§fn deserialize<__D>(
__deserializer: __D
) -> Result<Node<I, A>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<Node<I, A>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl<I, A> Ord for Node<I, A>
impl<I, A> Ord for Node<I, A>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl<I, A> PartialEq for Node<I, A>
impl<I, A> PartialEq for Node<I, A>
source§impl<I, A> PartialOrd for Node<I, A>where
I: PartialOrd,
A: PartialOrd,
impl<I, A> PartialOrd for Node<I, A>where
I: PartialOrd,
A: PartialOrd,
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read moresource§impl<I, A> Serialize for Node<I, A>
impl<I, A> Serialize for Node<I, A>
source§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
source§impl<I, A> Transformable for Node<I, A>where
I: Transformable,
A: Transformable,
impl<I, A> Transformable for Node<I, A>where
I: Transformable,
A: Transformable,
§type Error = NodeTransformError<I, A>
type Error = NodeTransformError<I, A>
The error type returned when encoding or decoding fails.
source§fn encode(
&self,
dst: &mut [u8]
) -> Result<usize, <Node<I, A> as Transformable>::Error>
fn encode( &self, dst: &mut [u8] ) -> Result<usize, <Node<I, A> as Transformable>::Error>
Encodes the value into the given buffer for transmission. Read more
source§fn encoded_len(&self) -> usize
fn encoded_len(&self) -> usize
Returns the encoded length of the value.
This is used to pre-allocate a buffer for encoding.
source§fn decode(
src: &[u8]
) -> Result<(usize, Node<I, A>), <Node<I, A> as Transformable>::Error>
fn decode( src: &[u8] ) -> Result<(usize, Node<I, A>), <Node<I, A> as Transformable>::Error>
Decodes the value from the given buffer received over the wire. Read more
source§fn encode_to_vec(&self) -> Result<Vec<u8>, Self::Error>
fn encode_to_vec(&self) -> Result<Vec<u8>, Self::Error>
Encodes the value into a vec for transmission.
source§fn encode_to_writer<W>(&self, writer: &mut W) -> Result<usize, Error>where
W: Write,
fn encode_to_writer<W>(&self, writer: &mut W) -> Result<usize, Error>where
W: Write,
Encodes the value into the given writer for transmission.
source§fn encode_to_async_writer<W>(
&self,
writer: &mut W
) -> impl Future<Output = Result<usize, Error>> + Send
fn encode_to_async_writer<W>( &self, writer: &mut W ) -> impl Future<Output = Result<usize, Error>> + Send
Encodes the value into the given async writer for transmission.
impl<I, A> Copy for Node<I, A>
impl<I, A> Eq for Node<I, A>
impl<I, A> StructuralPartialEq for Node<I, A>
Auto Trait Implementations§
impl<I, A> Freeze for Node<I, A>
impl<I, A> RefUnwindSafe for Node<I, A>where
I: RefUnwindSafe,
A: RefUnwindSafe,
impl<I, A> Send for Node<I, A>
impl<I, A> Sync for Node<I, A>
impl<I, A> Unpin for Node<I, A>
impl<I, A> UnwindSafe for Node<I, A>where
I: UnwindSafe,
A: UnwindSafe,
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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<T> Decodable for Twhere
T: Transformable,
impl<T> Decodable for Twhere
T: Transformable,
§type Error = <T as Transformable>::Error
type Error = <T as Transformable>::Error
The error type returned when encoding or decoding fails.
source§fn decode(src: &[u8]) -> Result<(usize, T), <T as Decodable>::Error>
fn decode(src: &[u8]) -> Result<(usize, T), <T as Decodable>::Error>
Decodes the value from the given buffer received over the wire. Read more
source§impl<T> Encodable for Twhere
T: Transformable,
impl<T> Encodable for Twhere
T: Transformable,
§type Error = <T as Transformable>::Error
type Error = <T as Transformable>::Error
The error type returned when encoding or decoding fails.
source§fn encode(&self, dst: &mut [u8]) -> Result<usize, <T as Encodable>::Error>
fn encode(&self, dst: &mut [u8]) -> Result<usize, <T as Encodable>::Error>
Encodes the value into the given buffer for transmission. Read more
source§fn encoded_len(&self) -> usize
fn encoded_len(&self) -> usize
Returns the encoded length of the value.
This is used to pre-allocate a buffer for encoding.
source§fn encode_to_vec(&self) -> Result<Vec<u8>, <T as Encodable>::Error>
fn encode_to_vec(&self) -> Result<Vec<u8>, <T as Encodable>::Error>
Encodes the value into a vec for transmission.
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> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more