spirv_bindings: remove the IntoFfi/FromFfi stuff

This commit is contained in:
2022-07-25 00:55:43 -07:00
parent 8a16a5ce30
commit 2032e90688
2 changed files with 10 additions and 64 deletions

View File

@@ -1,67 +1,4 @@
use coremem_types::compound::Optional;
use coremem_types::vec::{Vec3, Vec3u};
/// hide the actual spirv backend structures inside a submodule to make their use/boundary clear.
mod ffi {
pub use spirv_backend::entry_points;
}
// conversion traits for types defined cross-lib
pub trait IntoFfi {
type Ffi;
fn into_ffi(self) -> Self::Ffi;
}
pub trait IntoLib {
type Lib;
fn into_lib(self) -> Self::Lib;
}
pub trait Identity { }
impl<T: Identity> IntoFfi for T {
type Ffi = Self;
fn into_ffi(self) -> Self::Ffi {
self
}
}
impl<T: Identity> IntoLib for T {
type Lib = Self;
fn into_lib(self) -> Self::Lib {
self
}
}
impl Identity for f32 {}
impl<'a> Identity for &'a str {}
impl<T0: Identity, T1: Identity> Identity for (T0, T1) {}
impl Identity for Vec3u {}
impl<T: Identity> Identity for Vec3<T> {}
impl<L: IntoFfi> IntoFfi for Option<L>
where L::Ffi: Default
{
type Ffi = Optional<L::Ffi>;
fn into_ffi(self) -> Self::Ffi {
match self {
Some(s) => Optional::some(s.into_ffi()),
None => Optional::none(),
}
}
}
impl<F: Copy + IntoLib> IntoLib for Optional<F> {
type Lib = Option<F::Lib>;
fn into_lib(self) -> Self::Lib {
if self.is_some() {
Some(self.unwrap().into_lib())
} else {
None
}
}
}
// FUNCTION BINDINGS
pub fn entry_points<L: 'static>() -> Option<(&'static str, &'static str)>
{
ffi::entry_points::<L>().into_lib()
spirv_backend::entry_points::<L>().into()
}

View File

@@ -84,4 +84,13 @@ impl<T0: Default, T1: Default> Optional<(T0, T1)> {
}
}
impl<T> Into<Option<T>> for Optional<T> {
fn into(self) -> Option<T> {
if self.present != 0 {
Some(self.unwrap())
} else {
None
}
}
}