use crate::types::{GeneratorContext, TypeDesc};
use crate::{none_ty, Net};
pub unsafe trait ToNet: Net + ToNetReturn {
#[doc(hidden)]
const TO_DESC: &'static TypeDesc = &TypeDesc {
marshal_out: Some(Self::gen_marshal),
..*Self::DESC
};
#[doc(hidden)]
fn into_raw(self) -> Self::Raw;
#[doc(hidden)]
fn gen_marshal(ctx: &mut GeneratorContext, arg: &str) -> Box<str>;
}
pub unsafe trait ToNetArg: Sized {
#[doc(hidden)]
type Owned: ToNet;
#[doc(hidden)]
fn to_owned(self) -> Self::Owned;
#[doc(hidden)]
fn to_owned_raw(self) -> <Self::Owned as Net>::Raw {
self.to_owned().into_raw()
}
}
unsafe impl<T: ToNet> ToNetArg for T {
type Owned = Self;
fn to_owned(self) -> Self::Owned {
self
}
}
pub unsafe trait ToNetReturn {
#[doc(hidden)]
const RETURN_DESC: &'static TypeDesc;
#[doc(hidden)]
type RawReturn;
#[doc(hidden)]
fn to_raw_return(self) -> Self::RawReturn;
}
unsafe impl<T: ToNet> ToNetReturn for T {
const RETURN_DESC: &'static TypeDesc = T::TO_DESC;
type RawReturn = <Self as Net>::Raw;
fn to_raw_return(self) -> Self::RawReturn {
let raw = self.into_raw();
unsafe { std::mem::transmute_copy(&raw) }
}
}
unsafe impl ToNetReturn for () {
const RETURN_DESC: &'static TypeDesc = &TypeDesc {
net_ty: none_ty,
base_ty: none_ty,
raw_ty: none_ty,
marshal_in: None,
marshal_out: Some(|_, arg| arg.into()),
};
type RawReturn = ();
fn to_raw_return(self) -> Self::RawReturn {}
}