23 lines
688 B
Rust
23 lines
688 B
Rust
use crate::handling::Script;
|
|
use alloc::boxed::Box;
|
|
|
|
pub trait WithVolatile {
|
|
fn has_volatile(&self, script_name: &str) -> bool;
|
|
fn add_volatile(&self, script: Box<dyn Script>) -> &dyn Script;
|
|
fn add_volatile_by_name(&self, script_name: &str) -> &dyn Script;
|
|
fn remove_volatile(&self, script: &dyn Script);
|
|
fn get_volatile_script(&self, script_name: &str) -> Option<&dyn Script>;
|
|
}
|
|
|
|
pub fn get_volatile_as<'a, T>(v: &'a dyn WithVolatile, script_name: &str) -> Option<&'a T>
|
|
where
|
|
T: Script + 'static,
|
|
{
|
|
let s = v.get_volatile_script(script_name);
|
|
if let Some(s) = s {
|
|
Some(s.as_any().downcast_ref::<T>().unwrap())
|
|
} else {
|
|
None
|
|
}
|
|
}
|