Skip to content

Commit

Permalink
Derive Debug, PartialEq, Eq, & Clone when possible
Browse files Browse the repository at this point in the history
EntryData and FeedData need an explicitly implementation of Debug
because the atom types don't support it, and we probably don't want to
show the contained feeds anyway.
  • Loading branch information
porglezomp committed Jun 15, 2016
1 parent bbf50f9 commit c11d7ef
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/category.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use atom_syndication as atom;
use rss;

#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Category {
pub term: String,
pub scheme: Option<String>,
Expand Down
12 changes: 12 additions & 0 deletions src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,30 @@ use atom_syndication as atom;
use rss;

use std::str::FromStr;
use std::fmt::{Formatter, Debug, Error};
use chrono::{DateTime, UTC};

use category::Category;
use link::Link;
use person::Person;
use guid::Guid;

#[derive(Clone)]
enum EntryData {
Atom(atom::Entry),
Rss(rss::Item),
}

impl Debug for EntryData {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
match *self {
EntryData::Atom(_) => write!(f, "Atom(_)"),
EntryData::Rss(_) => write!(f, "Rss(_)"),
}
}
}

#[derive(Debug, Clone)]
pub struct Entry {
// If created from an Atom or RSS entry, this is the original contents
source_data: Option<EntryData>,
Expand Down
12 changes: 12 additions & 0 deletions src/feed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use atom_syndication as atom;
use rss;

use std::str::FromStr;
use std::fmt::{Debug, Formatter, Error};
use chrono::{DateTime, UTC};

use link::Link;
Expand All @@ -12,13 +13,24 @@ use entry::Entry;
use image::Image;
use text_input::TextInput;

#[derive(Clone)]
enum FeedData {
Atom(atom::Feed),
Rss(rss::Channel),
}

impl Debug for FeedData {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
match *self {
FeedData::Atom(_) => write!(f, "Atom(_)"),
FeedData::Rss(_) => write!(f, "Rss(_)"),
}
}
}

// A helpful table of approximately equivalent elements can be found here:
// http://www.intertwingly.net/wiki/pie/Rss20AndAtom10Compared#table
#[derive(Debug, Clone)]
pub struct Feed {
// If created from an RSS or Atom feed, this is the original contents
source_data: Option<FeedData>,
Expand Down
1 change: 1 addition & 0 deletions src/generator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use atom_syndication as atom;

#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Generator {
pub name: String,
pub uri: Option<String>,
Expand Down
1 change: 1 addition & 0 deletions src/guid.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use rss;

#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Guid {
pub is_permalink: bool,
pub id: String,
Expand Down
1 change: 1 addition & 0 deletions src/image.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use rss;

#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Image {
pub url: String,
pub title: String,
Expand Down
1 change: 1 addition & 0 deletions src/link.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use atom_syndication as atom;

#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Link {
pub href: String,
pub rel: Option<String>,
Expand Down
1 change: 1 addition & 0 deletions src/person.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use atom_syndication as atom;

#[derive(Debug, PartialEq, Clone)]
pub struct Person {
pub name: String,
pub uri: Option<String>,
Expand Down
1 change: 1 addition & 0 deletions src/text_input.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use rss;

#[derive(Debug, PartialEq, Eq, Clone)]
pub struct TextInput {
pub title: String,
pub description: String,
Expand Down

0 comments on commit c11d7ef

Please sign in to comment.