Skip to main content

TopicPath

Struct TopicPath 

Source
pub struct TopicPath { /* private fields */ }

Implementations§

Source§

impl TopicPath

Source

pub fn new_action_topic(&self, action_name: &str) -> Result<Self, String>

Creates a new TopicPath for an action based on this service path

INTENTION: Provide a simple way to create an action path from a service path, ensuring consistent formatting and proper path type.

Example:

use runar_node::TopicPath;
let service_path = TopicPath::new("main:auth", "default").expect("Valid path");
let action_path = service_path.new_action_topic("login").expect("Valid action path");

assert_eq!(action_path.action_path(), "auth/login");
Source

pub fn new_event_topic(&self, event_name: &str) -> Result<Self, String>

Creates a new TopicPath for an event based on this service path

INTENTION: Provide a simple way to create an event path from a service path, ensuring consistent formatting and proper path type.

Example:

use runar_node::TopicPath;
let service_path = TopicPath::new("main:auth", "default").expect("Valid path");
let event_path = service_path.new_event_topic("user_logged_in").expect("Valid event path");

assert_eq!(event_path.action_path(), "auth/user_logged_in");
Source

pub fn from_full_path(path: &str) -> Result<Self, String>

Source

pub fn new(path: &str, default_network: &str) -> Result<Self, String>

Create a new TopicPath from a string

INTENTION: Validate and construct a TopicPath from a string input, ensuring it follows the required format conventions.

This method now supports wildcard patterns:

  • “*” matches any single segment
  • “>” matches one or more segments to the end (must be the last segment)

Example:

use runar_node::routing::TopicPath;

// With network_id prefix
let path = TopicPath::new("main:auth/login", "default").expect("Valid path");
assert_eq!(path.network_id(), "main");
assert_eq!(path.service_path(), "auth");
assert_eq!(path.action_path(), "auth/login");

// With wildcards
let pattern = TopicPath::new("main:services/*/state", "default").expect("Valid pattern");
assert!(pattern.is_pattern());
Source

pub fn is_pattern(&self) -> bool

Check if this path contains wildcards

INTENTION: Quickly determine if a path is a wildcard pattern, which affects how it’s used for matching.

Source

pub fn has_multi_wildcard(&self) -> bool

Check if this path contains a multi-segment wildcard

INTENTION: Identify paths with multi-segment wildcards which have special matching rules and storage requirements.

Source

pub fn action_path(&self) -> String

Get the path after the network ID

INTENTION: Get the complete path after the network ID, including all segments. This is useful when you need the path for routing.

Example:

use runar_node::routing::TopicPath;

let path = TopicPath::new("main:auth/login", "default").expect("Valid path");
assert_eq!(path.action_path(), "auth/login");

// When there is only a service with no action, returns empty string
let service_only = TopicPath::new("main:auth", "default").expect("Valid path");
assert_eq!(service_only.action_path(), "");
Source

pub fn as_str(&self) -> &str

Get the path as a string

INTENTION: Access the raw path string for this TopicPath, useful for display and logging purposes.

Source

pub fn network_id(&self) -> String

Get the network ID from this path

INTENTION: Extract just the network segment from the path, which is crucial for network isolation and routing.

Example:

use runar_node::routing::TopicPath;

let path = TopicPath::new("main:auth/login", "default").expect("Valid path");
assert_eq!(path.network_id(), "main");
Source

pub fn service_path(&self) -> String

Get the service path part of this path

INTENTION: Extract the service path from the full path, which is used for service lookup and addressing.

Example:

use runar_node::routing::TopicPath;

let path = TopicPath::new("main:auth/login", "default").expect("Valid path");
// The service_path method returns just the service name (first segment)
assert_eq!(path.service_path(), "auth");

// If you need just the first segment, use get_segments
let segments = path.get_segments();
assert_eq!(segments[0], "auth");
Source

pub fn new_service(network_id: &str, service_name: &str) -> Self

Create a new service path from a network ID and service name

INTENTION: Create a TopicPath specifically for a service, avoiding manual string concatenation and validation.

Example:

use runar_node::routing::TopicPath;

let path = TopicPath::new_service("main", "auth");
assert_eq!(path.as_str(), "main:auth");
Source

pub fn starts_with(&self, other: &TopicPath) -> bool

Check if this path starts with another path

INTENTION: Determine if this path is a “child” or more specific version of another path, useful for hierarchical routing and subscription matching.

Example:

use runar_node::routing::TopicPath;

let path = TopicPath::new("main:auth/users", "default").expect("Valid path");
let prefix = TopicPath::new("main:auth", "default").expect("Valid path");
let different = TopicPath::new("main:payments", "default").expect("Valid path");

assert!(path.starts_with(&prefix));
assert!(!path.starts_with(&different));
Source

pub fn child(&self, segment: &str) -> Result<Self, String>

Create a child path by appending a segment

INTENTION: Generate a new TopicPath that is a child of this path, useful for creating more specific paths from a base path.

Example:

use runar_node::routing::TopicPath;

let base = TopicPath::new("main:auth", "default").expect("Valid path");
let child = base.child("login").expect("Valid child path");

assert_eq!(child.as_str(), "main:auth/login");
Source

pub fn get_segments(&self) -> Vec<String>

Get the path segments

INTENTION: Get the segments of the path after the network ID. This is useful for path analysis and custom path parsing.

Example:

use runar_node::routing::TopicPath;

let path = TopicPath::new("main:auth/login/form", "default").expect("Valid path");
let segments = path.get_segments();
assert_eq!(segments, vec!["auth", "login", "form"]);
Source

pub fn parent(&self) -> Result<Self, String>

Create a parent path

INTENTION: Generate a new TopicPath that is the parent of this path, useful for navigating up the path hierarchy.

Example:

use runar_node::routing::TopicPath;

let path = TopicPath::new("main:auth/users", "default").expect("Valid path");
let parent = path.parent().expect("Valid parent path");

assert_eq!(parent.as_str(), "main:auth");
Source

pub fn test_default(path: &str) -> Self

Create a default path for running unit tests with default network ID

INTENTION: Simplify test setup by creating a valid path with a default network ID.

Note: This is primarily intended for testing purposes.

Example:

use runar_node::routing::TopicPath;

let path = TopicPath::test_default("auth/login");
assert_eq!(path.as_str(), "default:auth/login");
Source

pub fn extract_params( &self, template: &str, ) -> Result<HashMap<String, String>, String>

Match this path against a template pattern and extract parameters

INTENTION: Enable services to define URL-like templates with named parameters and extract those parameter values from actual request paths.

Template patterns can include segments like {param_name} which will match any value in that position and capture it with the specified name.

Example:

use runar_node::routing::TopicPath;

let template = "services/{service_path}/state";
let path = TopicPath::new("main:services/math/state", "main").expect("Valid path");

let params = path.extract_params(template).expect("Template should match");
assert_eq!(params.get("service_path"), Some(&"math".to_string()));

// Non-matching templates return an error
let non_matching = TopicPath::new("main:users/profile", "main").expect("Valid path");
assert!(non_matching.extract_params(template).is_err());
Source

pub fn matches_template(&self, template: &str) -> bool

Check if a path matches a template pattern

INTENTION: Quickly determine if a path can be processed by a particular template, without needing to extract parameters.

Example:

use runar_node::routing::TopicPath;

let template = "services/{service_path}/state";
let path = TopicPath::new("main:services/math/state", "default").expect("Valid path");

assert!(path.matches_template(template));

let non_matching = TopicPath::new("main:users/profile", "default").expect("Valid path");
assert!(!non_matching.matches_template(template));
Source

pub fn has_templates(&self) -> bool

Check if this path contains template parameters

INTENTION: Quickly determine if a path has template parameters, which affects template matching behavior.

Source

pub fn segment_count(&self) -> usize

Get the number of segments in this path

INTENTION: Quickly get the segment count without iterating segments.

Source

pub fn has_segment_type(&self, index: usize, segment_type: u8) -> bool

Source

pub fn matches(&self, topic: &TopicPath) -> bool

Implement pattern matching against another path

INTENTION: Allow checking if a topic matches a pattern with wildcards, enabling powerful pattern-based subscriptions.

Example:

use runar_node::routing::TopicPath;

let pattern = TopicPath::new("main:services/*/state", "default").expect("Valid pattern");
let topic1 = TopicPath::new("main:services/math/state", "default").expect("Valid topic");
let topic2 = TopicPath::new("main:services/math/config", "default").expect("Valid topic");

assert!(pattern.matches(&topic1));
assert!(!pattern.matches(&topic2));
Source

pub fn from_template( template_string: &str, params: HashMap<String, String>, network_id_string: &str, ) -> Result<Self, String>

Create a TopicPath from a template and parameter values

INTENTION: Allow dynamic construction of TopicPaths from templates with parameter placeholders, similar to route templates in web frameworks.

Example:

use runar_node::routing::TopicPath;
use std::collections::HashMap;

let mut params = HashMap::new();
params.insert("service_path".to_string(), "math".to_string());
params.insert("action".to_string(), "add".to_string());

let path = TopicPath::from_template(
    "services/{service_path}/{action}",
    params,
    "main"
).expect("Valid template");

assert_eq!(path.as_str(), "main:services/math/add");

Trait Implementations§

Source§

impl Clone for TopicPath

Source§

fn clone(&self) -> TopicPath

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TopicPath

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for TopicPath

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for TopicPath

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for TopicPath

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for TopicPath

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more