Skip to main content

ClusterId

Struct ClusterId 

Source
pub struct ClusterId(/* private fields */);
Expand description

Ordered list of axis:value segments identifying a cluster’s path from the root.

The empty id (ClusterId::default()) addresses the root, before any axis has been applied.

§Examples

use face_core::ClusterId;

let id: ClusterId = "file:src/cli.rs,score:excellent".parse().unwrap();
assert_eq!(id.depth(), 2);
assert_eq!(id.to_string(), "file:src/cli.rs,score:excellent");

Implementations§

Source§

impl ClusterId

Source

pub fn new(segments: Vec<ClusterIdSegment>) -> Self

Construct a new cluster id from an ordered segment list.

Source

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

Borrow the underlying segments in nesting order.

Source

pub fn depth(&self) -> usize

Number of segments. The root id has depth 0.

Source

pub fn is_root(&self) -> bool

true when this id has no segments (i.e. addresses the root).

Source

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

Return a new id with the last segment dropped, or None if this id is already the root.

Source

pub fn parse_canonical(s: &str) -> Result<Self, ClusterIdError>

Parse the canonical comma form (§6.1).

A single-segment bare form (no :) is valid — the segment’s axis is left as the empty string and the CLI fills it in at bind-time. The bare form is allowed only when there is exactly one segment; mixing bare with multi-segment input is an error.

§Errors

Returns ClusterIdError if the input is empty, mixes bare and axis:value forms, has an explicit empty axis (:value), or contains an unterminated quoted value.

§Examples
use face_core::ClusterId;

let id = ClusterId::parse_canonical("file:src/cli.rs,score:excellent").unwrap();
assert_eq!(id.depth(), 2);

// Bare single-segment form: axis is empty, CLI fills at bind-time.
let bare = ClusterId::parse_canonical("excellent").unwrap();
assert_eq!(bare.segments()[0].axis, "");
assert_eq!(bare.segments()[0].value, "excellent");
Source

pub fn parse_structured<I, S>(parts: I) -> Result<Self, ClusterIdError>
where I: IntoIterator<Item = S>, S: AsRef<str>,

Parse a list of structured axis=value parts (§6.2).

Each part is a single axis=value pair; the order of parts is preserved as the nesting order.

§Errors

Returns ClusterIdError::StructuredMissingEquals if any part has no = separator, ClusterIdError::EmptyAxis if a part has an empty axis side, and ClusterIdError::Empty if no parts are supplied.

Trait Implementations§

Source§

impl Clone for ClusterId

Source§

fn clone(&self) -> ClusterId

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 ClusterId

Source§

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

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

impl Default for ClusterId

Source§

fn default() -> ClusterId

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ClusterId

Source§

fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for ClusterId

Source§

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

Emit the canonical comma form with §6.1 CSV-style quoting: values containing ,, :, or " are wrapped in double quotes; double quotes inside are escaped as "".

A single-segment id whose axis is empty emits just the value (no : prefix), matching the bare form accepted by Self::parse_canonical so that parse_canonical(&id.to_string()) == Ok(id) round-trips.

Source§

impl Eq for ClusterId

Source§

impl FromStr for ClusterId

Source§

type Err = ClusterIdError

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 ClusterId

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 ClusterId

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl Serialize for ClusterId

Source§

fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ClusterId

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> 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.