use std::{mem,marker::PhantomData};
use crate::{
StableAbi,
erased_types::{GetImplFlags, VirtualWrapperTrait},
std_types::{RBoxError, RCow, RStr,StaticStr,utypeid::new_utypeid},
version::VersionStrings,
return_value_equality::ReturnValueEquality,
};
use super::TypeInfo;
#[allow(unused_imports)]
use crate::type_level::bools::{False, True};
pub trait ImplType: Sized + 'static + Send + Sync {
type Interface: InterfaceType;
const INFO: &'static TypeInfo;
}
pub trait InterfaceType: Sized + 'static + Send + Sync + GetImplFlags + StableAbi {
type Clone;
type Default;
type Display;
type Debug;
type Serialize;
type Eq;
type PartialEq;
type Ord;
type PartialOrd;
type Hash;
type Deserialize;
#[doc(hidden)]
type define_this_in_the_impl_InterfaceType_macro;
}
pub trait SerializeImplType: ImplType {
fn serialize_impl<'a>(&'a self) -> Result<RCow<'a, RStr<'a>>, RBoxError>;
}
pub trait DeserializeInterfaceType: InterfaceType<Deserialize = True> {
type Deserialized: VirtualWrapperTrait<Interface = Self>;
fn deserialize_impl(s: RStr<'_>) -> Result<Self::Deserialized, RBoxError>;
}
pub struct InterfaceFor<T,Interface>(
PhantomData<fn()->(T,Interface)>
);
impl<T,Interface> ImplType for InterfaceFor<T,Interface>
where
Interface:InterfaceType,
T:'static,
{
type Interface=Interface;
const INFO:&'static TypeInfo=&TypeInfo{
size:mem::size_of::<T>(),
alignment:mem::align_of::<T>(),
uid:ReturnValueEquality{
function:new_utypeid::<T>
},
name:StaticStr::new("<erased>"),
file:StaticStr::new("<unavailable>"),
package:StaticStr::new("<unavailable>"),
package_version:VersionStrings{
major:StaticStr::new("99"),
minor:StaticStr::new("99"),
patch:StaticStr::new("99"),
},
_private_field:(),
};
}
crate::impl_InterfaceType!{
impl crate::erased_types::InterfaceType for () {
}
}