Skip to main content

BidsMetadata

Struct BidsMetadata 

Source
pub struct BidsMetadata {
    pub source_file: Option<String>,
    /* private fields */
}
Expand description

Ordered metadata dictionary for a BIDS file.

Wraps an IndexMap<String, serde_json::Value> preserving insertion order. Provides typed accessors for common value types and can be deserialized into arbitrary structs via deserialize_as().

Metadata is populated from JSON sidecar files following the BIDS inheritance principle, where more-specific sidecars (closer to the data file) override less-specific ones (closer to the dataset root).

Corresponds to PyBIDS’ BIDSMetadata class.

§Example

use bids_core::metadata::BidsMetadata;
use serde_json::json;

let mut md = BidsMetadata::new();
md.insert("SamplingFrequency".into(), json!(256.0));
md.insert("EEGReference".into(), json!("Cz"));

assert_eq!(md.get_f64("SamplingFrequency"), Some(256.0));
assert_eq!(md.get_str("EEGReference"), Some("Cz"));

Fields§

§source_file: Option<String>

The source file this metadata is associated with.

Implementations§

Source§

impl BidsMetadata

Source

pub fn new() -> Self

Create an empty metadata dictionary.

Source

pub fn with_source(source_file: &str) -> Self

Create an empty metadata dictionary tagged with a source file path.

Source

pub fn get(&self, key: &str) -> Option<&Value>

Get a raw JSON value by key.

Source

pub fn get_str(&self, key: &str) -> Option<&str>

Get a string value by key (returns None if missing or not a string).

Source

pub fn get_f64(&self, key: &str) -> Option<f64>

Get a float value by key (returns None if missing or not numeric).

Source

pub fn get_i64(&self, key: &str) -> Option<i64>

Get an integer value by key (returns None if missing or not numeric).

Source

pub fn get_bool(&self, key: &str) -> Option<bool>

Get a boolean value by key.

Source

pub fn get_array(&self, key: &str) -> Option<&Vec<Value>>

Get a JSON array value by key.

Source

pub fn insert(&mut self, key: String, value: Value)

Insert a key-value pair, replacing any existing value.

Source

pub fn extend(&mut self, other: BidsMetadata)

Merge all entries from other into this metadata (overwrites on conflict).

Source

pub fn update_from_map(&mut self, map: IndexMap<String, Value>)

Merge entries from an IndexMap into this metadata.

Source

pub fn contains_key(&self, key: &str) -> bool

Check if a key exists.

Source

pub fn keys(&self) -> Keys<'_, String, Value>

Iterate over keys.

Source

pub fn iter(&self) -> Iter<'_, String, Value>

Iterate over key-value pairs.

Source

pub fn len(&self) -> usize

Number of metadata entries.

Source

pub fn is_empty(&self) -> bool

Returns true if the metadata is empty.

Source§

impl BidsMetadata

Source

pub fn deserialize_as<T: DeserializeOwned>(&self) -> Option<T>

Try to deserialize this metadata into a typed struct.

Works via JSON roundtrip: metadata map → serde_json::ValueT.

Trait Implementations§

Source§

impl Clone for BidsMetadata

Source§

fn clone(&self) -> BidsMetadata

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 BidsMetadata

Source§

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

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

impl Default for BidsMetadata

Source§

fn default() -> BidsMetadata

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

impl<'de> Deserialize<'de> for BidsMetadata

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 BidsMetadata

Source§

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

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

impl From<IndexMap<String, Value>> for BidsMetadata

Source§

fn from(map: IndexMap<String, Value>) -> Self

Converts to this type from the input type.
Source§

impl From<Map<String, Value>> for BidsMetadata

Source§

fn from(map: Map<String, Value>) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<(String, Value)> for BidsMetadata

Source§

fn from_iter<I: IntoIterator<Item = (String, Value)>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl Index<&str> for BidsMetadata

Source§

fn index(&self, key: &str) -> &Value

Index into metadata by key.

§Panics

Panics if the key is not present. Use get() for a non-panicking alternative.

Source§

type Output = Value

The returned type after indexing.
Source§

impl IntoIterator for BidsMetadata

Source§

type Item = (String, Value)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<String, Value>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl Serialize for BidsMetadata

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