A rust crate to parse bare ComicInfo xml files.
This larger PR adds in a bunch of testing code, and updates the existing documentation. Specifically, it adds: - Roundtrip tests for serializing and deserializing `ComicInfo` structs. The implementation of those don't use `quickcheck`, but rather explicitly written `generate_XXX` functions in `mod tests`. - Generated tests for the "convenience" functions (e.g. `add_many_writers`). These are made with a macro, similar to how the functions themselves are made with a macro. - Relevant documentation for the above 2 points It changes: - The "set-esque" fields on `ComicInfo` structs are now `Option<IndexSet<String>>` so deserializing them is easier. It fixes: - Bugs in (de-)serialization logic. - Bugs in percent-encoding logic (for the `Web` field). Co-authored-by: Daniel Barenholz <hello@dbarenholz.com> Reviewed-on: #3 |
||
|---|---|---|
| .forgejo/workflows | ||
| src | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| LICENSE | ||
| README.md | ||
comicinfo
A tiny Rust crate to parse ComicInfo.xml files.
Installation
Once available on crates.io, use cargo to add this to your project: cargo add comicinfo
There are no feature flags.
Usage
The default version for the comicinfo spec is 2.1 (Draft), which is probably what you want.
use comicinfo::ComicInfo; // refers to the default version
let xml = std::fs::read_to_string("ComicInfo.xml")?;
let comicinfo = ComicInfo::from_str(&xml)?;
println!("Series: {}", info.series.unwrap_or_default());
Otherwise, import a specific version of the spec
use comicinfo::v2_0::ComicInfo; // explicitly use version 2.0
let xml = std::fs::read_to_string("ComicInfo.xml")?;
let comicinfo = ComicInfo::from_str(&xml)?;
println!("Series: {}", info.series.unwrap_or_default());
Please see the examples on the docs site for more details.
Dependencies
We depend on serde with the derive feature flag, and serde-xml-rs to make serde available for xml files. Internally we use indexset for collections on ComicInfo objects, and have a macro that requires paste to generate setters/getters and convenience methods. For property testing we need something that can generate random stuff, so we use rand.