Trait CStringLike

Source
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 a CString.
  • CStr - Will be borrowed.
  • String - Will be copied and converted to a CString.
  • 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§

Source

fn into_c_str(self) -> Option<Cow<'a, CStr>>

Convert the type to a CStr.

Implementations on Foreign Types§

Source§

impl<'a> CStringLike<'a> for &'a CStr

Source§

fn into_c_str(self) -> Option<Cow<'a, CStr>>

Source§

impl<'a> CStringLike<'a> for &str

Source§

fn into_c_str(self) -> Option<Cow<'a, CStr>>

Source§

impl<'a> CStringLike<'a> for CString

Source§

fn into_c_str(self) -> Option<Cow<'a, CStr>>

Source§

impl<'a> CStringLike<'a> for String

Source§

fn into_c_str(self) -> Option<Cow<'a, CStr>>

Implementors§