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
impl ClusterId
Sourcepub fn new(segments: Vec<ClusterIdSegment>) -> Self
pub fn new(segments: Vec<ClusterIdSegment>) -> Self
Construct a new cluster id from an ordered segment list.
Sourcepub fn segments(&self) -> &[ClusterIdSegment]
pub fn segments(&self) -> &[ClusterIdSegment]
Borrow the underlying segments in nesting order.
Sourcepub fn parent(&self) -> Option<ClusterId>
pub fn parent(&self) -> Option<ClusterId>
Return a new id with the last segment dropped, or None if this
id is already the root.
Sourcepub fn parse_canonical(s: &str) -> Result<Self, ClusterIdError>
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");Sourcepub fn parse_structured<I, S>(parts: I) -> Result<Self, ClusterIdError>
pub fn parse_structured<I, S>(parts: I) -> Result<Self, ClusterIdError>
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<'de> Deserialize<'de> for ClusterId
impl<'de> Deserialize<'de> for ClusterId
Source§fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
Source§impl Display for ClusterId
impl Display for ClusterId
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
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.