pub struct AgentPath { /* private fields */ }Expand description
A tree-style path identifying an agent in the agent hierarchy.
§Format
Path segments are separated by /. The root agent is always root.
Child agents have paths like root/searcher or root/analyzer.
§Examples
use agent_works::multi_agent::AgentPath;
let root = AgentPath::root();
assert!(root.is_root());
assert_eq!(root.depth(), 0);
assert_eq!(root.to_string(), "root");
let child = root.join("searcher");
assert!(!child.is_root());
assert_eq!(child.depth(), 1);
assert_eq!(child.to_string(), "root/searcher");
let parsed = "root/searcher".parse::<AgentPath>().unwrap();
assert_eq!(parsed, child);Implementations§
Source§impl AgentPath
impl AgentPath
Sourcepub fn join(&self, name: &str) -> Self
pub fn join(&self, name: &str) -> Self
Create a child path by appending a segment.
§Examples
use agent_works::multi_agent::AgentPath;
let root = AgentPath::root();
let searcher = root.join("searcher");
assert_eq!(searcher.to_string(), "root/searcher");Sourcepub fn parse(path: &str) -> Option<Self>
pub fn parse(path: &str) -> Option<Self>
Parse from a string like "root/searcher/worker-1".
Returns None if the string is empty, contains an empty segment, or does not
start with "root".
Sourcepub fn depth(&self) -> usize
pub fn depth(&self) -> usize
Returns the depth from root.
Root has depth 0, root/searcher has depth 1, root/searcher/worker-1 has depth 2.
Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Returns the name of this agent (the last segment).
§Examples
use agent_works::multi_agent::AgentPath;
let path = AgentPath::root().join("searcher");
assert_eq!(path.name(), "searcher");
assert_eq!(AgentPath::root().name(), "root");Trait Implementations§
Source§impl<'de> Deserialize<'de> for AgentPath
impl<'de> Deserialize<'de> for AgentPath
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
impl Eq for AgentPath
Source§impl Ord for AgentPath
impl Ord for AgentPath
1.21.0 (const: unstable) · 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 PartialOrd for AgentPath
impl PartialOrd for AgentPath
impl StructuralPartialEq for AgentPath
Auto Trait Implementations§
impl Freeze for AgentPath
impl RefUnwindSafe for AgentPath
impl Send for AgentPath
impl Sync for AgentPath
impl Unpin for AgentPath
impl UnsafeUnpin for AgentPath
impl UnwindSafe for AgentPath
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> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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.