mod frame_impl;
mod kind;
use alloc::boxed::Box;
#[cfg(nightly)]
use core::any::{self, Demand, Provider};
use core::{any::TypeId, fmt, panic::Location};
use self::frame_impl::FrameImpl;
pub use self::kind::{AttachmentKind, FrameKind};
pub struct Frame {
frame: Box<dyn FrameImpl>,
location: &'static Location<'static>,
sources: Box<[Frame]>,
}
impl Frame {
#[must_use]
#[deprecated(
since = "0.2.4",
note = "`location()` has been replaced with an additional attachment containing \
`Location<'static>` for each `Context`, similar to how `Backtrace` and \
`SpanTrace` are handled. Note: This means that once `location()` is removed you \
won't be able to get location of attachments anymore."
)]
pub const fn location(&self) -> &'static Location<'static> {
self.location
}
#[allow(missing_docs)]
#[must_use]
#[deprecated(since = "0.2.0", note = "use `sources()` instead")]
pub const fn source(&self) -> Option<&Self> {
self.sources().first()
}
#[must_use]
pub const fn sources(&self) -> &[Self] {
&self.sources
}
#[allow(missing_docs)]
#[must_use]
#[deprecated(since = "0.2.0", note = "use `sources_mut()` instead")]
pub fn source_mut(&mut self) -> Option<&mut Self> {
self.sources_mut().first_mut()
}
#[must_use]
pub fn sources_mut(&mut self) -> &mut [Self] {
&mut self.sources
}
#[must_use]
pub fn kind(&self) -> FrameKind<'_> {
self.frame.kind()
}
#[must_use]
#[cfg(nightly)]
pub fn request_ref<T>(&self) -> Option<&T>
where
T: ?Sized + 'static,
{
any::request_ref(self)
}
#[must_use]
#[cfg(nightly)]
pub fn request_value<T>(&self) -> Option<T>
where
T: 'static,
{
any::request_value(self)
}
#[must_use]
pub fn is<T: Send + Sync + 'static>(&self) -> bool {
self.frame.as_any().is::<T>()
}
#[must_use]
pub fn downcast_ref<T: Send + Sync + 'static>(&self) -> Option<&T> {
self.frame.as_any().downcast_ref()
}
#[must_use]
pub fn downcast_mut<T: Send + Sync + 'static>(&mut self) -> Option<&mut T> {
self.frame.as_any_mut().downcast_mut()
}
#[must_use]
pub fn type_id(&self) -> TypeId {
self.frame.as_any().type_id()
}
}
#[cfg(nightly)]
impl Provider for Frame {
fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
self.frame.provide(demand);
}
}
impl fmt::Debug for Frame {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut debug = fmt.debug_struct("Frame");
match self.kind() {
FrameKind::Context(context) => {
debug.field("context", &context);
debug.finish()
}
FrameKind::Attachment(AttachmentKind::Printable(attachment)) => {
debug.field("attachment", &attachment);
debug.finish()
}
FrameKind::Attachment(AttachmentKind::Opaque(_)) => debug.finish_non_exhaustive(),
}
}
}