[−][src]Struct minimal_object_notation::MiniON
Fields
name: String
length: usize
content: Option<String>
Implementations
impl MiniON
[src]
pub fn new(name: String) -> MiniON
[src]
Construct a new MiniON
.
pub fn set_content(&mut self, content: String)
[src]
Set the content of a MiniON
.
pub fn to_string(&self) -> String
[src]
Return the MiniON
as a String
.
Example
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 give you a String
containing "greeting|13~Hello, world!"
.
pub fn parse_one(bytes: &[u8], incr: &mut usize) -> Result<MiniON, Error>
[src]
Parse data into a MiniON
object.
Example
use minimal_object_notation::*; let data = b"greeting|13~Hello, world!"; let mut incr: usize = 0; 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()); } }
pub fn parse_all(bytes: &[u8]) -> Result<Vec<MiniON>, Error>
[src]
Parse data that contains multiple miniON objects ONE AFTER THE OTHER. Will not parse nested miniON objects.
Example
use minimal_object_notation::*; let data = b"first|4~ONE,second|4~TWO,third|6~THREE,container|29~name|5~NAME,content|7~CONTENT"; match MiniON::parse_all(data) { Ok(minions) => { assert_eq!(4,minions.len()); assert_eq!("first",minions[0].name); assert_eq!("second",minions[1].name); assert_eq!("third",minions[2].name); assert_eq!("container",minions[3].name); match &minions[0].content { Some(content) => { assert_eq!("ONE,",content); }, None => { panic!("Expected content!"); } } match &minions[3].content { Some(content) => { assert_eq!("name|5~NAME,content|7~CONTENT",content); }, None => { panic!("Expected content!"); } } }, Err(e) => { panic!("{}",e.to_string()); } }
pub fn find(bytes: &[u8], name: &str) -> Result<MiniON, Error>
[src]
Find a specific miniON object by its name.
Example
use minimal_object_notation::*; let data = b"one|3~ONEtwo|3~TWOthree|5~THREE"; match MiniON::find(data,"two") { Ok(minion) => { assert_eq!("two",minion.name); assert_eq!(Some("TWO".to_string()),minion.content); }, Err(e) => { panic!("{}",e.to_string()); } }
pub fn parse_name(bytes: &[u8], incr: &mut usize) -> Result<String, Error>
[src]
Parse the name of a miniON object. (Start at the correct position.)
Example
use minimal_object_notation::*; let data = b"greeting|13~Hello, world!"; let mut incr: usize = 0; match MiniON::parse_name(data,&mut incr) { Ok(name) => { assert_eq!("greeting",name); assert_eq!(9,incr); }, Err(e) => { panic!("{}",e.to_string()); } }
pub fn parse_length(
bytes: &[u8],
incr: &mut usize,
name: &str
) -> Result<usize, Error>
[src]
bytes: &[u8],
incr: &mut usize,
name: &str
) -> Result<usize, Error>
Parse the length of a miniON object (after having parsed the name tag).
Example
use minimal_object_notation::*; let data = b"greeting|13~Hello, world!"; let mut incr: usize = 9; match MiniON::parse_length(data,&mut incr,"greeting") { Ok(length) => { assert_eq!(13,length); assert_eq!(12,incr); }, Err(e) => { panic!("{}",e.to_string()); } }
pub fn parse_content(
bytes: &[u8],
incr: &mut usize,
name: &str,
length: usize
) -> Result<String, Error>
[src]
bytes: &[u8],
incr: &mut usize,
name: &str,
length: usize
) -> Result<String, Error>
Parse the contents of a miniON object (after having parsed the name and length tags).
Example
use minimal_object_notation::*; let data = b"greeting|13~Hello, world!"; let mut incr: usize = 12; match MiniON::parse_content(data, &mut incr, "greeting", 13) { Ok(content) => { assert_eq!("Hello, world!",content); assert_eq!(incr,data.len()); }, Err(e) => { panic!("{}",e.to_string()); } }
Warning!
Should not be called when the object has a length of 0! This will result in errors!
Auto Trait Implementations
impl RefUnwindSafe for MiniON
impl Send for MiniON
impl Sync for MiniON
impl Unpin for MiniON
impl UnwindSafe for MiniON
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,