1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//! Stable ABI building blocks for Rust dynamic module systems.
//!
//! `xabi` provides a small C-compatible ABI surface for hosts and dynamically
//! loaded modules. The high-level path is:
//!
//! - define an ABI trait with [`xabi`],
//! - aggregate exported implementations with [`module`],
//! - load the dynamic module with [`load`] or [`Module::load`],
//! - use the generated `XabiV1HandleTrait*` handle on the host side.
//!
//! # Define a trait ABI
//!
//! ```
//! pub const TRAIT_ID: &str = "xabi.example.Demo";
//! pub const ABI_VERSION: u32 = 1;
//!
//! #[xabi::data]
//! #[derive(Clone, Copy)]
//! pub struct BuildInput {
//! pub value: u64,
//! }
//!
//! #[xabi::xabi(id = TRAIT_ID, version = ABI_VERSION)]
//! pub trait Demo {
//! fn name(&self) -> String;
//! async fn build(&self, input: BuildInput) -> xabi::Result<Vec<u8>>;
//! async fn load(&self, details: &[u8]) -> xabi::Result<()>;
//! }
//! ```
//!
//! # Export an implementation
//!
//! ```no_run
//! # pub const TRAIT_ID: &str = "xabi.example.Demo";
//! # pub const ABI_VERSION: u32 = 1;
//! # #[xabi::data]
//! # #[derive(Clone, Copy)]
//! # pub struct BuildInput { pub value: u64 }
//! # #[xabi::xabi(id = TRAIT_ID, version = ABI_VERSION)]
//! # pub trait Demo {
//! # fn name(&self) -> String;
//! # async fn build(&self, input: BuildInput) -> xabi::Result<Vec<u8>>;
//! # async fn load(&self, details: &[u8]) -> xabi::Result<()>;
//! # }
//! #[derive(Default)]
//! struct DemoImpl;
//!
//! #[xabi::module]
//! mod exports {
//! use super::*;
//!
//! #[xabi::xabi(name = "demo", version = 1)]
//! impl Demo for DemoImpl {
//! fn name(&self) -> String {
//! "demo".to_string()
//! }
//!
//! async fn build(&self, input: BuildInput) -> xabi::Result<Vec<u8>> {
//! Ok(input.value.to_le_bytes().to_vec())
//! }
//!
//! async fn load(&self, _details: &[u8]) -> xabi::Result<()> {
//! Ok(())
//! }
//! }
//! }
//! # fn main() {}
//! ```
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
/// Mark a Rust item as participating in xabi ABI generation.
///
/// On traits this macro defines an ABI contract. Inside a [`module`] it marks
/// an implementation export. Users may import this macro with `use xabi::xabi;`
/// and write `#[xabi(...)]`.
pub use xabi;
/// Aggregate implementation exports from an inline Rust module.
///
/// The macro collects `#[xabi]` implementation items and emits the
/// `xabi_manifest` symbol for the dynamic module.
pub use module;
/// Mark a Rust struct as a stable xabi data type.
///
/// The macro generates an exact-version wire type and implements [`XabiType`].
/// Changing its fields requires a new version for every xabi contract that uses
/// the type. Data structs may use lifetime parameters to carry generated
/// borrowed trait handles as call inputs; the generated wire type remains
/// lifetime-free.
pub use data;
/// Mark a single-pointer Rust struct as an opaque xabi handle.
///
/// The macro generates a versioned wire type, validates that the pointer is not
/// null, and implements [`XabiType`].
///
/// ```
/// #[repr(C)]
/// pub struct Native;
///
/// #[xabi::opaque]
/// #[derive(Clone, Copy)]
/// pub struct NativeHandle {
/// raw: *mut Native,
/// }
///
/// let mut native = Native;
/// let handle = unsafe { NativeHandle::from_raw(&mut native) }.unwrap();
/// let wire = xabi::XabiType::into_wire(handle);
/// wire.validate().unwrap();
/// ```
pub use opaque;