lindera_dictionary/builder/
metadata.rs1use std::path::Path;
2
3use log::debug;
4
5use crate::LinderaResult;
6use crate::dictionary::metadata::Metadata;
7use crate::error::LinderaErrorKind;
8
9pub struct MetadataBuilder {}
10
11impl MetadataBuilder {
12 pub fn new() -> Self {
13 Self {}
14 }
15
16 pub fn build(&self, metadata: &Metadata, output_dir: &Path) -> LinderaResult<()> {
17 let json_data = serde_json::to_string_pretty(metadata)
19 .map_err(|err| LinderaErrorKind::Serialize.with_error(anyhow::anyhow!(err)))?;
20
21 let metadata_path = output_dir.join("metadata.json");
22 debug!("writing metadata to {metadata_path:?}");
23
24 std::fs::write(metadata_path, json_data)
26 .map_err(|err| LinderaErrorKind::Io.with_error(anyhow::anyhow!(err)))?;
27
28 Ok(())
29 }
30}
31
32impl Default for MetadataBuilder {
33 fn default() -> Self {
34 Self::new()
35 }
36}