pub struct Parser<'a> {
pub position: Position<'a>,
/* private fields */
}Fields§
§position: Position<'a>Implementations§
Source§impl<'a> Parser<'a>
impl<'a> Parser<'a>
Sourcepub fn new(path: &'a Path, src: &'a str) -> Self
pub fn new(path: &'a Path, src: &'a str) -> Self
Examples found in repository?
examples/network.rs (line 84)
70fn main() {
71 // The configuration we're going to parse
72 let config = r#"
73 <config>
74 <server name="localhost" ip="127.0.0.1">
75 <alias>local</alias>
76 <alias>me</alias>
77 </server>
78 <server name="example" ip="10.0.0.101">
79 <alias>example.com</alias>
80 </server>
81 </config>
82 "#;
83 // The parser state machine we'll use to do the work
84 let mut parser = Parser::new(Path::new("example.xml"), config);
85 // Parsing a piece of content from the top of the file.
86 // Content is either a piece of non-xml text or an xml element.
87 match parser.parse::<Option<Result<Content>>>() {
88 Some(Ok(content)) => println!("{content:?}"),
89 Some(Err(e)) => println!("{e}"),
90 None => {
91 let error = parser
92 .position
93 .error("Could not find root config node".into());
94 println!("{error}");
95 }
96 }
97}Sourcepub fn parse<T: Parse<'a>>(&mut self) -> T
pub fn parse<T: Parse<'a>>(&mut self) -> T
Examples found in repository?
examples/network.rs (line 87)
70fn main() {
71 // The configuration we're going to parse
72 let config = r#"
73 <config>
74 <server name="localhost" ip="127.0.0.1">
75 <alias>local</alias>
76 <alias>me</alias>
77 </server>
78 <server name="example" ip="10.0.0.101">
79 <alias>example.com</alias>
80 </server>
81 </config>
82 "#;
83 // The parser state machine we'll use to do the work
84 let mut parser = Parser::new(Path::new("example.xml"), config);
85 // Parsing a piece of content from the top of the file.
86 // Content is either a piece of non-xml text or an xml element.
87 match parser.parse::<Option<Result<Content>>>() {
88 Some(Ok(content)) => println!("{content:?}"),
89 Some(Err(e)) => println!("{e}"),
90 None => {
91 let error = parser
92 .position
93 .error("Could not find root config node".into());
94 println!("{error}");
95 }
96 }
97}Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Parser<'a>
impl<'a> RefUnwindSafe for Parser<'a>
impl<'a> Send for Parser<'a>
impl<'a> Sync for Parser<'a>
impl<'a> Unpin for Parser<'a>
impl<'a> UnwindSafe for Parser<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more