Better panic messages.
This commit is contained in:
parent
726b030616
commit
a2694114d1
17
src/any.rs
17
src/any.rs
@ -629,7 +629,7 @@ impl Dynamic {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "no_closure")]
|
#[cfg(feature = "no_closure")]
|
||||||
unimplemented!()
|
panic!("'no_closure' feature does not support converting into a shared value");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert the `Dynamic` value into specific type.
|
/// Convert the `Dynamic` value into specific type.
|
||||||
@ -781,7 +781,20 @@ impl Dynamic {
|
|||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn cast<T: Variant + Clone>(self) -> T {
|
pub fn cast<T: Variant + Clone>(self) -> T {
|
||||||
self.try_cast::<T>().unwrap()
|
let self_type_name = if self.is_shared() {
|
||||||
|
// Avoid panics/deadlocks with shared values
|
||||||
|
"<shared>"
|
||||||
|
} else {
|
||||||
|
self.type_name()
|
||||||
|
};
|
||||||
|
|
||||||
|
self.try_cast::<T>().unwrap_or_else(|| {
|
||||||
|
panic!(
|
||||||
|
"value is {} and cannot be cast to {}",
|
||||||
|
self_type_name,
|
||||||
|
type_name::<T>()
|
||||||
|
)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Flatten the `Dynamic` and clone it.
|
/// Flatten the `Dynamic` and clone it.
|
||||||
|
Loading…
Reference in New Issue
Block a user