Trait defmt::Logger[][src]

pub unsafe trait Logger {
    fn acquire() -> Option<NonNull<dyn Write>>;
unsafe fn release(writer: NonNull<dyn Write>); }
Expand description

Global logger acquire-release mechanism

Safety contract

  • acquire returns a handle that temporarily owns the global logger
  • acquire must return Some only once, until the handle is release-d
  • acquire is allowed to return a handle per thread or interrupt level
  • acquire is a safe function therefore it must be thread-safe and interrupt-safe
  • The value returned by acquire is not Send so it cannot be moved between threads or interrupt handlers

And, not safety related, acquire should never be invoked from user code. The easiest way to ensure this is to implement Logger on a private struct and mark that struct as the #[global_logger].

Required methods

Returns a handle to the global logger

For the requirements of the method see the documentation of the Logger trait

Releases the global logger


writer argument must be a value previously returned by Self::acquire and not, say, NonNull::dangling()