pub struct ReportAttachmentMut<'a, Attachment: ?Sized + 'static = Dynamic> { /* private fields */ }Expand description
A mutable reference to a ReportAttachment, enabling mutation of the
underlying attachment.
§Examples
let mut attachment = ReportAttachment::new_sendsync(41);
{
let mut attachment_mut = attachment.as_mut();
*attachment_mut.inner_mut() += 1;
}
println!("The answer: {}", attachment.format_inner());Implementations§
Source§impl<'a, A: Sized> ReportAttachmentMut<'a, A>
impl<'a, A: Sized> ReportAttachmentMut<'a, A>
Sourcepub fn inner(&self) -> &A
pub fn inner(&self) -> &A
Returns a reference to the attachment data.
§Examples
let mut attachment = ReportAttachment::new_sendsync(41i32);
let attachment_mut = attachment.as_mut();
let data = attachment_mut.inner();
println!("The answer: {}", *data + 1); // => 42Sourcepub fn inner_mut(&mut self) -> &mut A
pub fn inner_mut(&mut self) -> &mut A
Returns a mutable reference to the attachment data.
§Examples
let mut attachment = ReportAttachment::new_sendsync(41i32);
{
let mut attachment_mut = attachment.as_mut();
let data = attachment_mut.inner_mut();
*data += 1;
}
assert_eq!(attachment.format_inner().to_string(), "42");Sourcepub fn into_inner_mut(self) -> &'a mut A
pub fn into_inner_mut(self) -> &'a mut A
Obtain the mutable reference to the inner attachment data.
This method provides direct access to the attachment’s data when the
concrete type A is known at compile time. The attachment type must
be Sized to use this method.
§Panics
This method will panic if the actual type of the attachment doesn’t
match the type A. For a safe alternative that returns Option,
use downcast_inner instead.
§Examples
use rootcause::{
prelude::*,
report_attachment::{ReportAttachment, ReportAttachmentMut},
};
let mut attachment: ReportAttachment<i32> = ReportAttachment::new(40i32);
{
let attachment_mut: ReportAttachmentMut<'_, i32> = attachment.as_mut();
let number: &mut i32 = attachment_mut.into_inner_mut();
*number += 2;
}
assert_eq!(attachment.as_ref().inner(), &42i32);Source§impl<'a, A: ?Sized> ReportAttachmentMut<'a, A>
impl<'a, A: ?Sized> ReportAttachmentMut<'a, A>
Sourcepub fn into_dynamic(self) -> ReportAttachmentMut<'a, Dynamic>
pub fn into_dynamic(self) -> ReportAttachmentMut<'a, Dynamic>
Changes the attachment type of the ReportAttachmentMut to
Dynamic.
Calling this method is equivalent to calling attachment.into(),
however this method has been restricted to only change the
attachment to Dynamic.
This method can be useful to help with type inference or to improve code readability, as it more clearly communicates intent.
This method does not actually modify the attachment in any way. It only
has the effect of “forgetting” that the attachment actually has the
type A.
To get back the attachment with a concrete A you can use the method
ReportAttachmentMut::downcast_attachment.
Sourcepub fn as_ref(&self) -> ReportAttachmentRef<'_, A>
pub fn as_ref(&self) -> ReportAttachmentRef<'_, A>
Returns an immutable reference to the attachment.
Sourcepub fn into_ref(self) -> ReportAttachmentRef<'a, A>
pub fn into_ref(self) -> ReportAttachmentRef<'a, A>
Consumes the ReportAttachmentMut and returns a
ReportAttachmentRef with same lifetime.
Sourcepub fn as_mut(&mut self) -> ReportAttachmentMut<'_, A>
pub fn as_mut(&mut self) -> ReportAttachmentMut<'_, A>
Reborrows the ReportAttachmentMut to return a new
ReportAttachmentMut with a shorter lifetime.
Sourcepub fn inner_type_id(&self) -> TypeId
pub fn inner_type_id(&self) -> TypeId
Returns the TypeId of the inner attachment.
§Examples
use std::any::TypeId;
use rootcause::{
markers::Dynamic,
prelude::*,
report_attachment::{ReportAttachment, ReportAttachmentMut},
};
let attachment: ReportAttachment<&str> = ReportAttachment::new("text data");
let mut attachment: ReportAttachment<Dynamic> = attachment.into_dynamic();
let attachment_mut: ReportAttachmentMut<'_, Dynamic> = attachment.as_mut();
assert_eq!(attachment_mut.inner_type_id(), TypeId::of::<&str>());Sourcepub fn inner_type_name(&self) -> &'static str
pub fn inner_type_name(&self) -> &'static str
Returns the core::any::type_name of the inner attachment.
§Examples
use rootcause::{
markers::Dynamic,
prelude::*,
report_attachment::{ReportAttachment, ReportAttachmentMut},
};
let attachment: ReportAttachment<&str> = ReportAttachment::new("text data");
let mut attachment: ReportAttachment<Dynamic> = attachment.into_dynamic();
let attachment_mut: ReportAttachmentMut<'_, Dynamic> = attachment.as_mut();
assert_eq!(
attachment_mut.inner_type_name(),
core::any::type_name::<&str>()
);Sourcepub fn inner_handler_type_id(&self) -> TypeId
pub fn inner_handler_type_id(&self) -> TypeId
Returns the TypeId of the handler used when creating this
attachment.
Each attachment is associated with a specific handler (like
handlers::Display or handlers::Debug) that determines how it
should be formatted when included in a report. This method allows
you to inspect which handler is being used.
Sourcepub fn format_inner(&self) -> impl Display + Debug
pub fn format_inner(&self) -> impl Display + Debug
Formats the inner attachment data with formatting hooks applied.
This method formats the attachment using both its handler and any global
formatting hooks that have been registered. The hooks allow for
custom formatting behaviors such as filtering, transforming, or
decorating the output. The returned object implements both
Display and Debug traits.
For direct formatting without hooks, use format_inner_unhooked
instead.
Sourcepub fn format_inner_unhooked(&self) -> impl Display + Debug
pub fn format_inner_unhooked(&self) -> impl Display + Debug
Formats the inner attachment data without applying any formatting hooks.
This method provides direct access to the attachment’s formatting
capabilities as defined by its handler, bypassing any global
formatting hooks that might modify the output. The returned object
implements both Display and Debug traits for flexible
formatting options.
For formatted output that includes formatting hooks, use
format_inner instead.
Sourcepub fn preferred_formatting_style(
&self,
report_formatting_function: FormattingFunction,
) -> AttachmentFormattingStyle
pub fn preferred_formatting_style( &self, report_formatting_function: FormattingFunction, ) -> AttachmentFormattingStyle
Returns the preferred formatting style for this attachment with formatting hooks applied.
This method determines how the attachment should be formatted when included in a report, taking into account both the attachment’s handler preferences and any global formatting hooks that might modify the behavior.
§Arguments
Sourcepub fn preferred_formatting_style_unhooked(
&self,
report_formatting_function: FormattingFunction,
) -> AttachmentFormattingStyle
pub fn preferred_formatting_style_unhooked( &self, report_formatting_function: FormattingFunction, ) -> AttachmentFormattingStyle
Returns the preferred formatting style for this attachment without formatting hooks.
This method determines how the attachment should be formatted based
solely on its handler’s preferences, bypassing any global formatting
hooks that might modify the behavior. For formatting that includes
hooks, use preferred_formatting_style instead.
§Arguments
Sourcepub fn preformat(&self) -> ReportAttachment<PreformattedAttachment, SendSync>
pub fn preformat(&self) -> ReportAttachment<PreformattedAttachment, SendSync>
Creates a new attachment, with the inner attachment data preformatted.
This can be useful, as the preformatted attachment is a newly allocated
object and additionally is Send+Sync.
See PreformattedAttachment for more information.
Source§impl<'a> ReportAttachmentMut<'a, Dynamic>
impl<'a> ReportAttachmentMut<'a, Dynamic>
Sourcepub fn downcast_attachment<A>(self) -> Result<ReportAttachmentMut<'a, A>, Self>where
A: Sized + 'static,
pub fn downcast_attachment<A>(self) -> Result<ReportAttachmentMut<'a, A>, Self>where
A: Sized + 'static,
Attempts to downcast the attachment reference to a different type A.
This method performs a safe type cast, returning Ok if the
attachment actually contains data of type A, or Err with the
original reference if the types don’t match.
This method is most useful when going from a Dynamic to a concrete
A.
§Examples
use rootcause::{
markers::Dynamic,
prelude::*,
report_attachment::{ReportAttachment, ReportAttachmentMut},
};
let mut attachment: ReportAttachment<Dynamic> = ReportAttachment::new(41i32).into_dynamic();
let attachment_mut: ReportAttachmentMut<'_, Dynamic> = attachment.as_mut();
// Try to downcast to an incorrect type
let wrong_ref: Result<ReportAttachmentMut<'_, String>, _> =
attachment_mut.downcast_attachment();
assert!(wrong_ref.is_err());
let attachment_mut = wrong_ref.unwrap_err();
// Try to downcast to the correct type
let typed_ref: Result<ReportAttachmentMut<'_, i32>, _> = attachment_mut.downcast_attachment();
assert!(typed_ref.is_ok());Sourcepub unsafe fn downcast_attachment_unchecked<A>(
self,
) -> ReportAttachmentMut<'a, A>where
A: Sized + 'static,
pub unsafe fn downcast_attachment_unchecked<A>(
self,
) -> ReportAttachmentMut<'a, A>where
A: Sized + 'static,
Performs an unchecked downcast of the attachment reference to type A.
This method bypasses type checking and performs the cast without
verifying that the attachment actually contains data of type A. It
is the caller’s responsibility to ensure the cast is valid.
§Safety
The caller must ensure:
- The inner attachment is actually of type
A. This can be verified by callinginner_type_id()first.
§Examples
use rootcause::{
markers::Dynamic,
prelude::*,
report_attachment::{ReportAttachment, ReportAttachmentMut},
};
let attachment: ReportAttachment<&str> = ReportAttachment::new("text data");
let mut attachment: ReportAttachment<Dynamic> = attachment.into_dynamic();
let attachment_mut: ReportAttachmentMut<'_, Dynamic> = attachment.as_mut();
// SAFETY: We know the attachment contains &str data
let typed_mut: ReportAttachmentMut<'_, &str> =
unsafe { attachment_mut.downcast_attachment_unchecked() };Sourcepub fn downcast_inner<A>(&self) -> Option<&A>where
A: Sized + 'static,
pub fn downcast_inner<A>(&self) -> Option<&A>where
A: Sized + 'static,
Attempts to downcast the inner attachment data to an immutable reference of type
A.
See ReportAttachmentRef::downcast_inner for more info.
Sourcepub unsafe fn downcast_inner_unchecked<A>(&self) -> &Awhere
A: Sized + 'static,
pub unsafe fn downcast_inner_unchecked<A>(&self) -> &Awhere
A: Sized + 'static,
Performs an unchecked downcast of the inner attachment data to a
reference of type A.
See ReportAttachmentRef::downcast_inner_unchecked for more info.
§Safety
The caller must ensure:
- The inner attachment is actually of type
A. This can be verified by callinginner_type_id()first.
Sourcepub fn downcast_inner_mut<A>(&mut self) -> Option<&mut A>where
A: Sized + 'static,
pub fn downcast_inner_mut<A>(&mut self) -> Option<&mut A>where
A: Sized + 'static,
Attempts to downcast the inner attachment data to a reference of type
A.
This method performs a safe type cast, returning Some with a
reference to the data if the attachment actually contains data of
type A, or None if the types don’t match. Unlike
downcast_attachment, this method returns a direct reference to
the data rather than a ReportAttachmentRef.
§Examples
let mut attachment: ReportAttachment<Dynamic> =
ReportAttachment::new_sendsync(42).into_dynamic();
let mut attachment_mut: ReportAttachmentMut<'_, Dynamic> = attachment.as_mut();
// Try to downcast to the correct type
let data: Option<&mut i32> = attachment_mut.downcast_inner_mut();
assert_eq!(data, Some(&mut 42));
// Try to downcast to an incorrect type
let wrong_data: Option<&mut String> = attachment_mut.downcast_inner_mut();
assert!(wrong_data.is_none());Sourcepub unsafe fn downcast_inner_mut_unchecked<A>(&mut self) -> &mut Awhere
A: Sized + 'static,
pub unsafe fn downcast_inner_mut_unchecked<A>(&mut self) -> &mut Awhere
A: Sized + 'static,
Performs an unchecked downcast of the inner attachment data to a
mutable reference of type A.
§Safety
The caller must ensure:
- The inner attachment is actually of type
A. This can be verified by callinginner_type_id()first.
§Examples
let mut attachment: ReportAttachment<Dynamic> = ReportAttachment::new(41i32).into_dynamic();
let mut attachment_mut: ReportAttachmentMut<'_, Dynamic> = attachment.as_mut();
// SAFETY: We know the attachment contains i32 data
let data: &mut i32 = unsafe { attachment_mut.downcast_inner_mut_unchecked() };
*data += 1;
assert_eq!(*data, 42);