molframe_core/structure/disorder_checked.rs
1//! Altloc resolution for callers that cannot carry a refusal.
2
3use super::Structure;
4use crate::contract::AnalysisPolicy;
5use crate::diagnostic::{Code, Diagnostic};
6use crate::selection::AtomSelection;
7
8impl Structure {
9 /// The atoms an altloc policy selects, with the findings that came with them.
10 ///
11 /// For callers that cannot do anything with a refusal: it becomes the
12 /// diagnostic that explains it. Code that can carry an indeterminate result
13 /// should use [`Structure::resolve_altlocs`] and keep the outcome.
14 ///
15 /// # Errors
16 ///
17 /// Returns the first finding, or [`Code::E3001`], when the policy selects
18 /// no consistent set of atoms.
19 pub fn resolved_atoms(
20 &self,
21 policy: &AnalysisPolicy,
22 ) -> Result<(AtomSelection, Vec<Diagnostic>), Diagnostic> {
23 let resolution = self.resolve_altlocs(policy);
24 let warnings = resolution.warnings.clone();
25 resolution
26 .into_result()
27 .map(|atoms| (atoms, warnings.clone()))
28 .map_err(|_| match warnings.into_iter().next() {
29 Some(finding) => finding,
30 None => Diagnostic::new(Code::E3001),
31 })
32 }
33}