-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support exporting items and list to yaml files
- Loading branch information
1 parent
79a0237
commit c261dd0
Showing
27 changed files
with
606 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ | |
!crates | ||
!.env | ||
!items.json | ||
!list.json | ||
!list.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,6 @@ target/ | |
# Local JSON 'items.json' and 'list.json' files | ||
*.json | ||
|
||
/sqlite.db | ||
*.yaml | ||
|
||
/sqlite.db |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use std::{fs::File, path::Path}; | ||
|
||
use serde::Serialize; | ||
use thiserror::Error; | ||
|
||
use crate::{item::Item, list::List}; | ||
|
||
pub const ITEMS_YAML_PATH: &str = "items.yaml"; | ||
pub const LIST_YAML_PATH: &str = "list.yaml"; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum ExportError { | ||
#[error("file error: {0}")] | ||
FileError(#[from] std::io::Error), | ||
|
||
#[error("'serde-yaml' error: {0}")] | ||
SerdeYamlError(#[from] serde_yaml::Error), | ||
} | ||
|
||
pub trait YamlSerializable { | ||
fn serialize_to_yaml_and_write<P>(&self, path: P) -> Result<(), ExportError> | ||
where | ||
P: AsRef<Path>, | ||
Self: Serialize, | ||
{ | ||
let file = File::create(path)?; | ||
serde_yaml::to_writer(file, self)?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
impl YamlSerializable for Vec<Item> {} | ||
impl YamlSerializable for List {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.