pub trait CStringLike<'a> {
// Required method
fn into_c_str(self) -> Option<Cow<'a, CStr>>;
}
Expand description
A trait for types that can be converted to a CStr
.
This is used to allow for a few different types:
&str
- Will be copied and converted to aCString
.CStr
- Will be borrowed.String
- Will be copied and converted to aCString
.CString
- Will be owned.
If the string is empty, the Option::None
will be returned.
§Examples
use scuffle_ffmpeg::dict::Dictionary;
let mut dict = Dictionary::new();
// "key" is a &CStr, so it will be borrowed.
dict.set(c"key", c"value").expect("Failed to set key");
// "key" is a &str, so it will be copied and converted to a CString.
assert_eq!(dict.get("key"), Some(c"value"));
// "nonexistent_key" is a &str, so it will be copied and converted to a CString.
assert_eq!(dict.set("nonexistent_key".to_owned(), "value"), Ok(()));
// "nonexistent_key" is a CString, so it will be borrowed.
assert_eq!(dict.get(c"nonexistent_key".to_owned()), Some(c"value"));
Required Methods§
Sourcefn into_c_str(self) -> Option<Cow<'a, CStr>>
fn into_c_str(self) -> Option<Cow<'a, CStr>>
Convert the type to a CStr
.