diff --git a/src/lib.rs b/src/lib.rs index bb48094..aae068c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -92,6 +92,16 @@ impl<'a> ImStr<'a> { fn as_ptr(&self) -> *const c_char { self.bytes.as_ptr() as *const c_char } } +impl<'a> From<&'a str> for ImStr<'a> { + fn from(value: &'a str) -> ImStr<'a> { + let mut bytes: Vec = value.bytes().collect(); + bytes.push(0); + ImStr { + bytes: Cow::Owned(bytes) + } + } +} + impl From for ImStr<'static> { fn from(mut value: String) -> ImStr<'static> { value.push('\0');