aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-05-14 19:23:04 +0200
committerHampusM <hampus@hampusmat.com>2023-05-14 19:23:04 +0200
commit7b3e889eca2cfae85c88be99dd8624b47e295cf2 (patch)
tree99fca302514ac870ac1bf9e2b9dfb3b3772d5a80 /README.md
parentf91a47ff6bb03a99ca4c82672ba95aa8729beeb4 (diff)
docs: add readmeHEADv0.1.0master
Diffstat (limited to 'README.md')
-rw-r--r--README.md64
1 files changed, 64 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..8b928a8
--- /dev/null
+++ b/README.md
@@ -0,0 +1,64 @@
+## XML-Stinks
+Powerful, fast & easy manual XML deserialization using abstractions over [quick-xml](https://github.com/tafia/quick-xml).
+
+## Example usage
+```rust
+use std::convert::Infallible;
+
+use xml_stinks::deserializer::buffered::Buffered as BufferedDeserializer;
+use xml_stinks::deserializer::{Deserializer, IgnoreEnd};
+use xml_stinks::tagged::TagStart;
+use xml_stinks::DeserializeTagged;
+
+let mut deserializer =
+ BufferedDeserializer::new("<foo>Baz<bar>DF</bar></foo>".as_bytes());
+
+let foo = deserializer.de_tag::<Foo>("foo", IgnoreEnd::No).unwrap();
+
+assert_eq!(&foo.name, "Baz");
+assert_eq!(foo.bar.num, 223);
+
+struct Foo
+{
+ name: String,
+ bar: Bar,
+}
+
+impl DeserializeTagged for Foo
+{
+ type Error = Infallible;
+
+ fn deserialize<TDeserializer: Deserializer>(
+ start: &TagStart,
+ deserializer: &mut TDeserializer,
+ ) -> Result<Self, Self::Error>
+ {
+ let name = deserializer.de_text().unwrap();
+
+ let bar = deserializer.de_tag::<Bar>("bar", IgnoreEnd::No).unwrap();
+
+ Ok(Self { name, bar })
+ }
+}
+
+struct Bar
+{
+ num: u32,
+}
+
+impl DeserializeTagged for Bar
+{
+ type Error = Infallible;
+
+ fn deserialize<TDeserializer: Deserializer>(
+ start: &TagStart,
+ deserializer: &mut TDeserializer,
+ ) -> Result<Self, Self::Error>
+ {
+ let num = u32::from_str_radix(&deserializer.de_text().unwrap(), 16).unwrap();
+
+ Ok(Self { num })
+ }
+}
+```
+