[][src]Enum rhymessage::ParseStatus

pub enum ParseStatus {
    Complete(usize),
    Incomplete(usize),
}

This enumerates the possible non-error states MessageHeaders can be in after parsing a bit of input.

Examples

use rhymessage::{MessageHeaders, ParseStatus};

let mut headers = MessageHeaders::new();

// `parse` does not consume first line because the next line
// it hasn't seen yet might contain part of the "From" header.
assert_eq!(
    ParseStatus::Incomplete(0),
    headers.parse("From: joe@example.com\r\n")?
);

// So we re-send the "From" line along with the content that follows.
// At this point, `parse` knows it has the full "From" header, and
// consumes it, but not the "To" header, since the next line might
// be a continuation of it.
assert_eq!(
    ParseStatus::Incomplete(23),
    headers.parse(concat!(
        "From: joe@example.com\r\n",
        "To: sal@example.com\r\n",
    ))?
);

// So we re-send the "To" line along with the content that follows.
// At this point, `parse` knows it has the full "To" header, and
// consumes it, but not the "Subject" header, since the next line might
// be a continuation of it.
assert_eq!(
    ParseStatus::Incomplete(21),
    headers.parse(concat!(
        "To: sal@example.com\r\n",
        "Subject: Hello,\r\n",
    ))?
);

// So we re-send the "Subject" line along with the content that
// follows.  At this point, `parse` still doesn't know it has the
// full "Subject" header, so nothing is consumed.
assert_eq!(
    ParseStatus::Incomplete(0),
    headers.parse(concat!(
        "Subject: Hello,\r\n",
        " World!\r\n",
    ))?
);

// So we re-send again with even more content.  At this point,
// `parse` sees the empty line separating headers from body,
// so it can finally consume the "Subject" header as well as
// indicate that parsing the headers is complete.
assert_eq!(
    ParseStatus::Complete(28),
    headers.parse(concat!(
        "Subject: Hello,\r\n",
        " World!\r\n",
        "\r\n",
    ))?
);

Variants

Complete(usize)

The body was found at the attached byte offset in the last input string.

Incomplete(usize)

The body was not found, but all characters up to but not including the attached byte offset were parsed.

The user is expected to call parse again with more input, starting with the unparsed portion of the previous input string, and adding more to it.

Trait Implementations

impl Debug for ParseStatus[src]

impl Eq for ParseStatus[src]

impl PartialEq<ParseStatus> for ParseStatus[src]

impl StructuralEq for ParseStatus[src]

impl StructuralPartialEq for ParseStatus[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.