Struct glib::LogField

source ·
pub struct LogField<'a>(/* private fields */);
Expand description

Structure representing a single field in a structured log entry.

See g_log_structured for details. Log fields may contain UTF-8 strings, binary with embedded nul bytes, or arbitrary pointers.

Implementations§

source§

impl<'a> LogField<'a>

source

pub fn new(key: &'a GStr, value: &[u8]) -> Self

Creates a field from a borrowed key and value.

source

pub fn new_user_data(key: &'a GStr, data: usize) -> Self

Creates a field with an empty value and data as a user data key. Fields created with this function are ignored by the default log writer. These fields are used to pass custom data into a writer function set with log_set_writer_func, where it can be retreived using Self::user_data.

The passed usize can be used by the log writer as a key into a static data structure. Thread locals are preferred since the log writer function will run in the same thread that invoked log_structured_array.

source

pub fn key(&self) -> &str

Retreives the field key.

source

pub fn value_bytes(&self) -> Option<&[u8]>

Retrieves a byte array of the field value. Returns None if the field was created with Self::new_user_data.

source

pub fn value_str(&self) -> Option<&str>

Retrieves a string of the field value, or None if the string is not valid UTF-8. Also returns None if the field was created with Self::new_user_data.

source

pub fn user_data(&self) -> Option<usize>

Retrieves the the user data value from a field created with Self::new_user_data. Returns None if the field was created with Self::new.

Trait Implementations§

source§

impl<'a> Debug for LogField<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for LogField<'a>

§

impl<'a> !Send for LogField<'a>

§

impl<'a> !Sync for LogField<'a>

§

impl<'a> Unpin for LogField<'a>

§

impl<'a> UnwindSafe for LogField<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.