Skip to content

Commit

Permalink
Derive builders with Into<T> and default values
Browse files Browse the repository at this point in the history
  • Loading branch information
James Hurst committed Jul 16, 2017
1 parent 9935b2e commit e72b20a
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ include = ["src/*", "Cargo.toml", "LICENSE-MIT", "LICENSE-APACHE", "README.md"]

[dependencies]
quick-xml = "0.8"
derive_builder = { version = "0.4", features = ["private_fields"] }
derive_builder = "0.5"
1 change: 1 addition & 0 deletions src/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use toxml::ToXml;

/// Represents a category in an Atom feed
#[derive(Debug, Default, Clone, PartialEq, Builder)]
#[builder(setter(into), default)]
pub struct Category {
/// Identifies the category.
term: String,
Expand Down
1 change: 1 addition & 0 deletions src/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use util::atom_text;

/// Represents the content of an Atom entry
#[derive(Debug, Default, Clone, PartialEq, Builder)]
#[builder(setter(into), default)]
pub struct Content {
/// The text value of the content.
value: Option<String>,
Expand Down
1 change: 1 addition & 0 deletions src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use util::atom_text;

/// Represents an entry in an Atom feed
#[derive(Debug, Default, Clone, PartialEq, Builder)]
#[builder(setter(into), default)]
pub struct Entry {
/// A human-readable title for the entry.
title: String,
Expand Down
1 change: 1 addition & 0 deletions src/extension/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub type ExtensionMap = HashMap<String, HashMap<String, Vec<Extension>>>;

/// A namespaced extension.
#[derive(Debug, Default, Clone, PartialEq, Builder)]
#[builder(setter(into), default)]
pub struct Extension {
/// The qualified name of the extension element.
name: String,
Expand Down
6 changes: 5 additions & 1 deletion src/feed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use util::atom_text;

/// Represents an Atom feed
#[derive(Debug, Default, Clone, PartialEq, Builder)]
#[builder(setter(into), default)]
pub struct Feed {
/// A human-readable title for the feed.
title: String,
Expand Down Expand Up @@ -699,7 +700,10 @@ impl ToXml for Feed {
fn to_xml<W: Write>(&self, writer: &mut Writer<W>) -> Result<(), XmlError> {
let name = b"feed";
let mut element = BytesStart::borrowed(name, name.len());
element.push_attribute(("xmlns".as_bytes(), "http://www.w3.org/2005/Atom".as_bytes()));
element.push_attribute((
"xmlns".as_bytes(),
"http://www.w3.org/2005/Atom".as_bytes(),
));

for (ns, uri) in &self.namespaces {
element.push_attribute((format!("xmlns:{}", ns).as_bytes(), uri.as_bytes()));
Expand Down
1 change: 1 addition & 0 deletions src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use util::atom_text;

/// Represents the generator of an Atom feed
#[derive(Debug, Default, Clone, PartialEq, Builder)]
#[builder(setter(into), default)]
pub struct Generator {
/// The name of the generator.
value: String,
Expand Down
1 change: 1 addition & 0 deletions src/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use toxml::ToXml;

/// Represents a link in an Atom feed
#[derive(Debug, Clone, PartialEq, Builder)]
#[builder(setter(into), default)]
pub struct Link {
/// The URI of the referenced resource.
href: String,
Expand Down
1 change: 1 addition & 0 deletions src/person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use util::atom_text;

/// Represents a person in an Atom feed
#[derive(Debug, Default, Clone, PartialEq, Builder)]
#[builder(setter(into), default)]
pub struct Person {
/// A human-readable name for the person.
name: String,
Expand Down
1 change: 1 addition & 0 deletions src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use util::atom_text;

/// Represents the source of an Atom entry
#[derive(Debug, Default, Clone, PartialEq, Builder)]
#[builder(setter(into), default)]
pub struct Source {
/// A human-readable title for the feed.
title: String,
Expand Down

0 comments on commit e72b20a

Please sign in to comment.