#[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
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.
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
impl RssData
Sourcepub fn new(version: Option<RssVersion>) -> Self
pub fn new(version: Option<RssVersion>) -> Self
Sourcepub fn set<T: Into<String>>(self, field: RssDataField, value: T) -> Self
pub fn set<T: Into<String>>(self, field: RssDataField, value: T) -> Self
Sourcepub fn set_item_field<T: Into<String>>(&mut self, field: RssItemField, value: T)
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 theRssItem
.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.
Sourcepub fn validate_size(&self) -> Result<()>
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
).
Sourcepub fn set_image(&mut self, title: &str, url: &str, link: &str)
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.
Sourcepub fn add_item(&mut self, item: RssItem)
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
- TheRssItem
to be added to the feed.
Sourcepub fn remove_item(&mut self, guid: &str) -> bool
pub fn remove_item(&mut self, guid: &str) -> bool
Sourcepub fn item_count(&self) -> usize
pub fn item_count(&self) -> usize
Returns the number of items in the RSS feed.
Sourcepub fn clear_items(&mut self)
pub fn clear_items(&mut self)
Clears all items from the RSS feed.
Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Validates the RssData
to ensure that all required fields are set and valid.
§Returns
Ok(())
if theRssData
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.
Sourcepub fn to_hash_map(&self) -> HashMap<String, String>
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.
Sourcepub fn version(self, version: RssVersion) -> Self
pub fn version(self, version: RssVersion) -> Self
Sets the RSS version.
Sets the author.
Sourcepub fn description<T: Into<String>>(self, value: T) -> Self
pub fn description<T: Into<String>>(self, value: T) -> Self
Sets the description.
Sourcepub fn image_title<T: Into<String>>(self, value: T) -> Self
pub fn image_title<T: Into<String>>(self, value: T) -> Self
Sets the image title.
Sourcepub fn image_link<T: Into<String>>(self, value: T) -> Self
pub fn image_link<T: Into<String>>(self, value: T) -> Self
Sets the image link.
Sourcepub fn last_build_date<T: Into<String>>(self, value: T) -> Self
pub fn last_build_date<T: Into<String>>(self, value: T) -> Self
Sets the last build date.
Sourcepub fn managing_editor<T: Into<String>>(self, value: T) -> Self
pub fn managing_editor<T: Into<String>>(self, value: T) -> Self
Sets the managing editor.