Crates.io | minimal_object_notation |
lib.rs | minimal_object_notation |
version | 0.1.0 |
source | src |
created_at | 2020-09-25 08:29:32.145209 |
updated_at | 2020-09-25 08:29:32.145209 |
description | Minimal encoding. |
homepage | |
repository | https://github.com/36den/minimal_object_notation |
max_upload_size | |
id | 292762 |
size | 26,119 |
A Rust crate for reading and writing minimimal object notation.
What is 'Minimal Object Notation'? It is a format that comes from simply attaching a name tag and a length tag to some information. For example: greeting|13~Hello, world!
.
miniON
s use minimal_object_notation::*;
let mut minion = MiniON::new("greeting".to_string());
minion.set_content("Hello, world!".to_string());
let minion = minion.to_string();
Will result in a String
containing greeting|13~Hello, world!
.
miniON
s use minimal_object_notation::*;
let data = b"greeting|13~Hello, world!container|23~first|3~ONEsecond|3~TWO";
let mut incr: usize = 0;
// Parse a single object that starts at the position `incr`...
match MiniON::parse_one(data, &mut incr) {
Ok(minion) => {
assert_eq!("greeting",minion.name);
match minion.content {
Some(content) => {
assert_eq!("Hello, world!",content);
},
None => {
panic!("Expected content!");
}
}
},
Err(e) => {
panic!("{}",e.to_string());
}
}
// ... OR parse all (sucessive) miniON objects.
match MiniON::parse_all(data) {
Ok(minions) => {
assert_eq!(minions.len(),2);
assert_eq!("container",minions[1].name);
},
Err(e) => {
panic!("{}",e.to_string());
}
}