#[cfg(feature = "chemfiles")]
#[path = "chemfiles_import_imp.rs"]
mod imp;
#[cfg(feature = "chemfiles")]
pub use imp::*;
#[cfg(not(feature = "chemfiles"))]
mod stubs {
use std::fmt;
use std::path::Path;
use crate::types::ConFrame;
pub const CHEMFILES_EXTRA_PREFIX: &str = "chemfiles::";
pub const CHEMFILES_ATOM_PROPS_KEY: &str = "chemfiles_atom_properties";
pub const CHEMFILES_ATOM_NAMES_KEY: &str = "chemfiles_atom_names";
pub const CHEMFILES_ATOM_TYPES_KEY: &str = "chemfiles_atom_types";
#[derive(Debug)]
pub enum ChemfilesImportError {
InvalidFrame(String),
Io(std::io::Error),
FeatureDisabled,
}
impl fmt::Display for ChemfilesImportError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ChemfilesImportError::InvalidFrame(msg) => {
write!(f, "invalid chemfiles frame: {msg}")
}
ChemfilesImportError::Io(e) => write!(f, "I/O error: {e}"),
ChemfilesImportError::FeatureDisabled => write!(
f,
"chemfiles support is not enabled in this build; rebuild with `--features chemfiles` \
(Python: `maturin develop --features python,chemfiles` or install the `chemfiles` extra from source — see docs)"
),
}
}
}
impl std::error::Error for ChemfilesImportError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
ChemfilesImportError::Io(e) => Some(e),
ChemfilesImportError::InvalidFrame(_) | ChemfilesImportError::FeatureDisabled => {
None
}
}
}
}
impl From<std::io::Error> for ChemfilesImportError {
fn from(e: std::io::Error) -> Self {
ChemfilesImportError::Io(e)
}
}
fn disabled<T>() -> Result<T, ChemfilesImportError> {
Err(ChemfilesImportError::FeatureDisabled)
}
pub fn con_frames_from_trajectory_path<P: AsRef<Path>>(
_path: P,
) -> Result<Vec<ConFrame>, ChemfilesImportError> {
disabled()
}
pub fn con_frame_from_trajectory_path<P: AsRef<Path>>(
_path: P,
) -> Result<ConFrame, ChemfilesImportError> {
disabled()
}
pub fn con_frames_from_memory(
_data: &str,
_format: &str,
) -> Result<Vec<ConFrame>, ChemfilesImportError> {
disabled()
}
pub const fn chemfiles_enabled() -> bool {
false
}
}
#[cfg(not(feature = "chemfiles"))]
pub use stubs::*;
#[cfg(feature = "chemfiles")]
pub const fn chemfiles_enabled() -> bool {
true
}
#[cfg(test)]
mod stub_tests {
use super::*;
#[test]
fn chemfiles_enabled_matches_feature() {
assert_eq!(chemfiles_enabled(), cfg!(feature = "chemfiles"));
}
#[cfg(not(feature = "chemfiles"))]
#[test]
fn trajectory_path_stub_is_feature_disabled() {
let err = con_frame_from_trajectory_path("nope.xyz").unwrap_err();
assert!(matches!(err, ChemfilesImportError::FeatureDisabled));
let msg = err.to_string();
assert!(msg.contains("chemfiles"), "{msg}");
}
}