feed_to_rss_xml

Function feed_to_rss_xml 

Source
pub fn feed_to_rss_xml(
    feed: &Feed,
    site_title: &str,
    site_link: &str,
) -> Result<String>
Expand description

Converts a Feed into an RSS 2.0 XML string.

This function generates a fully formatted RSS feed from the provided Feed data structure. Each Link in the feed is converted to an Item in the RSS feed using link_to_rss_item.

§Parameters

  • feed: A reference to a Feed struct containing the feed title and links.
  • site_title: A fallback title for the feed if feed.title is empty.
  • site_link: The canonical URL of the website or feed source; used as the <link> of the channel.

§Returns

Returns a Result<String> containing the RSS XML string if successful.

§Errors

Returns an error if:

  • The channel cannot be serialized into XML.
  • The resulting UTF-8 string cannot be created from the XML buffer.

§Behavior

  • If feed.title is empty, site_title is used as the RSS channel title.
  • Each link’s tags, summary, guid, and publication date are included in the corresponding RSS <item>.
  • The XML is pretty-printed with an indentation of 2 spaces.

§Example

use linkleaf_core::linkleaf_proto::Feed;
use linkleaf_core::feed_to_rss_xml;

let feed = Feed {
    title: "My Links".to_string(),
    links: vec![/* ... */],
    version: 1
};
let rss_xml = feed_to_rss_xml(&feed, "Default Site", "https://example.com")
    .expect("Failed to generate RSS XML");
println!("{}", rss_xml);