From dd80f55c5f5bcdfa52e3a2da9bbe262c64efa9d4 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Tue, 26 Feb 2019 19:43:29 +0100 Subject: [PATCH] =?UTF-8?q?disco:=20Add=20constructors=20for=20Identity,?= =?UTF-8?q?=20and=20fix=20Feature=E2=80=99s.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/disco.rs | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/disco.rs b/src/disco.rs index 0acdcb86..b958cce5 100644 --- a/src/disco.rs +++ b/src/disco.rs @@ -36,9 +36,9 @@ attributes: [ impl Feature { /// Create a new `` with the according `@var`. - pub fn new(var: &str) -> Feature { + pub fn new>(var: S) -> Feature { Feature { - var: String::from(var) + var: var.into(), } } } @@ -59,6 +59,36 @@ pub struct Identity { pub name: Option, } +impl Identity { + /// Create a new ``. + pub fn new(category: C, type_: T, lang: L, name: N) -> Identity + where C: Into, + T: Into, + L: Into, + N: Into, + { + Identity { + category: category.into(), + type_: type_.into(), + lang: Some(lang.into()), + name: Some(name.into()), + } + } + + /// Create a new `` without a name. + pub fn new_anonymous(category: C, type_: T) -> Identity + where C: Into, + T: Into, + { + Identity { + category: category.into(), + type_: type_.into(), + lang: None, + name: None, + } + } +} + impl TryFrom for Identity { type Err = Error;