diff --git a/src/lib.rs b/src/lib.rs index 6fb0b2a..5f850e9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -349,6 +349,12 @@ impl LocatedSpan { } } +impl From for LocatedSpan { + fn from(i: T) -> Self { + Self::new_extra(i, X::default()) + } +} + impl PartialEq for LocatedSpan { fn eq(&self, other: &Self) -> bool { self.line == other.line && self.offset == other.offset && self.fragment == other.fragment diff --git a/src/tests.rs b/src/tests.rs index 249d072..17451f6 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -51,6 +51,13 @@ fn it_should_call_new_for_u8_successfully() { assert_eq!(BytesSpan::new(input), output); } +#[test] +fn it_should_convert_from_u8_successfully() { + let input = &b"foobar"[..]; + assert_eq!(BytesSpan::new(input), input.into()); + assert_eq!(BytesSpanEx::new_extra(input, "extra"), input.into()); +} + #[test] fn it_should_call_new_for_str_successfully() { let input = &"foobar"[..]; @@ -64,6 +71,13 @@ fn it_should_call_new_for_str_successfully() { assert_eq!(StrSpan::new(input), output); } +#[test] +fn it_should_convert_from_str_successfully() { + let input = &"foobar"[..]; + assert_eq!(StrSpan::new(input), input.into()); + assert_eq!(StrSpanEx::new_extra(input, "extra"), input.into()); +} + #[test] fn it_should_ignore_extra_for_equality() { let input = &"foobar"[..];