reqtk 0.1.0

ReqTk is a requirements management toolkit built around a human-readable, git-friendly `.req` file format.
Documentation
use crate::*;

pub struct JsonImpex {
    pub spans: bool,
}

impl RequirementTreeImport for JsonImpex {
    fn extension(&self) -> &'static str {
        "json"
    }
    fn import(&self, location: &Location) -> Result<RequirementTree, CommandError> {
        Ok(serde_json::from_reader(location.reader()?).err_localized(location)?)
    }
}

impl RequirementTreeExport for JsonImpex {
    fn extension(&self) -> &'static str {
        "json"
    }

    fn export(
        &self,
        location: &Location,
        mut req_tree: RequirementTree,
    ) -> Result<(), CommandError> {
        if !self.spans {
            req_tree.clear_spans();
        };

        Ok(
            JsonFormatter::serialize_into(location.writer(true)?, &req_tree)
                .err_localized(location)?,
        )
    }
}