mirror of https://github.com/chipsenkbeil/distant
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
696 B
Rust
30 lines
696 B
Rust
use std::any::Any;
|
|
|
|
/// Trait used for casting support into the [`Any`] trait object
|
|
pub trait AsAny: Any {
|
|
/// Converts reference to [`Any`]
|
|
fn as_any(&self) -> &dyn Any;
|
|
|
|
/// Converts mutable reference to [`Any`]
|
|
fn as_mut_any(&mut self) -> &mut dyn Any;
|
|
|
|
/// Consumes and produces `Box<dyn Any>`
|
|
fn into_any(self: Box<Self>) -> Box<dyn Any>;
|
|
}
|
|
|
|
/// Blanket implementation that enables any `'static` reference to convert
|
|
/// to the [`Any`] type
|
|
impl<T: 'static> AsAny for T {
|
|
fn as_any(&self) -> &dyn Any {
|
|
self
|
|
}
|
|
|
|
fn as_mut_any(&mut self) -> &mut dyn Any {
|
|
self
|
|
}
|
|
|
|
fn into_any(self: Box<Self>) -> Box<dyn Any> {
|
|
self
|
|
}
|
|
}
|