Module atom

Module atom 

Source
Expand description

Atom Syndication Format is an XML based syndication format.

Use Iter as the starting type for parsing a feed.

§Examples

§Atom

use readfeed::atom::{self, Elem, EntryElem, FeedElem};

let input = r#"
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Lorem ipsum dolor sit amet.</title>
    <link href="https://example.com/"/>
    <updated>2021-02-24T09:08:10Z</updated>
    <id>urn:uuid:ba9192e8-9e34-4c23-8445-94b67ba316ee</id>
    <entry>
        <title>Lorem ipsum dolor sit.</title>
        <link href="http://example.com/2021/02/24/hello"/>
        <id>urn:uuid:425ba23c-d283-4580-8a3c-3b67aaa6b373</id>
        <updated>2021-02-24T09:08:10Z</updated>
        <summary>Lorem ipsum dolor sit amet, consectetur adipiscing.</summary>
    </entry>
</feed>
"#;

let mut iter = atom::Iter::new(input);

let Some(Elem::Feed(mut feed_iter)) = iter.next() else {
    panic!();
};

if let Some(FeedElem::Title(title)) = feed_iter.next() {
    assert_eq!("Lorem ipsum dolor sit amet.", title.content());
} else {
    panic!();
}

if let Some(FeedElem::Link(link)) = feed_iter.next() {
    assert_eq!(Some("https://example.com/"), link.href().map(|v| v.as_str()));
} else {
    panic!();
}

if let Some(FeedElem::Updated(updated)) = feed_iter.next() {
    assert_eq!("2021-02-24T09:08:10Z", updated.content());
} else {
    panic!();
}

if let Some(FeedElem::Id(id)) = feed_iter.next() {
    assert_eq!("urn:uuid:ba9192e8-9e34-4c23-8445-94b67ba316ee", id.content());
} else {
    panic!();
}

if let Some(FeedElem::Entry(mut entry_iter)) = feed_iter.next() {
    if let Some(EntryElem::Title(title)) = entry_iter.next() {
        assert_eq!("Lorem ipsum dolor sit.", title.content());
    } else {
        panic!();
    }
    if let Some(EntryElem::Link(link)) = entry_iter.next() {
        assert_eq!(Some("http://example.com/2021/02/24/hello"), link.href().map(|v| v.as_str()));
    } else {
        panic!();
    }
    if let Some(EntryElem::Id(id)) = entry_iter.next() {
        assert_eq!("urn:uuid:425ba23c-d283-4580-8a3c-3b67aaa6b373", id.content());
    } else {
        panic!();
    }
    if let Some(EntryElem::Updated(updated)) = entry_iter.next() {
        assert_eq!("2021-02-24T09:08:10Z", updated.content());
    } else {
        panic!();
    }
    if let Some(EntryElem::Summary(summary)) = entry_iter.next() {
        assert_eq!("Lorem ipsum dolor sit amet, consectetur adipiscing.", summary.content());
    } else {
        panic!();
    }
    assert_eq!(None, entry_iter.next());
} else {
    panic!();
}

assert_eq!(None, feed_iter.next());
assert_eq!(None, iter.next());

Structs§

Category
Content
EntryIter
FeedIter
Generator
Icon
Id
Iter
Link
Logo
PersonEmail
PersonIter
PersonName
PersonUri
Published
Rights
SourceIter
Subtitle
Summary
Title
Unknown
Updated

Enums§

Elem
EntryElem
FeedElem
PersonElem
SourceElem