molframe_pdb/writer/
stream.rs1use super::pdb::{PdbOptions, render_selected};
4use molframe_core::diagnostic::{Code, Diagnostic};
5use molframe_core::io::{Select, SelectAll, TextOutput};
6use molframe_core::structure::Structure;
7use std::io::Write;
8
9pub fn write_to<W: Write>(
16 structure: &Structure,
17 options: &PdbOptions,
18 output: &mut W,
19) -> Result<(), Vec<Diagnostic>> {
20 write_selected_to(structure, options, &SelectAll, output)
21}
22
23pub fn write_selected_to<W: Write>(
29 structure: &Structure,
30 options: &PdbOptions,
31 select: &impl Select,
32 output: &mut W,
33) -> Result<(), Vec<Diagnostic>> {
34 let mut output = TextOutput::new(output);
35 render_selected(&mut output, structure, options, select)?;
36 output
37 .finish()
38 .map_err(|error| vec![output_diagnostic(error)])
39}
40
41fn output_diagnostic(error: impl std::fmt::Display) -> Diagnostic {
42 Diagnostic::new(Code::E7901).with_context("reason", error.to_string())
43}