rss_gen::data

Struct RssData

Source
#[non_exhaustive]
pub struct RssData {
Show 23 fields pub atom_link: String, pub author: String, pub category: String, pub copyright: String, pub description: String, pub docs: String, pub generator: String, pub guid: String, pub image_title: String, pub image_url: String, pub image_link: String, pub language: String, pub last_build_date: String, pub link: String, pub managing_editor: String, pub pub_date: String, pub title: String, pub ttl: String, pub webmaster: String, pub items: Vec<RssItem>, pub version: RssVersion, pub creator: String, pub date: String,
}
Expand description

Represents the main structure for an RSS feed.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§atom_link: String

The Atom link of the RSS feed.

§author: String

The author of the RSS feed.

§category: String

The category of the RSS feed.

§copyright: String

The copyright notice for the content of the feed.

§description: String

The description of the RSS feed.

§docs: String

The docs link of the RSS feed.

§generator: String

The generator of the RSS feed.

§guid: String

The GUID of the RSS feed.

§image_title: String

The image title of the RSS feed.

§image_url: String

The image URL of the RSS feed.

§image_link: String

The image link of the RSS feed.

§language: String

The language of the RSS feed.

§last_build_date: String

The last build date of the RSS feed.

§link: String

The main link to the RSS feed.

§managing_editor: String

The managing editor of the RSS feed.

§pub_date: String

The publication date of the RSS feed.

§title: String

The title of the RSS feed.

§ttl: String

Time To Live (TTL), the number of minutes the feed should be cached before refreshing.

§webmaster: String

The webmaster of the RSS feed.

§items: Vec<RssItem>

A collection of additional items in the RSS feed.

§version: RssVersion

The version of the RSS feed.

§creator: String

The creator of the RSS feed.

§date: String

The date the RSS feed was created.

Implementations§

Source§

impl RssData

Source

pub fn new(version: Option<RssVersion>) -> Self

Creates a new RssData instance with default values and a specified RSS version.

§Arguments
  • version - An optional RssVersion specifying the RSS version for the feed.
§Returns

A new RssData instance.

Source

pub fn set<T: Into<String>>(self, field: RssDataField, value: T) -> Self

Sets the value of a specified field and returns the RssData instance for method chaining.

§Arguments
  • field - The field to set.
  • value - The value to assign to the field.
§Returns

The updated RssData instance.

Source

pub fn set_item_field<T: Into<String>>(&mut self, field: RssItemField, value: T)

Sets the value of a specified field for the last RssItem and updates it.

§Arguments
  • field - The field to set for the RssItem.
  • value - The value to assign to the field.
§Panics

This function will panic if self.items is empty, as it uses .unwrap() to retrieve the last mutable item in the list.

Ensure that self.items contains at least one RssItem before calling this method.

Source

pub fn validate_size(&self) -> Result<()>

Validates the size of the RSS feed to ensure it does not exceed the maximum allowed size.

§Returns
  • Ok(()) if the feed size is valid.
  • Err(RssError) if the feed size exceeds the maximum allowed size.
§Errors

This function returns an Err(RssError::InvalidInput) if the total size of the feed exceeds the maximum allowed size (MAX_FEED_SIZE).

Source

pub fn set_image(&mut self, title: &str, url: &str, link: &str)

Sets the image for the RSS feed.

§Arguments
  • title - The title of the image.
  • url - The URL of the image.
  • link - The link associated with the image.
Source

pub fn add_item(&mut self, item: RssItem)

Adds an item to the RSS feed.

This method appends the given RssItem to the items vector of the RssData struct.

§Arguments
  • item - The RssItem to be added to the feed.
Source

pub fn remove_item(&mut self, guid: &str) -> bool

Removes an item from the RSS feed by its GUID.

§Arguments
  • guid - The GUID of the item to remove.
§Returns

true if an item was removed, false otherwise.

Source

pub fn item_count(&self) -> usize

Returns the number of items in the RSS feed.

Source

pub fn clear_items(&mut self)

Clears all items from the RSS feed.

Source

pub fn validate(&self) -> Result<()>

Validates the RssData to ensure that all required fields are set and valid.

§Returns
  • Ok(()) if the RssData is valid.
  • Err(RssError) if any validation errors are found.
§Errors

This function returns an Err(RssError) in the following cases:

  • RssError::InvalidInput if the category exceeds the maximum allowed length.
  • RssError::ValidationErrors if there are missing or invalid fields (e.g., title, link, description, publication date).

Additionally, it can return an error if the link format is invalid or the publication date cannot be parsed.

Source

pub fn to_hash_map(&self) -> HashMap<String, String>

Converts the RssData into a HashMap<String, String> for easier manipulation.

§Returns

A HashMap<String, String> containing the RSS feed data.

Source

pub fn version(self, version: RssVersion) -> Self

Sets the RSS version.

Sets the Atom link.

Source

pub fn author<T: Into<String>>(self, value: T) -> Self

Sets the author.

Source

pub fn category<T: Into<String>>(self, value: T) -> Self

Sets the category.

Source

pub fn copyright<T: Into<String>>(self, value: T) -> Self

Sets the copyright.

Source

pub fn description<T: Into<String>>(self, value: T) -> Self

Sets the description.

Source

pub fn docs<T: Into<String>>(self, value: T) -> Self

Sets the docs link.

Source

pub fn generator<T: Into<String>>(self, value: T) -> Self

Sets the generator.

Source

pub fn guid<T: Into<String>>(self, value: T) -> Self

Sets the GUID.

Source

pub fn image_title<T: Into<String>>(self, value: T) -> Self

Sets the image title.

Source

pub fn image_url<T: Into<String>>(self, value: T) -> Self

Sets the image URL.

Sets the image link.

Source

pub fn language<T: Into<String>>(self, value: T) -> Self

Sets the language.

Source

pub fn last_build_date<T: Into<String>>(self, value: T) -> Self

Sets the last build date.

Sets the main link.

Source

pub fn managing_editor<T: Into<String>>(self, value: T) -> Self

Sets the managing editor.

Source

pub fn pub_date<T: Into<String>>(self, value: T) -> Self

Sets the publication date.

Source

pub fn title<T: Into<String>>(self, value: T) -> Self

Sets the title.

Source

pub fn ttl<T: Into<String>>(self, value: T) -> Self

Sets the TTL (Time To Live).

Source

pub fn webmaster<T: Into<String>>(self, value: T) -> Self

Sets the webmaster.

Trait Implementations§

Source§

impl Clone for RssData

Source§

fn clone(&self) -> RssData

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 RssData

Source§

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

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

impl Default for RssData

Source§

fn default() -> RssData

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

impl<'de> Deserialize<'de> for RssData

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 PartialEq for RssData

Source§

fn eq(&self, other: &RssData) -> 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 RssData

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 StructuralPartialEq for RssData

Auto Trait Implementations§

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

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

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T