Struct Char
pub struct Char(pub i8);Expand description
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:
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.into_glib().
§Examples
use glib::Char;
use std::convert::TryFrom;
Char::from(b'a');
Char::try_from('a').unwrap();
assert!(Char::try_from('☔').is_err());extern "C" fn have_a_byte(b: libc::c_char);
have_a_byte(Char::from(b'a').into_glib());Tuple Fields§
§0: i8Trait Implementations§
impl Copy for Char
impl Eq for Char
impl StructuralPartialEq for Char
Auto Trait Implementations§
impl Freeze for Char
impl RefUnwindSafe for Char
impl Send for Char
impl Sync for Char
impl Unpin for Char
impl UnwindSafe for Char
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more