molframe_core/io/format/
names.rs1use super::detect::Format;
4use super::options::{AmbiguousResidueBoundaryPolicy, MissingElementPolicy, ParseMode};
5use crate::contract::{PolicyParseError, closed_vocabulary};
6use std::fmt;
7use std::str::FromStr;
8
9closed_vocabulary!(
10 ParseMode,
11 "mode",
12 [
13 (ParseMode::Strict, "strict"),
14 (ParseMode::Permissive, "permissive"),
15 (ParseMode::Recover, "recover"),
16 ]
17);
18
19closed_vocabulary!(
20 MissingElementPolicy,
21 "missing_element",
22 [
23 (MissingElementPolicy::PreserveUnknown, "preserve-unknown"),
24 (
25 MissingElementPolicy::InferFromAtomName,
26 "infer-from-atom-name"
27 ),
28 ]
29);
30
31closed_vocabulary!(
32 AmbiguousResidueBoundaryPolicy,
33 "ambiguous_residue_boundary",
34 [
35 (AmbiguousResidueBoundaryPolicy::Reject, "reject"),
36 (
37 AmbiguousResidueBoundaryPolicy::InferFromFileOrder,
38 "infer-from-file-order"
39 ),
40 ]
41);
42
43impl Format {
44 pub const NAMES: &'static [&'static str] = &[
47 "auto", "mmcif", "pdbml", "bcif", "mmtf", "pdb", "pqr", "pdbqt", "sdf", "mol2", "smallcif",
48 ];
49}
50
51impl fmt::Display for Format {
52 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
53 formatter.write_str(self.name())
54 }
55}
56
57impl FromStr for Format {
58 type Err = PolicyParseError;
59
60 fn from_str(value: &str) -> Result<Self, Self::Err> {
62 Self::parse(value)
63 .ok_or_else(|| PolicyParseError::new("format", value, &Self::NAMES.join(", ")))
64 }
65}
66
67#[cfg(test)]
68#[path = "names_tests.rs"]
69mod tests;