pub trait ContextualDisplay<Context> {
type Error;
// Required method
fn contextual_format<F>(
&self,
f: &mut F,
context: &Context,
) -> Result<(), Self::Error>
where F: Write;
// Provided methods
fn format<F, TContext>(
&self,
f: &mut F,
context: TContext,
) -> Result<(), Self::Error>
where F: Write,
TContext: Into<Context> { ... }
fn display<'a, 'b, TContext>(
&'a self,
context: TContext,
) -> ContextDisplayable<'a, Self, Context>
where TContext: Into<Context> { ... }
fn to_string<'a, 'b, TContext>(&'a self, context: TContext) -> String
where TContext: Into<Context> { ... }
}Expand description
This trait is used where context is required to correctly display a value.
Typically, this is due to needing to know the current network to display addresses.
Other forms of Context are also possible. See ComponentAddress
or TransactionReceipt in the radix-engine crate for example implementations.
The Context used should typically just be a wrapper type around references, and so
be a small, cheap, ephemeral value on the stack (if it’s not just optimized away entirely).
It is therefore recommended that the Context implement Copy,
to make it very easy to pass around and re-use.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn format<F, TContext>(
&self,
f: &mut F,
context: TContext,
) -> Result<(), Self::Error>
fn format<F, TContext>( &self, f: &mut F, context: TContext, ) -> Result<(), Self::Error>
Formats the value to the given fmt::Write buffer, making use of the provided context.
See also contextual_format, which takes a &Context instead of an Into<Context>.
Alternatively, the display method can be used to create an object that can be used
directly in a format! style macro.
Sourcefn display<'a, 'b, TContext>(
&'a self,
context: TContext,
) -> ContextDisplayable<'a, Self, Context>where
TContext: Into<Context>,
fn display<'a, 'b, TContext>(
&'a self,
context: TContext,
) -> ContextDisplayable<'a, Self, Context>where
TContext: Into<Context>,
Returns an object implementing fmt::Display, which can be used in a format! style macro.
Whilst this is syntactically nicer, beware that the use of format! absorbs any errors during
formatting, replacing them with fmt::Error.
If you’d like to preserve errors, use the format method instead. This may require manually
splitting up your format! style macro. For example:
// Syntactically nice, but the AddressError is swallowed into fmt::Error
write!(f, "ComponentAddress(\"{}\")", address.display(context))?;
// Less nice, but the AddressError is correctly returned
f.write_str("ComponentAddress(\"")?;
address.format(f, context)?;
f.write_str("\")")?;fn to_string<'a, 'b, TContext>(&'a self, context: TContext) -> Stringwhere
TContext: Into<Context>,
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.
Implementations on Foreign Types§
Source§impl<'a, 'b> ContextualDisplay<TransactionReceiptDisplayContext<'a>> for (&'b StateUpdates, &'b SystemStructure)
impl<'a, 'b> ContextualDisplay<TransactionReceiptDisplayContext<'a>> for (&'b StateUpdates, &'b SystemStructure)
type Error = Error
fn contextual_format<F>(
&self,
f: &mut F,
context: &TransactionReceiptDisplayContext<'a>,
) -> Result<(), <(&'b StateUpdates, &'b SystemStructure) as ContextualDisplay<TransactionReceiptDisplayContext<'a>>>::Error>where
F: Write,
Implementors§
Source§impl<'a> ContextualDisplay<ManifestDecompilationDisplayContext<'a>> for ManifestCustomValue
impl<'a> ContextualDisplay<ManifestDecompilationDisplayContext<'a>> for ManifestCustomValue
Source§impl<'a> ContextualDisplay<ManifestDecompilationDisplayContext<'a>> for Value<ManifestCustomValueKind, ManifestCustomValue>
impl<'a> ContextualDisplay<ManifestDecompilationDisplayContext<'a>> for Value<ManifestCustomValueKind, ManifestCustomValue>
Source§impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for Emitter
impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for Emitter
Source§impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for BlueprintId
impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for BlueprintId
Source§impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for ComponentAddress
impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for ComponentAddress
Source§impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for FnIdentifier
impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for FnIdentifier
Source§impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for GlobalAddress
impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for GlobalAddress
Source§impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for InternalAddress
impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for InternalAddress
Source§impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for NodeId
impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for NodeId
Source§impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for NonFungibleGlobalId
impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for NonFungibleGlobalId
Source§impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for PackageAddress
impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for PackageAddress
Source§impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for ResourceAddress
impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for ResourceAddress
Source§impl<'a> ContextualDisplay<ScryptoValueDisplayContext<'a>> for RejectionReason
impl<'a> ContextualDisplay<ScryptoValueDisplayContext<'a>> for RejectionReason
Source§impl<'a> ContextualDisplay<ScryptoValueDisplayContext<'a>> for RuntimeError
impl<'a> ContextualDisplay<ScryptoValueDisplayContext<'a>> for RuntimeError
Source§impl<'a> ContextualDisplay<ScryptoValueDisplayContext<'a>> for PersistableRejectionReason
impl<'a> ContextualDisplay<ScryptoValueDisplayContext<'a>> for PersistableRejectionReason
Source§impl<'a> ContextualDisplay<ScryptoValueDisplayContext<'a>> for PersistableRuntimeError
This is used to render the error message, with a fallback if an invalid schema
is associated with the error.
impl<'a> ContextualDisplay<ScryptoValueDisplayContext<'a>> for PersistableRuntimeError
This is used to render the error message, with a fallback if an invalid schema is associated with the error.
This fallback is necessary due to historic breakages of backwards compatibility
in the RuntimeError type structure.
Specifically, at anemone / bottlenose, there were very minor changes, which affected a tiny minority of errors. If we could find the historic schemas, we could actually render them properly here. Unfortunately, the historic schemas are not easy to find out (it would require backporting the schema generation logic), so instead we just have a fallback for these cases.
This fallback will only be applied on nodes, when returning occasional errors for old transactions that haven’t resynced since Bottlenose.