Struct Parser

Source
pub struct Parser<'a> {
    pub position: Position<'a>,
    /* private fields */
}

Fields§

§position: Position<'a>

Implementations§

Source§

impl<'a> Parser<'a>

Source

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}
Source

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§

Source§

impl<'a> Clone for Parser<'a>

Source§

fn clone(&self) -> Parser<'a>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.