pub trait Inspect {
// Required method
fn iattach(
self,
parent: &Node,
name: impl AsRef<str>,
) -> Result<(), AttachError>;
}
Expand description
A trait for types that can be inspected using fuchsia_inspect and that
maintain their inspect state during their lifetime. Notably, this trait is
implemented for most fuchsia_inspect properties and the IOwned
smart
pointers. Generic implementations are also provided for interior mutability
wrappers whose inner type also implement Inspect
, such as RefCell and
various Mutex types. This method should generally be implemented for a
mutable reference (or a regular reference if the type has interior
mutability).
Required Methods§
Sourcefn iattach(
self,
parent: &Node,
name: impl AsRef<str>,
) -> Result<(), AttachError>
fn iattach( self, parent: &Node, name: impl AsRef<str>, ) -> Result<(), AttachError>
Attaches self
to the inspect tree, under parent[name]
. Note that:
- If this method is called on a type with interior mutability, it
will attempt to get exclusive access to the inner data, but will
not wait for a mutex to unlock. If it fails, an
AttachError
is returned. - If this method is called on a fuchsia_inspect Property, it is reinitialized to its default value.
Therefore it is recommended to attach to inspect immediately after initialization, although not within constructors. Whether or not to use inspect should usually be a choice of the caller.
NOTE: Implementors should avoid returning AttachError whenever possible. It is reserved for irrecoverable invariant violations (see above). Invalid data structure invariants are not attachment errors and should instead be ignored and optionally logged.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.