Skip to content

Commit

Permalink
schedule doc example type clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny-g authored and filmor committed Feb 13, 2024
1 parent d8c394a commit 9b86803
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
14 changes: 7 additions & 7 deletions rustler/src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn consume_timeslice(env: Env, percent: i32) -> bool {
#[macro_export]
macro_rules! reschedule {
($flags:expr, $($arg:expr),*) => (
rustler::schedule::Schedule::from(($flags, $($arg,)*))
rustler::Schedule::from(($flags, $($arg,)*))
)
}

Expand All @@ -40,16 +40,16 @@ macro_rules! reschedule {
/// ## Example:
/// ```rust,ignore
/// #[nif]
/// fn factorial(input: u32, result: Option<u32>) -> Schedule<factorial, u32, u32, u32> {
/// fn factorial(input: u8, result: Option<u32>) -> Schedule<factorial, u32, u8, Option<u32>> {
/// let result = result.unwrap_or(1);
/// if input == 0 {
/// Schedule::Return(result)
/// } else {
/// // alternatively `Schedule::Continue2(std::marker::PhantomData, SchedulerFlags::Normal, input - 1, result * input)`
/// // alternatively `Schedule::continue2(SchedulerFlags::Normal, input - 1, result * input)`
/// // alternatively `Schedule::from((SchedulerFlags::Normal, input - 1, result * input))`
/// // alternatively `(SchedulerFlags::Normal, input - 1, result * input).into()`
/// reschedule!(SchedulerFlags::Normal, input - 1, result * input)
/// // alternatively `Schedule::Continue2(std::marker::PhantomData, SchedulerFlags::Normal, input - 1, Some(result * input as u32))`
/// // or `Schedule::continue2(SchedulerFlags::Normal, input - 1, Some(result * input as u32))`
/// // or `Schedule::from((SchedulerFlags::Normal, input - 1, Some(result * input as u32)))`
/// // or `(SchedulerFlags::Normal, input - 1, Some(result * input as u32)).into()`
/// reschedule!(SchedulerFlags::Normal, input - 1, Some(result * input as u32))
/// }
/// }
/// ```
Expand Down
11 changes: 9 additions & 2 deletions rustler_tests/native/rustler_test/src/test_schedule.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
use rustler::{reschedule, Schedule, SchedulerFlags};

#[rustler::nif]
fn scheduled_fac<'a>(input: u32, result: Option<u32>) -> Schedule<scheduled_fac, u32, u32, u32> {
fn scheduled_fac<'a>(
input: u8,
result: Option<u32>,
) -> Schedule<scheduled_fac, u32, u8, Option<u32>> {
let result = result.unwrap_or(1);
if input == 0 {
Schedule::Return(result)
} else {
reschedule!(SchedulerFlags::Normal, input - 1, result * input)
reschedule!(
SchedulerFlags::Normal,
input - 1,
Some(result * input as u32)
)
}
}

0 comments on commit 9b86803

Please sign in to comment.