Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion stabby-abi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ workspace = true

[features]
default = ["std"]
std = ["alloc-rs"]
std = ["alloc", "alloc-rs"]
alloc = []
alloc-rs = []
experimental-ctypes = ["stabby-macros/experimental-ctypes"]
libc = ["dep:libc"]
Expand Down
2 changes: 2 additions & 0 deletions stabby-abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
extern crate alloc as alloc_rs;

/// ABI-stable smart pointers and allocated data structures, with support for custom allocators.
#[cfg(feature = "alloc")]
pub mod alloc;
/// Extending [Non-Zero Types](core::num) to enable niches for other values than 0.
pub mod num;
Expand Down Expand Up @@ -144,6 +145,7 @@ mod fatptr;
/// Closures, but ABI-stable
pub mod closure;
/// Futures, but ABI-stable
#[cfg(feature = "alloc")]
pub mod future;
mod stable_impls;
/// Support for vtables for multi-trait objects
Expand Down
3 changes: 2 additions & 1 deletion stabby/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ workspace = true

[features]
default = ["std"]
std = ["stabby-abi/std", "alloc-rs"]
std = ["stabby-abi/std", "alloc", "alloc-rs"]
alloc = ["stabby-abi/alloc"]
alloc-rs = ["stabby-abi/alloc-rs"]
experimental-ctypes = ["stabby-abi/experimental-ctypes"]
libloading = ["dep:libloading", "std"]
Expand Down
2 changes: 2 additions & 0 deletions stabby/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub use stabby_abi::{

pub use stabby_abi as abi;

#[cfg(feature = "alloc")]
pub use stabby_abi::alloc::{self, boxed, collections, string, sync, vec};

pub use stabby_abi::{Dyn, DynRef};
Expand All @@ -42,6 +43,7 @@ pub use stabby_abi::tuple;
stabby_unsafe_wakers = "true",
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)"
)]
#[cfg(feature = "alloc")]
pub mod future {
pub use crate::abi::future::*;
use crate::boxed::Box;
Expand Down
7 changes: 7 additions & 0 deletions stabby/src/tests/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#![cfg_attr(stabby_unsafe_wakers = "true", allow(deprecated))]

pub use crate as stabby;
#[cfg(feature = "alloc")]
use stabby::boxed::Box;

#[stabby::stabby(checked)]
Expand Down Expand Up @@ -76,6 +77,7 @@ pub trait MyTrait3<Hi: core::ops::Deref> {
extern "C" fn test2(&mut self);
}

#[cfg(feature = "alloc")]
impl MyTrait3<Box<()>> for u8 {
type A = u8;
type B = u8;
Expand All @@ -88,6 +90,8 @@ impl MyTrait3<Box<()>> for u8 {
extern "C" fn test(&mut self) {}
extern "C" fn test2(&mut self) {}
}

#[cfg(feature = "alloc")]
impl MyTrait3<Box<()>> for u16 {
type A = u8;
type B = u8;
Expand All @@ -101,13 +105,15 @@ impl MyTrait3<Box<()>> for u16 {
extern "C" fn test2(&mut self) {}
}

#[cfg(feature = "alloc")]
#[stabby::stabby(checked)]
pub trait AsyncRead {
extern "C" fn read<'a>(
&'a mut self,
buffer: stabby::slice::SliceMut<'a, u8>,
) -> stabby::future::DynFuture<'a, usize>;
}
#[cfg(feature = "alloc")]
impl AsyncRead for stabby::slice::Slice<'_, u8> {
extern "C" fn read<'a>(
&'a mut self,
Expand All @@ -125,6 +131,7 @@ impl AsyncRead for stabby::slice::Slice<'_, u8> {
}
}

#[cfg(feature = "alloc")]
#[test]
fn dyn_traits() {
let boxed = Box::new(6u8);
Expand Down