Skip to main content

CapabilityPath

Struct CapabilityPath 

Source
pub struct CapabilityPath { /* private fields */ }
Expand description

A validated capability path from an agent URI.

The capability path describes what an agent does, organized as a hierarchical path of segments separated by forward slashes.

§Constraints

  • At least one segment required
  • Maximum 32 segments
  • Maximum 256 total characters
  • Each segment: 1-64 chars, lowercase alphanumeric + hyphens

§Examples

use agent_uri::CapabilityPath;

let path = CapabilityPath::parse("assistant/chat").unwrap();
assert_eq!(path.segments().len(), 2);
assert_eq!(path.segments()[0].as_str(), "assistant");
assert_eq!(path.segments()[1].as_str(), "chat");

// Deep hierarchies
let path = CapabilityPath::parse("workflow/approval/invoice").unwrap();
assert_eq!(path.segments().len(), 3);

Implementations§

Source§

impl CapabilityPath

Source

pub fn from_segments( segments: Vec<PathSegment>, ) -> Result<Self, CapabilityPathError>

Builds a CapabilityPath from pre-validated PathSegment vectors.

This method allows constructing a CapabilityPath from segments that have already been validated individually, while still validating that the resulting path meets the overall path constraints.

§Arguments
  • segments - A vector of pre-validated PathSegment instances
§Returns

A validated CapabilityPath on success.

§Errors

Returns CapabilityPathError if:

  • The segments vector is empty
  • The path exceeds 256 total characters
  • The path has more than 32 segments
§Examples
use agent_uri::{CapabilityPath, PathSegment};

let segments = vec![
    PathSegment::parse("assistant").unwrap(),
    PathSegment::parse("chat").unwrap(),
];
let path = CapabilityPath::from_segments(segments).unwrap();
assert_eq!(path.as_str(), "assistant/chat");
Source

pub fn try_from_strs(segments: &[&str]) -> Result<Self, CapabilityPathError>

Builds a CapabilityPath by parsing each segment string individually.

This is a convenience method for constructing paths from string slices without first parsing them into PathSegment instances.

§Arguments
  • segments - A slice of string slices, each representing a path segment
§Returns

A validated CapabilityPath on success.

§Errors

Returns CapabilityPathError if:

  • The segments slice is empty
  • Any segment string is invalid
  • The path exceeds 256 total characters
  • The path has more than 32 segments
§Examples
use agent_uri::CapabilityPath;

let path = CapabilityPath::try_from_strs(&["assistant", "chat"]).unwrap();
assert_eq!(path.as_str(), "assistant/chat");

// Invalid segment fails
let result = CapabilityPath::try_from_strs(&["valid", "INVALID"]);
assert!(result.is_err());
Source

pub fn parse(input: &str) -> Result<Self, CapabilityPathError>

Parses a capability path from a string.

§Errors

Returns CapabilityPathError if:

  • The path is empty
  • The path exceeds 256 characters
  • The path has more than 32 segments
  • Any segment is invalid
Source

pub fn segments(&self) -> &[PathSegment]

Returns the path segments.

Source

pub fn depth(&self) -> usize

Returns the number of segments.

Source

pub fn starts_with(&self, prefix: &CapabilityPath) -> bool

Returns true if this path starts with the given prefix path.

Source

pub fn as_str(&self) -> &str

Returns the normalized string representation.

Source

pub fn parent(&self) -> Option<Self>

Returns the parent path, or None if this is a single-segment path.

§Examples
use agent_uri::CapabilityPath;

let path = CapabilityPath::parse("assistant/chat/streaming").unwrap();
let parent = path.parent().unwrap();
assert_eq!(parent.as_str(), "assistant/chat");

let root = CapabilityPath::parse("chat").unwrap();
assert!(root.parent().is_none());
Source

pub fn join(&self, segment: &PathSegment) -> Result<Self, CapabilityPathError>

Returns a new path with the given segment appended.

§Errors

Returns CapabilityPathError if the resulting path would be invalid.

§Examples
use agent_uri::{CapabilityPath, PathSegment};

let path = CapabilityPath::parse("assistant").unwrap();
let segment = PathSegment::parse("chat").unwrap();
let joined = path.join(&segment).unwrap();
assert_eq!(joined.as_str(), "assistant/chat");
Source

pub fn try_join(&self, s: &str) -> Result<Self, CapabilityPathError>

Returns a new path with a segment parsed from a string appended.

§Errors

Returns CapabilityPathError if the segment or resulting path would be invalid.

§Examples
use agent_uri::CapabilityPath;

let path = CapabilityPath::parse("assistant").unwrap();
let joined = path.try_join("chat").unwrap();
assert_eq!(joined.as_str(), "assistant/chat");
Source

pub fn last(&self) -> &PathSegment

Returns the last segment of the path.

§Examples
use agent_uri::CapabilityPath;

let path = CapabilityPath::parse("assistant/chat").unwrap();
assert_eq!(path.last().as_str(), "chat");
§Panics

This method will not panic because a CapabilityPath always has at least one segment (empty paths cannot be created).

Source

pub fn iter(&self) -> Iter<'_, PathSegment>

Returns an iterator over the path segments.

§Examples
use agent_uri::CapabilityPath;

let path = CapabilityPath::parse("assistant/chat/streaming").unwrap();
let names: Vec<&str> = path.iter().map(|s| s.as_str()).collect();
assert_eq!(names, vec!["assistant", "chat", "streaming"]);

Trait Implementations§

Source§

impl AsRef<str> for CapabilityPath

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for CapabilityPath

Source§

fn clone(&self) -> CapabilityPath

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for CapabilityPath

Source§

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

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

impl Display for CapabilityPath

Source§

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

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

impl Eq for CapabilityPath

Source§

impl FromStr for CapabilityPath

Source§

type Err = CapabilityPathError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for CapabilityPath

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<'a> IntoIterator for &'a CapabilityPath

Source§

type Item = &'a PathSegment

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, PathSegment>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl Ord for CapabilityPath

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for CapabilityPath

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for CapabilityPath

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for CapabilityPath

Source§

impl TryFrom<&str> for CapabilityPath

Source§

type Error = CapabilityPathError

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

fn try_from(s: &str) -> Result<Self, Self::Error>

Performs the conversion.

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<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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> PrefixFactory for T
where T: AsRef<str>,

Source§

fn create_prefix_sanitized(&self) -> TypeIdPrefix

Sanitizes the input and creates a valid TypeIdPrefix. Read more
Source§

fn try_create_prefix(&self) -> Result<TypeIdPrefix, ValidationError>

Attempts to create a TypeIdPrefix from the input without modifying it. Read more
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.