NOTE: Under Construction - I'm in the middle of upgrading my site and lots of stuff is kinda broken. Please forgive the mess.

Create An Atom Feed In Rust

January 2024


This is what I'm doing to make an Atom feed for my site. More notes below the code.

//! ```cargo
//! [dependencies]
//! atom_syndication = "0.12.2"
//! chrono = { version = "0.4.26", features = ["std"] }
//! uuid = { version = "1.6.1", features = ["v5"] }
//! ```

use atom_syndication::*;
use chrono::prelude::*;
use std::collections::BTreeMap;
use std::fs;
use uuid::Uuid;

fn main() {

  let feed_constant_uuid4 = Uuid::try_parse(

  let generation_date = chrono::offset::Utc::now().fixed_offset();

  let author = Person {
    name: "Alan W. Smith".to_string(), 
    email: None,
    uri: Some("https://www.example.com/".to_string())

  let entry_uuid5 = format!("urn:uuid:{}", Uuid::new_v5(
    &feed_constant_uuid4, b"unque_file_id_alfa")

  let entry_title = Text {
    value: "This Is A Title".to_string(),
    base: None, 
    lang: None,
    r#type: TextType::Text

  let tz_hour_offset = 5; 
  let tz = FixedOffset::west_opt(tz_hour_offset * 60 * 60).unwrap();
  let updated_date = NaiveDateTime::parse_from_str("2023-12-17 10:33:55", "%Y-%m-%d %H:%M:%S")

  let entry_content = Some(
    Content {
      base: None, 
      lang: None, 
      value: Some("<p>Hello, world</p>".to_string()),
      src: Some("https://www.example.com/some_path.html".to_string()),
      content_type: Some("html".to_string()),

  let entry = Entry {
      id: entry_uuid5,
      title: entry_title,
      authors: vec![author.clone()],
      categories: vec![],
      content: entry_content,
      summary: None, 
      source: None,
      rights: None, 
      published: None, 
      links: vec![],
      contributors: vec![],
      updated: updated_date,
      extensions: BTreeMap::new() 

  let entries = vec![entry];

  let feed_id = format!(

  let feed_link = Link{
    href: "https://www.example.com/atom.xml".to_string(),
    rel: "self".to_string(),
    hreflang: None, 
    length: None, 
    mime_type: None,
    title: None

  let feed = Feed {
    title: "My Example Feed".into(),
    id: feed_id,
    updated: generation_date,
    authors: vec![author],
    links: vec![feed_link],

  let config = WriteConfig {
    write_document_declaration: true,
    indent_size: Some(2),

  let file = fs::OpenOptions::new()

  // output the file
  feed.write_with_config(&file, config).unwrap();

  // print it for demo
  println!("{}", feed.to_string());
<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>My Example Feed</title>
    <name>Alan W. Smith</name>
  <link href="https://www.example.com/atom.xml" rel="self"/>
    <title>This Is A Title</title>
      <name>Alan W. Smith</name>
    <content type="html" src="https://www.example.com/some_path.html">&lt;p&gt;Hello, world&lt;/p&gt;</content>
═══ § ═══

Footnotes And References