brrrr_lib/
writer.rs

1// (c) Copyright 2020 Trent Hauck
2// All Rights Reserved
3
4use serde::ser::Serialize;
5
6use std::io::Result;
7
8/// A RecordWriter writes FASTA records to the underlying source.
9///
10/// Implement this trait in order to read bioinformatic formats and write it the paricular
11/// underlying format.
12///
13/// # Examples
14///
15/// ```ignore
16/// // Given our `JsonRecordWriter`, implementing the RecordWriter means it's possible to
17/// // write records in json to underlying structs that implement Write.
18///
19/// use serde::Serialize;
20///
21/// use std::io::Result;
22/// use std::io::Write;
23///
24/// use brrrr_lib::writer;
25///
26/// impl<W: Write> writer::RecordWriter for JsonRecordWriter<W> {
27///     fn write_serde_record<S: Serialize>(&mut self, r: S) -> Result<()> {
28///         serde_json::to_writer(&mut self.writer, &r)?;
29///         self.writer.write_all(b"\n")?;
30///
31///         Ok(())
32///     }
33/// }
34/// ```
35pub trait RecordWriter {
36    fn write_serde_record<S: Serialize>(&mut self, r: S) -> Result<()>;
37}