Skip to content

Commit 2164a7c

Browse files
committed
feat: new fiber abstractions
There are now 2 types of fibers * Immediate - a fiber that starts executing immediately * Deferred - a fiber that is scheduled for execution Both of them come in 2 variants, consider the case of Immediate: * Immediate<F, T> - has a fiber function that returns a T * UnitImmediate<F> - has a fiber function that returns nothing. This is an optimized version of Immediate<F, ()>. Same with Deferred and UnitDeferred. All of these fibers are joinable. Non-joinable fibers are not supported yet.
1 parent eebb7ca commit 2164a7c

File tree

6 files changed

+847
-9
lines changed

6 files changed

+847
-9
lines changed

src/error.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ use rmp::encode::ValueWriteError;
2727

2828
use crate::ffi::tarantool as ffi;
2929

30+
/// A specialized [`Result`] type for the crate
31+
pub type Result<T> = std::result::Result<T, Error>;
32+
3033
/// Represents all error cases for all routines of crate (including Tarantool errors)
3134
#[derive(Debug, Fail)]
3235
pub enum Error {
@@ -171,7 +174,7 @@ pub struct TarantoolError {
171174
impl TarantoolError {
172175
/// Tries to get the information about the last API call error. If error was not set
173176
/// returns `Ok(())`
174-
pub fn maybe_last() -> Result<(), Self> {
177+
pub fn maybe_last() -> std::result::Result<(), Self> {
175178
let error_ptr = unsafe { ffi::box_error_last() };
176179
if error_ptr.is_null() {
177180
return Ok(());

src/ffi/helper.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,19 @@ use std::ffi::CString;
33
pub unsafe fn new_c_str(s: &str) -> CString {
44
return CString::new(s).unwrap();
55
}
6+
7+
#[macro_export]
8+
macro_rules! c_str {
9+
($s:literal) => {
10+
::std::ffi::CStr::from_bytes_with_nul_unchecked(
11+
::std::concat!($s, "\0").as_bytes()
12+
)
13+
};
14+
}
15+
16+
#[macro_export]
17+
macro_rules! c_ptr {
18+
($s:literal) => {
19+
crate::c_str!($s).as_ptr()
20+
};
21+
}

0 commit comments

Comments
 (0)