stabby/
lib.rs

1//
2// Copyright (c) 2023 ZettaScale Technology
3//
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7// which is available at https://www.apache.org/licenses/LICENSE-2.0.
8//
9// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10//
11// Contributors:
12//   Pierre Avital, <pierre.avital@me.com>
13//
14
15#![deny(
16    missing_docs,
17    clippy::missing_panics_doc,
18    clippy::missing_const_for_fn,
19    clippy::missing_safety_doc,
20    clippy::missing_errors_doc
21)]
22#![cfg_attr(not(feature = "std"), no_std)]
23#![cfg_attr(not(doctest), doc = include_str!("../README.md"))]
24
25extern crate core;
26
27pub use stabby_abi::{
28    assert_unchecked, dynptr, export, import, stabby, unreachable_unchecked, vtmacro as vtable,
29};
30
31pub use stabby_abi as abi;
32
33pub use stabby_abi::alloc::{self, boxed, collections, string, sync, vec};
34
35pub use stabby_abi::{Dyn, DynRef};
36
37/// ABI-stable tuples
38pub use stabby_abi::tuple;
39
40/// Futures can be ABI-stable if you wish hard enough
41#[cfg_attr(
42    stabby_unsafe_wakers = "true",
43    deprecated = "Warning! you are using the `stabby/stabby_unsafe_wakers` feature. This could cause UB if you poll a future received from another shared library with mismatching ABI! (this API isn't actually deprecated)"
44)]
45pub mod future {
46    pub use crate::abi::future::*;
47    use crate::boxed::Box;
48    /// A type alias for `dynptr!(Box<dyn Future<Output = Output> + Send + Sync + 'a>)`
49    pub type DynFuture<'a, Output> =
50        crate::dynptr!(Box<dyn Future<Output = Output> + Send + Sync + 'a>);
51    /// A type alias for `dynptr!(Box<dyn Future<Output = Output> + Send + 'a>)`
52    pub type DynFutureUnsync<'a, Output> =
53        crate::dynptr!(Box<dyn Future<Output = Output> + Send + 'a>);
54    /// A type alias for `dynptr!(Box<dyn Future<Output = Output> + 'a>)`
55    pub type DynFutureUnsend<'a, Output> = crate::dynptr!(Box<dyn Future<Output = Output> + 'a>);
56}
57
58/// The collection of traits that make `dynptr!(Box<dyn Fn...>)` possible
59pub use crate::abi::closure;
60pub use crate::abi::{option, result, slice, str};
61
62pub use crate::abi::{vtable::Any, AccessAs, IStable, IntoSuperTrait};
63
64#[cfg(all(feature = "libloading", any(unix, windows, doc)))]
65/// Integration with [`libloading`](::libloading), allowing symbol loads to be validated thanks to either reflection or canaries.
66///
67/// Requires the `libloading` feature to be enabled.
68pub mod libloading;
69
70/// ABI-stable representations of durations and instants.
71pub mod time;
72
73/// Like [`std::format`], but returning an ABI-stable [`String`](crate::string::String)
74#[macro_export]
75macro_rules! format {
76    ($($t: tt)*) => {{
77        use ::core::fmt::Write;
78        let mut s = $crate::string::String::default();
79        ::core::write!(s, $($t)*).map(move |_| s)
80    }};
81}
82
83#[cfg(doc)]
84#[doc = include_str!("../TUTORIAL.md")]
85pub mod _tutorial_ {}
86// #[cfg(test)]
87mod tests {
88    mod enums;
89    mod layouts;
90    mod traits;
91}