godot_binary_serialization/types/
variant.rsuse std::{fmt::Debug, hash::Hash};
pub trait GodotVariant: Debug + Send + Sync {
fn byte_length(&self) -> usize;
fn as_any(&self) -> &dyn std::any::Any;
fn variant_eq(&self, other: &dyn GodotVariant) -> bool;
fn bytes(&self) -> Vec<u8>;
}
impl PartialEq for dyn GodotVariant {
fn eq(&self, other: &Self) -> bool {
self.variant_eq(other)
}
}
impl Eq for dyn GodotVariant {}
impl Hash for Box<dyn GodotVariant> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.bytes().hash(state)
}
}
pub trait AsVariant {
fn as_var<T>(&self) -> Option<&T> where T: GodotVariant + 'static;
}
impl AsVariant for dyn GodotVariant + '_ {
fn as_var<T>(&self) -> Option<&T> where T: GodotVariant + Send + Sync + 'static {
self.as_any().downcast_ref::<T>()
}
}