diff --git a/src/lib.rs b/src/lib.rs index 960af26..f12250d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -323,14 +323,22 @@ impl ByteSubstring where T: AsRef<[u8]> { /// A convenience type that can be used in a constant or static. pub type ByteSubstringConst = ByteSubstring<&'static [u8]>; -/// Searches a string for the first occurence of the substring. -pub struct Substring<'a>(ByteSubstring<&'a [u8]>); +/// Searches a string for the first occurrence of the substring. +pub struct Substring(ByteSubstring); -impl<'a> Substring<'a> { +impl<'a> Substring<&'a [u8]> { pub /* const */ fn new(needle: &'a str) -> Self { Substring(ByteSubstring::new(needle.as_bytes())) } +} + +impl Substring> { + pub fn new_owned(needle: String) -> Self { + Substring(ByteSubstring::new(needle.into_bytes())) + } +} +impl Substring where T: AsRef<[u8]> { #[cfg(feature = "pattern")] fn needle_len(&self) -> usize { self.0.needle_len() @@ -344,7 +352,7 @@ impl<'a> Substring<'a> { } /// A convenience type that can be used in a constant or static. -pub type SubstringConst = Substring<'static>; +pub type SubstringConst = Substring<&'static str>; #[cfg(all(test, feature = "benchmarks"))] mod bench {