Struct Feed

Source
pub struct Feed { /* private fields */ }
Expand description

A list of items with associated metadata.

The type provides a view into a JSON object value with accessor methods for the standard properties. Feed owns the underlying JSON object data and provides methods to access the backing object itself with as_map, as_map_mut, and into_inner.

The underlying data is not guaranteed to be a valid JSON Feed.

§Valid Feed

A Feed must have the version set to a valid JSON Feed version value, the title property set, and the items property set.

§Example

use json_feed_model::{Feed};
let json = serde_json::json!({
    "version": "https://jsonfeed.org/version/1.1",
    "title": "Lorem ipsum dolor sit amet.",
    "home_page_url": "https://example.org/",
    "feed_url": "https://example.org/feed.json",
    "items": [
        {
            "id": "cd7f0673-8e81-4e13-b273-4bd1b83967d0",
            "content_text": "Aenean tristique dictum mauris, et.",
            "url": "https://example.org/aenean-tristique"
        },
        {
            "id": "2bcb497d-c40b-4493-b5ae-bc63c74b48fa",
            "content_html": "Vestibulum non magna vitae tortor.",
            "url": "https://example.org/vestibulum-non"
        }
    ]
});
let feed = json_feed_model::from_value(json).unwrap();
assert_eq!(feed.version()?, Some(json_feed_model::VERSION_1_1));
assert_eq!(feed.title()?, Some("Lorem ipsum dolor sit amet."));
assert_eq!(feed.home_page_url()?, Some("https://example.org/"));
assert_eq!(feed.feed_url()?, Some("https://example.org/feed.json"));

let items = feed.items()?;
let items = items.unwrap();
assert_eq!(items.len(), 2);

assert_eq!(items[0].id()?, Some("cd7f0673-8e81-4e13-b273-4bd1b83967d0"));
assert_eq!(
    items[0].content_text()?,
    Some("Aenean tristique dictum mauris, et.")
);
assert_eq!(
    items[0].url()?,
    Some("https://example.org/aenean-tristique")
);

assert_eq!(items[1].id()?, Some("2bcb497d-c40b-4493-b5ae-bc63c74b48fa"));
assert_eq!(
    items[1].content_html()?,
    Some("Vestibulum non magna vitae tortor.")
);
assert_eq!(items[1].url()?, Some("https://example.org/vestibulum-non"));

Implementations§

Source§

impl Feed

Source

pub fn new() -> Self

Instantiates with an empty JSON object.

Source

pub fn as_map(&self) -> &Map<String, Value>

Returns the inner Map as a reference.

Source

pub fn as_map_mut(&mut self) -> &mut Map<String, Value>

Returns the inner Map as a mutable reference.

Source

pub fn into_inner(self) -> Map<String, Value>

Converts the type into the inner Map.

Source

pub fn version(&self) -> Result<Option<&str>, Error>

The required URL formatted version identifier.

Identifies what version of the spec the feed is suppose to be compliant with.

Source

pub fn set_version<T>(&mut self, value: T) -> Option<Value>
where T: ToString,

Sets the version identifier.

Source

pub fn remove_version(&mut self) -> Option<Value>

Removes the version identifier.

Source

pub fn title(&self) -> Result<Option<&str>, Error>

The optional name of the feed.

Source

pub fn set_title<T>(&mut self, value: T) -> Option<Value>
where T: ToString,

Sets the name of the feed.

Source

pub fn remove_title(&mut self) -> Option<Value>

Removes the name of the feed.

Source

pub fn home_page_url(&self) -> Result<Option<&str>, Error>

The optional URL which the feed is suppose to represent.

Source

pub fn set_home_page_url<T>(&mut self, value: T) -> Option<Value>
where T: ToString,

Sets the home page URL.

Source

pub fn remove_home_page_url(&mut self) -> Option<Value>

Removes the home page URL.

Source

pub fn feed_url(&self) -> Result<Option<&str>, Error>

The optional URL which this feed can be retrieived from.

Source

pub fn set_feed_url<T>(&mut self, value: T) -> Option<Value>
where T: ToString,

Sets the feed URL.

Source

pub fn remove_feed_url(&mut self) -> Option<Value>

Removes the feed URL.

Source

pub fn description(&self) -> Result<Option<&str>, Error>

An optional description of the feed.

Source

pub fn set_description<T>(&mut self, value: T) -> Option<Value>
where T: ToString,

Sets the description of the feed.

Source

pub fn remove_description(&mut self) -> Option<Value>

Removes the description of the feed.

Source

pub fn user_comment(&self) -> Result<Option<&str>, Error>

An optional meta description about the feed only intended to be viewed in the raw JSON form.

Source

pub fn set_user_comment<T>(&mut self, value: T) -> Option<Value>
where T: ToString,

Sets the user comment.

Source

pub fn remove_user_comment(&mut self) -> Option<Value>

Removes the user comment.

Source

pub fn next_url(&self) -> Result<Option<&str>, Error>

An optional pagination URL.

Source

pub fn set_next_url<T>(&mut self, value: T) -> Option<Value>
where T: ToString,

Sets the next URL.

Source

pub fn remove_next_url(&mut self) -> Option<Value>

Removes the next URL.

Source

pub fn icon(&self) -> Result<Option<&str>, Error>

An optional URL to an icon for use in a list of items.

Source

pub fn set_icon<T>(&mut self, value: T) -> Option<Value>
where T: ToString,

Sets the icon.

Source

pub fn remove_icon(&mut self) -> Option<Value>

Removes the icon.

Source

pub fn favicon(&self) -> Result<Option<&str>, Error>

An optional URL to a favicon suitable for use in a list of feeds.

Source

pub fn set_favicon<T>(&mut self, value: T) -> Option<Value>
where T: ToString,

Sets the favicon URL.

Source

pub fn remove_favicon(&mut self) -> Option<Value>

Removes the favicon URL.

Source

pub fn author(&self) -> Result<Option<AuthorRef<'_>>, Error>

An optional author.

§Deprecation

The author field is deprecated in favor of the authors field as of JSON Feed 1.1.

Source

pub fn author_mut(&mut self) -> Result<Option<AuthorMut<'_>>, Error>

An optional author.

§Deprecation

The author field is deprecated in favor of the authors field as of JSON Feed 1.1.

Source

pub fn set_author(&mut self, value: Author) -> Option<Value>

Sets the author.

Source

pub fn remove_author(&mut self) -> Option<Value>

Removes the author.

Source

pub fn authors(&self) -> Result<Option<Vec<AuthorRef<'_>>>, Error>

An optional array of authors.

Source

pub fn authors_mut(&mut self) -> Result<Option<Vec<AuthorMut<'_>>>, Error>

An optional array of authors.

Source

pub fn set_authors<I>(&mut self, items: I) -> Option<Value>
where I: IntoIterator<Item = Author>,

Sets the authors.

Source

pub fn remove_authors(&mut self) -> Option<Value>

Removes the authors.

Source

pub fn language(&self) -> Result<Option<&str>, Error>

The optional language which the feed data is written in.

Valid values are from RFC 5646.

Source

pub fn set_language<T>(&mut self, value: T) -> Option<Value>
where T: ToString,

Sets the language.

Source

pub fn remove_language(&mut self) -> Option<Value>

Removes the language.

Source

pub fn expired(&self) -> Result<Option<bool>, Error>

Optionally determines if the feed will be updated in the future.

If true, the feed will not be updated in the future. If false or None, then the feed may be updated in the future.

Source

pub fn set_expired<T>(&mut self, value: bool) -> Option<Value>

Sets the expired flag.

Source

pub fn remove_expired(&mut self) -> Option<Value>

Removes the expired flag.

Source

pub fn hubs(&self) -> Result<Option<Vec<HubRef<'_>>>, Error>

Optional subscription endpoints which can be used to received feed update notifications.

Source

pub fn hubs_mut(&mut self) -> Result<Option<Vec<HubMut<'_>>>, Error>

Subscription endpoints which can be used to received feed update notifications.

Source

pub fn set_hubs<I>(&mut self, items: I) -> Option<Value>
where I: IntoIterator<Item = Hub>,

Sets the hubs.

Source

pub fn remove_hubs(&mut self) -> Option<Value>

Removes the hubs.

Source

pub fn items(&self) -> Result<Option<Vec<ItemRef<'_>>>, Error>

A required array of Items.

Source

pub fn items_mut(&mut self) -> Result<Option<Vec<ItemMut<'_>>>, Error>

A required array of Items.

Source

pub fn set_items<I>(&mut self, items: I) -> Option<Value>
where I: IntoIterator<Item = Item>,

Sets the items.

Source

pub fn remove_items(&mut self) -> Option<Value>

Removes the items.

Source§

impl Feed

Source

pub fn is_valid(&self, version: &Version<'_>) -> bool

Verifies if the JSON data complies with a specific Version of the JSON Feed spec.

Trait Implementations§

Source§

impl AsMut<Map<String, Value>> for Feed

Source§

fn as_mut(&mut self) -> &mut Map<String, Value>

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<Map<String, Value>> for Feed

Source§

fn as_ref(&self) -> &Map<String, Value>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Feed

Source§

fn clone(&self) -> Feed

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

impl Debug for Feed

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Feed

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Feed

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Map<String, Value>> for Feed

Source§

fn from(value: Map<String, Value>) -> Self

Converts to this type from the input type.
Source§

impl PartialEq<Map<String, Value>> for Feed

Source§

fn eq(&self, other: &Map<String, Value>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for Feed

Source§

fn eq(&self, other: &Feed) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Feed

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Feed

Auto Trait Implementations§

§

impl Freeze for Feed

§

impl RefUnwindSafe for Feed

§

impl Send for Feed

§

impl Sync for Feed

§

impl Unpin for Feed

§

impl UnwindSafe for Feed

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,