pub struct DebugContextProperty { /* private fields */ }
Expand description

Debug context property

This can be used to give a module additional context for debugging panics and crashes by describing key module state by instantiating properties that describe different types of state. For example which level is loaded in a module.

If there are any panics or crashes in the module during the lifetime of this object then this context will be included in those panic / crash reports.

Note that this is intended for debugging purposes also and should only be select important state, not describe tons of state in the module. So recommendation is to use max 10 properties or so and update them when they change, not many times per frame / module call.

Example

In this example we load a level, and there can only be a single level active at the time so we can put the debug context property directly inside the object so it the debug context property is active while the level is active.

struct Level {
    name: String,
    _debug_prop: DebugContextProperty
}

impl Level {
    pub fn new(name: String) -> Self {
        let _debug_prop = DebugContextProperty::new("level", &name)
        Self {
            name,
            _debug_prop
        }
    }
}

Implementations§

source§

impl DebugContextProperty

source

pub fn new(name: &'static str, value: impl Display) -> Self

Creates a new debug context property

The name of the property is global and unique to the module, supposed to be brief and is required to be static. The value of the property can be any string but generally single-line strings are preferred.

Name and value strings may be capped by the host.

source

pub fn push(&mut self, value: impl Display)

Push a new value for an existing debug context property in the same stack.

source

pub fn pop(&mut self)

Pop a value of an existing debug context property stack.

Does nothing if the property stack was already empty.

source

pub fn reset(&mut self, value: impl Display)

Replace the current value of an existing debug context property (equivalent to pop and push).

Trait Implementations§

source§

impl Debug for DebugContextProperty

source§

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

Formats the value using the given formatter. Read more
source§

impl Drop for DebugContextProperty

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.