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
impl BidsMetadata
Sourcepub fn with_source(source_file: &str) -> Self
pub fn with_source(source_file: &str) -> Self
Create an empty metadata dictionary tagged with a source file path.
Sourcepub fn get_str(&self, key: &str) -> Option<&str>
pub fn get_str(&self, key: &str) -> Option<&str>
Get a string value by key (returns None if missing or not a string).
Sourcepub fn get_f64(&self, key: &str) -> Option<f64>
pub fn get_f64(&self, key: &str) -> Option<f64>
Get a float value by key (returns None if missing or not numeric).
Sourcepub fn get_i64(&self, key: &str) -> Option<i64>
pub fn get_i64(&self, key: &str) -> Option<i64>
Get an integer value by key (returns None if missing or not numeric).
Sourcepub fn insert(&mut self, key: String, value: Value)
pub fn insert(&mut self, key: String, value: Value)
Insert a key-value pair, replacing any existing value.
Sourcepub fn extend(&mut self, other: BidsMetadata)
pub fn extend(&mut self, other: BidsMetadata)
Merge all entries from other into this metadata (overwrites on conflict).
Sourcepub fn update_from_map(&mut self, map: IndexMap<String, Value>)
pub fn update_from_map(&mut self, map: IndexMap<String, Value>)
Merge entries from an IndexMap into this metadata.
Sourcepub fn contains_key(&self, key: &str) -> bool
pub fn contains_key(&self, key: &str) -> bool
Check if a key exists.
Source§impl BidsMetadata
impl BidsMetadata
Sourcepub fn deserialize_as<T: DeserializeOwned>(&self) -> Option<T>
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::Value → T.
Trait Implementations§
Source§impl Clone for BidsMetadata
impl Clone for BidsMetadata
Source§fn clone(&self) -> BidsMetadata
fn clone(&self) -> BidsMetadata
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more