pub struct BidsFile {
pub path: PathBuf,
pub filename: String,
pub dirname: PathBuf,
pub is_dir: bool,
pub file_type: FileType,
pub entities: Entities,
pub metadata: BidsMetadata,
}Expand description
Represents a single file in a BIDS dataset.
This is the Rust equivalent of PyBIDS’ BIDSFile hierarchy
(BIDSFile, BIDSDataFile, BIDSImageFile, BIDSJSONFile).
§Example
use bids_core::file::BidsFile;
let f = BidsFile::new("/data/sub-01/eeg/sub-01_task-rest_eeg.edf");
assert_eq!(f.suffix(), Some("eeg"));
assert_eq!(f.extension(), ".edf");
assert_eq!(f.file_type, bids_core::FileType::Eeg);Fields§
§path: PathBufAbsolute path to the file.
filename: StringJust the filename component.
dirname: PathBufThe parent directory.
is_dir: boolWhether this entry represents a directory.
file_type: FileTypeFile type determined from extension.
entities: EntitiesEntities extracted from the filename.
metadata: BidsMetadataMetadata loaded from JSON sidecars (populated during metadata indexing).
Note: This field is skipped during serialization/deserialization.
If you serialize a BidsFile and deserialize it back, metadata will be
empty. Use BidsLayout::get_metadata() to re-populate after
deserialization, or serialize metadata separately.
Implementations§
Source§impl BidsFile
impl BidsFile
Sourcepub fn with_entities(self, entities: Entities) -> Self
pub fn with_entities(self, entities: Entities) -> Self
Set entities on this file, returning self for chaining.
Sourcepub fn with_metadata(self, metadata: BidsMetadata) -> Self
pub fn with_metadata(self, metadata: BidsMetadata) -> Self
Set metadata on this file, returning self for chaining.
Sourcepub fn relpath(&self, root: &Path) -> Option<PathBuf>
pub fn relpath(&self, root: &Path) -> Option<PathBuf>
Get the path relative to a root directory.
Sourcepub fn get_entities(&self, metadata: Option<bool>) -> Entities
pub fn get_entities(&self, metadata: Option<bool>) -> Entities
Get a combined view of filename entities and metadata.
Sourcepub fn get_metadata(&self) -> &BidsMetadata
pub fn get_metadata(&self) -> &BidsMetadata
Get metadata for this file (from JSON sidecars).
Sourcepub fn extension(&self) -> &str
pub fn extension(&self) -> &str
Get the full extension, including compound extensions like .tsv.gz.
Compound extensions are checked first (longest match wins).
Sourcepub fn suffix(&self) -> Option<&str>
pub fn suffix(&self) -> Option<&str>
Get the suffix (the part before the extension, after the last underscore).
Sourcepub fn companion(&self, suffix: &str, ext: &str) -> PathBuf
pub fn companion(&self, suffix: &str, ext: &str) -> PathBuf
Find a companion file by replacing the suffix and extension.
E.g., for sub-01_task-rest_eeg.edf, companion("channels", "tsv")
returns sub-01_task-rest_channels.tsv in the same directory.
Sourcepub fn get_json(&self) -> Result<Value, BidsError>
pub fn get_json(&self) -> Result<Value, BidsError>
Read a JSON file and return as serde_json::Value.
§Errors
Returns a BidsError::FileType if this file is not a JSON file, or
an I/O / JSON parse error.
Sourcepub fn get_dict(&self) -> Result<HashMap<String, Value>, BidsError>
pub fn get_dict(&self) -> Result<HashMap<String, Value>, BidsError>
Read a JSON file and return as a HashMap.
§Errors
Returns an error if the file is not JSON, can’t be read, or the top-level JSON value is not an object.
Sourcepub fn get_df(&self) -> Result<Vec<HashMap<String, String>>, BidsError>
pub fn get_df(&self) -> Result<Vec<HashMap<String, String>>, BidsError>
Read a TSV/TSV.GZ file and return rows as Vec<HashMap<String, String>>.
Handles both plain .tsv and gzip-compressed .tsv.gz files. The
BIDS sentinel value n/a is automatically converted to empty strings.
For bulk TSV processing, prefer bids_io::read_tsv / bids_io::read_tsv_gz
which share the same parsing logic but don’t require a BidsFile.
§Errors
Returns an error if the file cannot be read, is empty, or is not a tabular data file.
§Example
let f = BidsFile::new("/data/sub-01/eeg/sub-01_events.tsv");
let rows = f.get_df().unwrap();
for row in &rows {
println!("onset={}, type={}", row["onset"], row["trial_type"]);
}Trait Implementations§
Source§impl<'de> Deserialize<'de> for BidsFile
impl<'de> Deserialize<'de> for BidsFile
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Ord for BidsFile
impl Ord for BidsFile
Source§impl PartialOrd for BidsFile
impl PartialOrd for BidsFile
impl Eq for BidsFile
Auto Trait Implementations§
impl Freeze for BidsFile
impl RefUnwindSafe for BidsFile
impl Send for BidsFile
impl Sync for BidsFile
impl Unpin for BidsFile
impl UnsafeUnpin for BidsFile
impl UnwindSafe for BidsFile
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.