use serde::Serialize;
use serde_json;
use std::io::{self, Write};

/// Minimal annotation carrying only the sequence length.
#[derive(Serialize)]
pub struct BasicAnnotation {
    pub seq_length: usize,
}

impl Annotation for BasicAnnotation {}

/// Serialize `self` as a single-line JSON object into a writer.
pub trait Annotation: Serialize {
    /// Write the annotation as compact JSON into `writer`.
    fn write<W: Write>(&self, writer: &mut W) -> io::Result<()> {
        let s = serde_json::to_string(self).map_err(io::Error::other)?;
        writer.write_all(s.as_bytes())
    }
}
