pub struct Entity {
pub name: String,
pub pattern: String,
pub mandatory: bool,
pub directory: Option<String>,
pub dtype: String,
/* private fields */
}Expand description
Represents a single entity defined in configuration.
Corresponds to PyBIDS Entity — a named key (e.g., “subject”, “task”)
with a regex pattern to extract values from file paths.
§Example
use bids_core::Entity;
let ent = Entity::new("subject", r"[/\\]+sub-([a-zA-Z0-9]+)");
let val = ent.match_path("/sub-01/anat/sub-01_T1w.nii.gz");
assert_eq!(val.unwrap().as_str_lossy(), "01");Fields§
§name: String§pattern: String§mandatory: bool§directory: Option<String>§dtype: StringImplementations§
Source§impl Entity
impl Entity
Sourcepub fn new(name: &str, pattern: &str) -> Self
pub fn new(name: &str, pattern: &str) -> Self
Create a new entity.
Eagerly compiles the regex. If the pattern is invalid, the entity will
never match any path. Prefer Entity::try_new() when working with
user-supplied patterns so you can surface the error.
Sourcepub fn try_new(name: &str, pattern: &str) -> Result<Self, Error>
pub fn try_new(name: &str, pattern: &str) -> Result<Self, Error>
Create a new entity, returning an error if the regex pattern is invalid.
§Errors
Returns regex::Error if pattern is not a valid regular expression.
Sourcepub fn with_dtype(self, dtype: &str) -> Self
pub fn with_dtype(self, dtype: &str) -> Self
Set the data type ("str", "int", "float", "bool").
Sourcepub fn with_directory(self, directory: &str) -> Self
pub fn with_directory(self, directory: &str) -> Self
Set the directory pattern for this entity.
Sourcepub fn with_mandatory(self, mandatory: bool) -> Self
pub fn with_mandatory(self, mandatory: bool) -> Self
Mark this entity as mandatory.
Sourcepub fn regex(&self) -> Option<&Regex>
pub fn regex(&self) -> Option<&Regex>
Return the compiled regex, lazily compiling on first access.
Returns None if the pattern is invalid. Only requires &self.
Sourcepub fn match_path(&self, path: &str) -> Option<EntityValue>
pub fn match_path(&self, path: &str) -> Option<EntityValue>
Match the entity pattern against a file path. Returns the captured value if found.
Only requires &self (no mutable borrow needed).
Sourcepub fn coerce_value(&self, val: &str) -> EntityValue
pub fn coerce_value(&self, val: &str) -> EntityValue
Coerce a string value to the appropriate type.