pub struct ConceptId { /* private fields */ }Expand description
A concept identifier: an ordered list of path segments (e.g.
["tables", "users"] for tables/users).
Implementations§
Source§impl ConceptId
impl ConceptId
Sourcepub fn new(segments: Vec<String>) -> Result<Self, ConceptIdError>
pub fn new(segments: Vec<String>) -> Result<Self, ConceptIdError>
Builds a concept id from segments, validating each.
§Errors
Returns ConceptIdError if segments is empty or any segment fails
validate_segment.
Sourcepub fn parse(s: &str) -> Result<Self, ConceptIdError>
pub fn parse(s: &str) -> Result<Self, ConceptIdError>
Parses a concept id from a /-separated string. Empty segments are
dropped (so leading/trailing/duplicate slashes are tolerated), matching
the reference parse_concept_id.
§Errors
Returns ConceptIdError if s resolves to no segments or any segment
fails validate_segment.
Sourcepub fn parent(&self) -> Option<Self>
pub fn parent(&self) -> Option<Self>
The id of the directory that contains this concept, if any.
Sourcepub fn to_path(&self, bundle_root: &Path) -> PathBuf
pub fn to_path(&self, bundle_root: &Path) -> PathBuf
Resolves this id to a file path under bundle_root (appending .md).
§Panics
Never panics in practice: the constructor rejects empty segment lists,
so ConceptId::segments always has at least one element.
Sourcepub fn from_path(
bundle_root: &Path,
path: &Path,
) -> Result<Self, ConceptIdError>
pub fn from_path( bundle_root: &Path, path: &Path, ) -> Result<Self, ConceptIdError>
Derives a concept id from a file path relative to bundle_root,
stripping the .md suffix.
The path must be a normalized, UTF-8 .md path whose segments can be
represented by a ConceptId. A file already on disk is a concept
whatever its portable spelling, and conformance is a question of
frontmatter, not filenames, so names such as my notes.md remain valid.
Rejecting non-UTF-8 names rather than replacing them is important: a
replacement character would produce an id that does not point back to
the original file.
§Errors
Returns ConceptIdError if path is not under bundle_root or
resolves to no segments, is not a .md file, contains a non-normal path
component, or cannot be represented as UTF-8 without loss.