mod array;
mod enums;
mod fnptr;
mod pattern;
mod primitive;
mod std;
mod structs;
mod wire;
use crate::lang::function::Signature;
use crate::lang::meta::{Docs, Emission, Visibility};
use crate::inventory::{Inventory, TypeId};
pub use array::Array;
pub use enums::{Enum, Variant, VariantKind};
pub use pattern::TypePattern;
pub use primitive::{Primitive, PrimitiveValue};
pub use std::{type_id_ptr, type_id_ptr_mut};
pub use structs::{Field, Struct};
pub use wire::{WireIO, WireOnly};
pub trait TypeProxy {}
pub unsafe trait TypeInfo {
const WIRE_SAFE: bool;
const RAW_SAFE: bool;
const ASYNC_SAFE: bool;
const SERVICE_SAFE: bool;
const SERVICE_CTOR_SAFE: bool;
const OPTION_PTR_SAFE: bool = false;
fn id() -> TypeId;
fn kind() -> TypeKind;
fn ty() -> Type;
fn register(inventory: &mut impl Inventory);
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum TypeKind {
Array(Array),
Primitive(Primitive),
Struct(Struct),
Enum(Enum),
FnPointer(Signature),
ReadPointer(TypeId),
Service,
ReadWritePointer(TypeId),
Opaque,
WireOnly(WireOnly),
TypePattern(TypePattern),
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Type {
pub name: String,
pub visibility: Visibility,
pub docs: Docs,
pub emission: Emission,
pub kind: TypeKind,
}
#[derive(Clone, Copy, Debug, PartialOrd, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Layout {
C,
Transparent,
Packed,
Opaque,
Primitive(Primitive),
}
#[derive(Clone, Copy, Debug, PartialOrd, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Repr {
pub layout: Layout,
pub alignment: Option<usize>,
}
impl Repr {
#[must_use]
pub fn c() -> Self {
Self { layout: Layout::C, alignment: None }
}
#[must_use]
pub fn u32() -> Self {
Self { layout: Layout::Primitive(Primitive::U32), alignment: None }
}
}
#[track_caller]
pub const fn assert_wire_safe<T: TypeInfo>() {
assert!(T::WIRE_SAFE);
}
#[track_caller]
pub const fn assert_raw_safe<T: TypeInfo>() {
assert!(T::RAW_SAFE, "This type cannot be safely passed over FFI boundaries.");
}
#[track_caller]
pub const fn assert_async_safe<T: TypeInfo>() {
assert!(T::ASYNC_SAFE, "This type cannot be used in async functions or methods.");
}
#[track_caller]
pub const fn assert_service_safe<T: TypeInfo>() {
assert!(T::SERVICE_SAFE, "This type cannot be used in service methods.");
}
pub const fn assert_send_sync<T: Send + Sync>() {}
#[track_caller]
pub const fn assert_service_type<T: TypeInfo>() {
assert!(T::SERVICE_SAFE, "This type is not declared as a service type. Use #[ffi(service)] on the struct definition to use it with an #[ffi] impl block.");
}
#[track_caller]
pub const fn assert_service_ctor_safe<T: TypeInfo>() {
assert!(T::SERVICE_CTOR_SAFE, "This method looks like a constructor, but does not return ffi::Result<Self, _>");
}