use crate::*;
impl Default for PanicData {
#[inline(always)]
fn default() -> Self {
Self {
message: String::new(),
location: None,
}
}
}
impl PanicData {
pub fn from_message<M>(message: M) -> Self
where
M: AsRef<str>,
{
Self {
message: message.as_ref().to_owned(),
location: None,
}
}
pub fn from_join_error(error: tokio::task::JoinError) -> Self {
Self {
message: error.to_string(),
location: None,
}
}
pub fn get_message(&self) -> &String {
&self.message
}
pub fn get_location(&self) -> Option<&String> {
self.location.as_ref()
}
pub fn set_location<L>(&mut self, location: L)
where
L: AsRef<str>,
{
self.location = Some(location.as_ref().to_owned());
}
}
impl Display for PanicData {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Panic: {}", self.get_message())?;
if let Some(location) = self.get_location() {
write!(f, " at {location}")?;
}
Ok(())
}
}
impl StdError for PanicData {}