med64 0.0.2

Headless MED64 electrophysiology toolkit: .modat I/O, spike/burst analysis, assays, spike-rate maps, and CSV/HTML/SVG/HDF5 export
Documentation
use std::path::Path;

use crate::reader::{is_modat_file, is_moflo_file};

/// Supported MED64 file formats.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum FileFormat {
    /// Binary 64-channel electrophysiology recording.
    Modat,
    /// Legacy / alias MED64 binary (same header as `.modat`).
    Dat,
    /// Extended / compressed MED64 stream (`FileReaderDax`).
    Dax,
    /// PRESTO / XML-augmented recording (`FileReaderPmodax1`).
    Modax,
    /// workflow XML protocol.
    Moflo,
    /// Comma-separated waveform export (`time_ms,channel,counts,millivolts`).
    Csv,
    /// JSON export (metadata + optional samples).
    Json,
}

impl FileFormat {
    pub fn from_path(path: &Path) -> Option<Self> {
        if is_modat_file(path) {
            Some(Self::Modat)
        } else if is_moflo_file(path) {
            Some(Self::Moflo)
        } else {
            path.extension().and_then(|ext| ext.to_str()).and_then(|ext| {
                match ext.to_ascii_lowercase().as_str() {
                    "dat" => Some(Self::Dat),
                    "dax" => Some(Self::Dax),
                    "modax" => Some(Self::Modax),
                    "csv" => Some(Self::Csv),
                    "json" => Some(Self::Json),
                    _ => None,
                }
            })
        }
    }

    pub fn extension(self) -> &'static str {
        match self {
            Self::Modat => "modat",
            Self::Dat => "dat",
            Self::Dax => "dax",
            Self::Modax => "modax",
            Self::Moflo => "moflo",
            Self::Csv => "csv",
            Self::Json => "json",
        }
    }

    pub fn is_readable(self) -> bool {
        matches!(self, Self::Modat | Self::Dat | Self::Dax | Self::Modax | Self::Moflo)
    }

    pub fn is_writable(self) -> bool {
        matches!(self, Self::Modat | Self::Csv | Self::Json)
    }

    pub fn is_waveform(self) -> bool {
        matches!(self, Self::Modat | Self::Dat | Self::Dax | Self::Modax)
    }
}