pub mod abi;
pub mod bridge;
pub mod string;
pub mod trampoline;
pub mod types;
#[doc(hidden)]
pub use zerocopy;
pub mod prelude {
pub use crate::abi::OutParam;
pub use crate::bridge::{FromMojo, IntoMojo, MojoMut, MojoRef, MojoSlice, MojoSliceMut};
pub use crate::mojo_type;
pub use crate::string::MojoStr;
pub use crate::trampoline::catch_mojo_call;
#[cfg(feature = "max")]
pub use crate::types::max;
pub use crate::types::primitives::*;
}
#[macro_export]
macro_rules! mojo_type {
(
$(#[$meta:meta])*
$vis:vis struct $name:ident {
$($field_vis:vis $field:ident : $ty:ty),* $(,)?
}
) => {
$(#[$meta])*
#[repr(C)]
#[derive(
Debug, Clone, Copy, PartialEq,
$crate::zerocopy::IntoBytes,
$crate::zerocopy::FromBytes,
$crate::zerocopy::Immutable,
$crate::zerocopy::KnownLayout,
)]
$vis struct $name {
$($field_vis $field : $ty),*
}
};
}
#[cfg(test)]
mod tests {
use super::prelude::*;
mojo_type! {
pub struct TestVec2 {
pub x: f64,
pub y: f64,
}
}
#[test]
fn mojo_type_is_repr_c() {
assert_eq!(std::mem::size_of::<TestVec2>(), 16);
}
#[test]
fn mojo_type_has_into_mojo() {
let v = TestVec2 { x: 1.0, y: 2.0 };
assert_ne!(v.as_raw(), 0);
}
#[test]
fn mojo_type_has_from_mojo() {
let mut v = TestVec2 { x: 0.0, y: 0.0 };
assert_ne!(v.as_raw_mut(), 0);
}
#[test]
fn mojo_type_is_copy_and_eq() {
let a = TestVec2 { x: 1.0, y: 2.0 };
let b = a;
assert_eq!(a, b);
}
}