Skip to main content

Node

Trait Node 

Source
pub trait Node {
    // Required method
    fn get_key(&self) -> &str;
}
Expand description

Trait representing a node in a consistent hash ring

Any type that implements this trait can be used as a node in consistent hashing. The key returned by get_key() will be used for hash mapping on the ring.

§Example

use rocketmq_common::common::consistenthash::Node;

struct ServerNode {
    address: String,
}

impl Node for ServerNode {
    fn get_key(&self) -> &str {
        &self.address
    }
}

let node = ServerNode {
    address: "192.168.1.1:8080".to_string(),
};
assert_eq!(node.get_key(), "192.168.1.1:8080");

Required Methods§

Source

fn get_key(&self) -> &str

Returns the key which will be used for hash mapping

This key uniquely identifies the node in the hash ring and is used to compute the node’s position on the ring.

§Returns

A string slice representing the node’s key

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T: Node> Node for VirtualNode<T>