Skip to content

Commit

Permalink
start docs for Fiber
Browse files Browse the repository at this point in the history
  • Loading branch information
matsadler committed Sep 2, 2023
1 parent 93e4c4d commit bcdc5c2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ impl RubyGvlState {
/// * [Errors](#errors)
/// * [Extracting values from `Opaque`/`Lazy`](#extracting-values-from-opaquelazy)
/// * [`false`](#false)
/// * [`Fiber`](#fiber)
/// * [`Fixnum`](#fixnum) - small/fast integers
/// * [`Float`](#float)
/// * [`Flonum`](#flonum) - lower precision/fast floats
Expand All @@ -123,6 +124,7 @@ impl RubyGvlState {
/// * [`StaticSymbol`](#staticsymbol) - non GC'd symbols
/// * [`Struct`](#struct)
/// * [`Symbol`](#symbol)
/// * [`Thread`](#thread)
/// * [`true`](#true)
/// * [`typed_data::Obj`](#typed_dataobj) - wrapping Rust data in a Ruby object
pub struct Ruby(PhantomData<*mut ()>);
Expand Down
29 changes: 29 additions & 0 deletions src/fiber.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Types and functions for working with Ruby's Fiber class.

use std::{fmt, mem::size_of, os::raw::c_int, slice};

#[cfg(ruby_lt_3_2)]
Expand Down Expand Up @@ -30,7 +32,18 @@ use crate::{
},
};

/// # `Fiber`
///
/// Functions to create and work with Ruby `Fiber`s.
///
/// See also the [`Fiber`] type.
impl Ruby {
/// Create a Ruby Fiber.
///
/// As `func` is a function pointer, only functions and closures that do
/// not capture any variables are permitted. For more flexibility (at the
/// cost of allocating) see [`fiber_new_from_fn`](Ruby::fiber_new_from_fn).
///
/// # Examples
///
/// ```
Expand Down Expand Up @@ -97,6 +110,11 @@ impl Ruby {
}
}

/// Create a Ruby Fiber.
///
/// See also [`fiber_new`](Ruby::fiber_new), which is more efficient when
/// `func` is a function or closure that does not capture any variables.
///
/// # Examples
///
/// ```
Expand Down Expand Up @@ -195,6 +213,11 @@ impl Ruby {
}
}

/// Wrapper type for a Value known to be an instance of Ruby's Fiber class.
///
/// See the [`ReprValue`] and [`Object`] traits for additional methods
/// available on this type. See [`Ruby`](Ruby#fiber) for methods to create a
/// `Fiber` and [`Ruby::fiber_yield`].
#[derive(Clone, Copy)]
#[repr(transparent)]
pub struct Fiber(RTypedData);
Expand All @@ -218,6 +241,8 @@ impl Fiber {
unsafe { Value::new(rb_fiber_alive_p(self.as_rb_value())).to_bool() }
}

/// Resume the execution of `self`.
///
/// # Examples
///
/// ```
Expand Down Expand Up @@ -342,11 +367,15 @@ impl TryConvert for Fiber {
}
}

/// Options for initialising Fiber-local storage.
pub enum Storage {
/// Inherit the storage from the current Fiber.
Inherit,
/// Initialise a new empty storage when needed.
#[cfg(any(ruby_gte_3_2, docsrs))]
#[cfg_attr(docsrs, doc(cfg(ruby_gte_3_2)))]
Lazy,
/// Use the given Hash as the Fiber's storage.
#[cfg(any(ruby_gte_3_2, docsrs))]
#[cfg_attr(docsrs, doc(cfg(ruby_gte_3_2)))]
Use(RHash),
Expand Down
2 changes: 1 addition & 1 deletion src/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::{

/// # `Thread`
///
/// Functions that can be used to create Ruby `Thread`s.
/// Functions to create and work with Ruby `Thread`s.
///
/// See also the [`Thread`] type.
impl Ruby {
Expand Down

0 comments on commit bcdc5c2

Please sign in to comment.