diff options
author | Hendrik Sollich <hendrik@hoodie.de> | 2016-11-20 18:22:33 +0100 |
---|---|---|
committer | Hendrik Sollich <hendrik@hoodie.de> | 2016-11-20 18:22:33 +0100 |
commit | a5ca909f3ef7779c99085701b95c589b1de9ed86 (patch) | |
tree | 96a125aed0aad0f3f5dbad39b4f54398dcf6abb9 | |
parent | 88c9d6b5a4fb0588db8d827e543fd3b960faffdf (diff) |
stricter lints
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | examples/write.rs | 1 | ||||
-rw-r--r-- | src/calendar.rs | 5 | ||||
-rw-r--r-- | src/components.rs | 18 | ||||
-rw-r--r-- | src/lib.rs | 14 | ||||
-rw-r--r-- | src/properties.rs | 37 |
6 files changed, 68 insertions, 9 deletions
@@ -10,4 +10,4 @@ error-chain = "*" [dependencies.uuid] features = ["v4"] -version = "0.2" +version = "0.3" diff --git a/examples/write.rs b/examples/write.rs index 49d94e9..cd8891f 100644 --- a/examples/write.rs +++ b/examples/write.rs @@ -1,6 +1,5 @@ extern crate chrono; extern crate icalendar; - use chrono::*; use icalendar::*; diff --git a/src/calendar.rs b/src/calendar.rs index cfffb97..d7cd121 100644 --- a/src/calendar.rs +++ b/src/calendar.rs @@ -39,6 +39,8 @@ pub struct Calendar { } impl Calendar { + + /// Creates a new Calendar. pub fn new() -> Self { Calendar { components: Vec::new() @@ -51,15 +53,18 @@ impl Calendar { self.push(component) } + /// Moves all the elements of other into Self, leaving other empty. pub fn append(&mut self, other: &mut Calendar) { self.components.append(&mut other.components); } + /// Appends an element to the back of the `Calendar`. pub fn push<T:Into<CalendarElement>>(&mut self, component:T) -> &mut Self { self.components.push(component.into()); self } + /// Writes `Calendar` into a `Writer` using `std::fmt`. fn fmt_write<W: fmt::Write>(&self, out: &mut W) -> Result<(), fmt::Error> { writeln!(out, "BEGIN:VCALENDAR")?; writeln!(out, "VERSION:2.0")?; diff --git a/src/components.rs b/src/components.rs index 3f8a51e..6cc48df 100644 --- a/src/components.rs +++ b/src/components.rs @@ -17,10 +17,14 @@ pub struct Event { properties: HashMap<String,Property> } pub struct Todo { properties: HashMap<String,Property> } impl Event { + + /// Creates a new Event. pub fn new() -> Self { Event { properties: HashMap::new() } } + /// End of builder pattern. + /// copies over everything pub fn done(&mut self) -> Self { Event { properties: mem::replace(&mut self.properties, HashMap::new()) } } @@ -33,10 +37,14 @@ impl Event { impl Todo { + + /// Creates a new Todo. pub fn new() -> Self { Todo { properties: HashMap::new() } } + /// End of builder pattern. + /// copies over everything pub fn done(&mut self) -> Self { Todo { properties: mem::replace(&mut self.properties, HashMap::new()) } } @@ -49,9 +57,18 @@ impl Todo { /// Implemented by everything that goes into a `Calendar` pub trait Component { + + /// Returns kind of component. + /// + /// + /// Must be ALL CAPS + /// These are used in the `BEGIN` and `END` line of the component. fn component_kind() -> &'static str; + + /// Allows access to the inner properties HashMap. fn properties<'a>(&'a self) -> &'a HashMap<String,Property>; + /// Writes `Component` into a `Writer` using `std::fmt`. fn fmt_write<W: fmt::Write>(&self, out: &mut W) -> Result<(), fmt::Error> { writeln!(out, "BEGIN:{}", Self::component_kind())?; @@ -66,6 +83,7 @@ pub trait Component { Ok(()) } + /// Guess what fn to_string(&self) -> String { let mut out_string = String::new(); self.fmt_write(&mut out_string).unwrap(); @@ -1,6 +1,8 @@ //! A library (far from anything) to generate icalendars -//! This is still just an early idea, there is nothing implemented, -//! I haven't even read the [spec](http://tools.ietf.org/html/rfc5545) yet. +//! This implementation is still far from complete, I haven't even read the entire [spec](http://tools.ietf.org/html/rfc5545) yet. +//! Instead I implemented the parts I needed first. +//! More to come, contributions very welcome. +//! //! //! ## Structure //! * `Calendar`s consist of `Components` @@ -45,6 +47,14 @@ //! //! ``` +#![warn(missing_docs, + missing_copy_implementations, + trivial_casts, trivial_numeric_casts, + unsafe_code, + unstable_features, + unused_import_braces, unused_qualifications)] +//#![warn(missing_debug_implementations)] + extern crate chrono; extern crate uuid; //extern crate vobject; diff --git a/src/properties.rs b/src/properties.rs index 46ba869..216b026 100644 --- a/src/properties.rs +++ b/src/properties.rs @@ -6,11 +6,13 @@ use std::convert::Into; #[derive(Debug)] /// key-value pairs inside of `Property`s pub struct Parameter { - pub key: String, - pub value: String, + key: String, + value: String, } impl Parameter { + + /// Creates a new `Parameter` pub fn new(key: &str, val: &str) -> Self { Parameter { key: key.to_owned(), @@ -31,6 +33,7 @@ pub struct Property { } impl Property { + /// Guess what this does :D pub fn new(key: &str, val: &str) -> Self { Property { @@ -40,23 +43,25 @@ impl Property { } } - /// Clones the key field + /// Clones the key field. pub fn key(&self) -> String { self.key.clone() } + /// Appends a new parameter. pub fn append_parameter<I:Into<Parameter>>(&mut self, into_parameter: I) -> &mut Self { let parameter = into_parameter.into(); self.parameters.insert(parameter.key.to_owned(), parameter); self } + /// Creates and appends a parameter. pub fn add_parameter(&mut self, key: &str, val: &str) -> &mut Self { self.append_parameter(Parameter::new(key, val)); self } - /// End of Builder Pattern + /// End of Builder Pattern. pub fn done(&mut self) -> Self { Property { key: mem::replace(&mut self.key, String::new()), @@ -77,8 +82,14 @@ impl Property { } /// Defines: `Public`, `Private`, `Confidential` +#[derive(Copy,Clone)] pub enum Class { - Public, Private, Confidential + /// Public + Public, + /// Private + Private, + /// Confidential + Confidential } impl Into<Property> for Class { @@ -95,20 +106,36 @@ impl Into<Property> for Class { } } +/// see 8.3.4. [Value Data Types Registry](https://tools.ietf.org/html/rfc5545#section-8.3.4) +#[derive(Copy,Clone)] pub enum ValueType{ + /// Binary Binary, + /// Boolean Boolean, + /// CalAddress CalAddress, + /// Date Date, + /// DateTime DateTime, + /// Duration Duration, + /// Float Float, + /// Integer Integer, + /// Period Period, + /// Recur Recur, + /// Text Text, + /// Time Time, + /// Uri Uri, + /// UtcOffset UtcOffset, } |