Skip to main content

Entity

Struct Entity 

Source
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: String

Implementations§

Source§

impl Entity

Source

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.

Source

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.

Source

pub fn with_dtype(self, dtype: &str) -> Self

Set the data type ("str", "int", "float", "bool").

Source

pub fn with_directory(self, directory: &str) -> Self

Set the directory pattern for this entity.

Source

pub fn with_mandatory(self, mandatory: bool) -> Self

Mark this entity as mandatory.

Source

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.

Source

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

Source

pub fn coerce_value(&self, val: &str) -> EntityValue

Coerce a string value to the appropriate type.

Trait Implementations§

Source§

impl Clone for Entity

Source§

fn clone(&self) -> Entity

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Entity

Source§

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

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

impl<'de> Deserialize<'de> for Entity

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

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

impl Display for Entity

Source§

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

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

impl Serialize for Entity

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,