Skip to content

Commit c11d7ef

Browse files
committed
Derive Debug, PartialEq, Eq, & Clone when possible
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.
1 parent bbf50f9 commit c11d7ef

File tree

9 files changed

+31
-0
lines changed

9 files changed

+31
-0
lines changed

src/category.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use atom_syndication as atom;
22
use rss;
33

4+
#[derive(Debug, PartialEq, Eq, Clone)]
45
pub struct Category {
56
pub term: String,
67
pub scheme: Option<String>,

src/entry.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,30 @@ use atom_syndication as atom;
22
use rss;
33

44
use std::str::FromStr;
5+
use std::fmt::{Formatter, Debug, Error};
56
use chrono::{DateTime, UTC};
67

78
use category::Category;
89
use link::Link;
910
use person::Person;
1011
use guid::Guid;
1112

13+
#[derive(Clone)]
1214
enum EntryData {
1315
Atom(atom::Entry),
1416
Rss(rss::Item),
1517
}
1618

19+
impl Debug for EntryData {
20+
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
21+
match *self {
22+
EntryData::Atom(_) => write!(f, "Atom(_)"),
23+
EntryData::Rss(_) => write!(f, "Rss(_)"),
24+
}
25+
}
26+
}
27+
28+
#[derive(Debug, Clone)]
1729
pub struct Entry {
1830
// If created from an Atom or RSS entry, this is the original contents
1931
source_data: Option<EntryData>,

src/feed.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use atom_syndication as atom;
22
use rss;
33

44
use std::str::FromStr;
5+
use std::fmt::{Debug, Formatter, Error};
56
use chrono::{DateTime, UTC};
67

78
use link::Link;
@@ -12,13 +13,24 @@ use entry::Entry;
1213
use image::Image;
1314
use text_input::TextInput;
1415

16+
#[derive(Clone)]
1517
enum FeedData {
1618
Atom(atom::Feed),
1719
Rss(rss::Channel),
1820
}
1921

22+
impl Debug for FeedData {
23+
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
24+
match *self {
25+
FeedData::Atom(_) => write!(f, "Atom(_)"),
26+
FeedData::Rss(_) => write!(f, "Rss(_)"),
27+
}
28+
}
29+
}
30+
2031
// A helpful table of approximately equivalent elements can be found here:
2132
// http://www.intertwingly.net/wiki/pie/Rss20AndAtom10Compared#table
33+
#[derive(Debug, Clone)]
2234
pub struct Feed {
2335
// If created from an RSS or Atom feed, this is the original contents
2436
source_data: Option<FeedData>,

src/generator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use atom_syndication as atom;
22

3+
#[derive(Debug, PartialEq, Eq, Clone)]
34
pub struct Generator {
45
pub name: String,
56
pub uri: Option<String>,

src/guid.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use rss;
22

3+
#[derive(Debug, PartialEq, Eq, Clone)]
34
pub struct Guid {
45
pub is_permalink: bool,
56
pub id: String,

src/image.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use rss;
22

3+
#[derive(Debug, PartialEq, Eq, Clone)]
34
pub struct Image {
45
pub url: String,
56
pub title: String,

src/link.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use atom_syndication as atom;
22

3+
#[derive(Debug, PartialEq, Eq, Clone)]
34
pub struct Link {
45
pub href: String,
56
pub rel: Option<String>,

src/person.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use atom_syndication as atom;
22

3+
#[derive(Debug, PartialEq, Clone)]
34
pub struct Person {
45
pub name: String,
56
pub uri: Option<String>,

src/text_input.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use rss;
22

3+
#[derive(Debug, PartialEq, Eq, Clone)]
34
pub struct TextInput {
45
pub title: String,
56
pub description: String,

0 commit comments

Comments
 (0)