From 62d88aa939f159134e73edec2d52c52ce275e219 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 12 Feb 2017 15:23:24 +0100 Subject: Add builder type --- src/task.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/task.rs') diff --git a/src/task.rs b/src/task.rs index b4b9387..8c9c47f 100644 --- a/src/task.rs +++ b/src/task.rs @@ -37,7 +37,8 @@ use uda::{UDA, UDAName, UDAValue}; /// /// It is deserializeable and serializeable via serde_json, so importing and exporting taskwarrior /// tasks is simply serializing and deserializing objects of this type. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Builder)] +#[builder(setter_prefix = "with")] pub struct Task { id: Option, @@ -856,4 +857,19 @@ mod test { assert!(back.contains("1234")); } + #[test] + fn test_builder_simple() { + use task::builder::TaskBuilder; + + let t = TaskBuilder::default() + .with_status(TaskStatus::Pending) + .with_description("test".into_string()) + .with_entry(mkdate("20150619T165438Z")) + .build(); + + assert_eq!(t.status(), TaskStatus::Pending); + assert_eq!(t.description(), "test".into_string()); + assert_eq!(t.entry(), mkdate("20150619T165438Z")); + } + } -- cgit v1.2.3