[][src]Struct glib::char::Char

pub struct Char(pub c_char);

Wrapper for values where C functions expect a plain C char

Consider the following C function prototype from glib:

void g_key_file_set_list_separator (GKeyFile *key_file, gchar separator);

This function plainly expects a byte as the separator argument. However, having this function exposed to Rust as the following would be inconvenient:

This example is not tested
impl KeyFile {
    pub fn set_list_separator(&self, separator: libc:c_char) { }
}

This would be inconvenient because users would have to do the conversion from a Rust char to an libc::c_char by hand, which is just a type alias for i8 on most system.

This Char type is a wrapper over an libc::c_char, so that we can pass it to Glib or C functions. The check for whether a Rust char (a Unicode scalar value) actually fits in a libc::c_char is done in the new function; see its documentation for details.

The inner libc::c_char (which is equivalent to i8 can be extracted with .0, or by calling my_char.to_glib().

Methods

impl Char[src]

pub fn new(c: char) -> Option<Char>[src]

Creates a Some(Char) if the given char is representable as an libc::c_char

Example

This example is not tested
extern "C" fn have_a_byte(b: libc::c_char);

let a = Char::new('a').unwrap();
assert!(a.0 == 65);
have_a_byte(a.to_glib());

let not_representable = Char::new('☔');
assert!(not_representable.is_none());

Trait Implementations

impl Clone for Char[src]

impl Copy for Char[src]

impl Debug for Char[src]

impl Eq for Char[src]

impl From<Char> for char[src]

impl PartialEq<Char> for Char[src]

impl StructuralEq for Char[src]

impl StructuralPartialEq for Char[src]

Auto Trait Implementations

impl RefUnwindSafe for Char

impl Send for Char

impl Sync for Char

impl Unpin for Char

impl UnwindSafe for Char

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.