Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added abi stable equivalents of closure traits #95

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
43 changes: 43 additions & 0 deletions abi_stable/src/closures.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
pub use rfn::*;

mod rfn {
use crate::StableAbi;

#[crate::sabi_trait]
pub trait RFn<'a, In, Out> {
fn call(&self, input: In) -> Out;
}
impl<'a, In: StableAbi, Out: StableAbi, F: Fn(In) -> Out> RFn<'a, In, Out> for F {
fn call(&self, input: In) -> Out {
(self)(input)
}
}
}

mod rfnmut {
use crate::StableAbi;

#[crate::sabi_trait]
pub trait RFnMut<'a, In, Out> {
fn call_mut(&mut self, input: In) -> Out;
}
impl<'a, In: StableAbi, Out: StableAbi, F: FnMut(In) -> Out> RFnMut<'a, In, Out> for F {
fn call_mut(&mut self, input: In) -> Out {
(self)(input)
}
}
}

mod rfnonce {
use crate::StableAbi;

#[crate::sabi_trait]
pub trait RFnOnce<'a, In, Out> {
fn call_once(self, input: In) -> Out;
}
impl<'a, In: StableAbi, Out: StableAbi, F: FnOnce(In) -> Out> RFnOnce<'a, In, Out> for F {
fn call_once(self, input: In) -> Out {
(self)(input)
}
}
}
1 change: 1 addition & 0 deletions abi_stable/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ pub mod erased_types;
pub mod external_types;
#[macro_use]
pub mod library;
pub mod closures;
pub mod inline_storage;
pub mod marker_type;
mod multikey_map;
Expand Down