nushell/src/object/types.rs

31 lines
567 B
Rust
Raw Normal View History

2019-05-16 00:58:44 +02:00
use std::any::Any;
use std::fmt::Debug;
2019-05-10 18:59:12 +02:00
pub trait Type: Debug + Send {
2019-05-15 18:12:38 +02:00
fn as_any(&self) -> &dyn Any;
fn equal(&self, other: &dyn Type) -> bool;
fn id(&self) -> u64;
fn copy(&self) -> Box<Type>;
2019-05-15 18:12:38 +02:00
}
2019-05-10 18:59:12 +02:00
#[derive(Debug, Eq, PartialEq)]
2019-05-15 18:12:38 +02:00
pub struct AnyShell;
impl Type for AnyShell {
fn as_any(&self) -> &dyn Any {
self as &dyn Any
}
fn equal(&self, other: &dyn Type) -> bool {
other.as_any().is::<AnyShell>()
}
fn id(&self) -> u64 {
0
}
fn copy(&self) -> Box<Type> {
Box::new(AnyShell)
}
2019-05-15 18:12:38 +02:00
}