Add method to scalar (#283)

This commit is contained in:
Brendan Ball 2018-11-29 19:47:19 +02:00 committed by Christian Legnitto
parent 4ecf558066
commit e2212a539a

View file

@ -23,6 +23,13 @@ impl From<String> for ID {
}
}
impl ID {
/// Construct a new ID from anything implementing `Into<String>`
pub fn new<S: Into<String>>(value: S) -> Self {
ID(value.into())
}
}
impl Deref for ID {
type Target = str;
@ -353,6 +360,13 @@ mod tests {
assert_eq!(actual, expected);
}
#[test]
fn test_id_new() {
let actual = ID::new("foo");
let expected = ID(String::from("foo"));
assert_eq!(actual, expected);
}
#[test]
fn test_id_deref() {
let id = ID(String::from("foo"));