pub enum Step<Y, D> {
Yielded(Y),
Complete(D),
}Expand description
Result of a computation step, either yielding a value to continue or completing with a final value.
Step is the return type for coroutine computations, similar to how Option represents
optional values and Result represents fallible operations.
§Examples
use sans::Step;
let continuing: Step<i32, String> = Step::Yielded(42);
let completed: Step<i32, String> = Step::Complete("finished".to_string());
// Using combinators
let doubled = continuing.map_yielded(|x| x * 2);
assert_eq!(doubled, Step::Yielded(84));Variants§
Yielded(Y)
Continue computation with an intermediate yield value
Complete(D)
Complete computation with a final value
Implementations§
Source§impl<Y, D> Step<Y, D>
impl<Y, D> Step<Y, D>
Sourcepub const fn is_yielded(&self) -> bool
pub const fn is_yielded(&self) -> bool
Returns true if the step is Yielded.
§Examples
use sans::Step;
let x: Step<i32, &str> = Step::Yielded(42);
assert!(x.is_yielded());
let y: Step<i32, &str> = Step::Complete("complete");
assert!(!y.is_yielded());Sourcepub const fn is_complete(&self) -> bool
pub const fn is_complete(&self) -> bool
Returns true if the step is Complete.
§Examples
use sans::Step;
let x: Step<i32, &str> = Step::Complete("complete");
assert!(x.is_complete());
let y: Step<i32, &str> = Step::Yielded(42);
assert!(!y.is_complete());Sourcepub fn yielded_value(self) -> Option<Y>
pub fn yielded_value(self) -> Option<Y>
Converts from Step<Y, D> to Option<Y>.
Converts self into an Option<Y>, consuming self,
and discarding the complete value, if any.
§Examples
use sans::Step;
let x: Step<i32, &str> = Step::Yielded(42);
assert_eq!(x.yielded_value(), Some(42));
let y: Step<i32, &str> = Step::Complete("complete");
assert_eq!(y.yielded_value(), None);Sourcepub fn complete_value(self) -> Option<D>
pub fn complete_value(self) -> Option<D>
Converts from Step<Y, D> to Option<D>.
Converts self into an Option<D>, consuming self,
and discarding the yield value, if any.
§Examples
use sans::Step;
let x: Step<i32, &str> = Step::Complete("complete");
assert_eq!(x.complete_value(), Some("complete"));
let y: Step<i32, &str> = Step::Yielded(42);
assert_eq!(y.complete_value(), None);Sourcepub fn map_complete<D2, F>(self, f: F) -> Step<Y, D2>where
F: FnOnce(D) -> D2,
pub fn map_complete<D2, F>(self, f: F) -> Step<Y, D2>where
F: FnOnce(D) -> D2,
Maps a Step<Y, D> to Step<Y, D2> by applying a function to the complete value.
§Examples
use sans::Step;
let x: Step<i32, i32> = Step::Complete(5);
assert_eq!(x.map_complete(|v| v * 2), Step::Complete(10));
let y: Step<i32, i32> = Step::Yielded(3);
assert_eq!(y.map_complete(|v| v * 2), Step::Yielded(3));Sourcepub fn map_yielded<Y2, F>(self, f: F) -> Step<Y2, D>where
F: FnOnce(Y) -> Y2,
pub fn map_yielded<Y2, F>(self, f: F) -> Step<Y2, D>where
F: FnOnce(Y) -> Y2,
Maps a Step<Y, D> to Step<Y2, D> by applying a function to the yielded value.
§Examples
use sans::Step;
let x: Step<i32, &str> = Step::Yielded(42);
assert_eq!(x.map_yielded(|v| v * 2), Step::Yielded(84));
let y: Step<i32, &str> = Step::Complete("complete");
assert_eq!(y.map_yielded(|v: i32| v * 2), Step::Complete("complete"));Sourcepub fn map<Y2, D2, FY, FD>(self, fy: FY, fd: FD) -> Step<Y2, D2>
pub fn map<Y2, D2, FY, FD>(self, fy: FY, fd: FD) -> Step<Y2, D2>
Maps a Step<Y, D> to Step<Y2, D2> by applying functions to both values.
§Examples
use sans::Step;
let x: Step<i32, i32> = Step::Yielded(42);
assert_eq!(x.map(|y| y * 2, |d| d + 1), Step::Yielded(84));
let y: Step<i32, i32> = Step::Complete(10);
assert_eq!(y.map(|y| y * 2, |d| d + 1), Step::Complete(11));Sourcepub fn yielded_or(self, default: Y) -> Y
pub fn yielded_or(self, default: Y) -> Y
Returns the yielded value or a default.
§Examples
use sans::Step;
let x: Step<i32, &str> = Step::Yielded(42);
assert_eq!(x.yielded_or(0), 42);
let y: Step<i32, &str> = Step::Complete("complete");
assert_eq!(y.yielded_or(0), 0);Sourcepub fn yielded_or_else<F>(self, f: F) -> Ywhere
F: FnOnce() -> Y,
pub fn yielded_or_else<F>(self, f: F) -> Ywhere
F: FnOnce() -> Y,
Returns the yielded value or computes it from a closure.
§Examples
use sans::Step;
let x: Step<i32, &str> = Step::Yielded(42);
assert_eq!(x.yielded_or_else(|| 0), 42);
let y: Step<i32, &str> = Step::Complete("complete");
assert_eq!(y.yielded_or_else(|| 0), 0);Sourcepub fn complete_or(self, default: D) -> D
pub fn complete_or(self, default: D) -> D
Returns the complete value or a default.
§Examples
use sans::Step;
let x: Step<i32, &str> = Step::Complete("complete");
assert_eq!(x.complete_or("default"), "complete");
let y: Step<i32, &str> = Step::Yielded(42);
assert_eq!(y.complete_or("default"), "default");Sourcepub fn complete_or_else<F>(self, f: F) -> Dwhere
F: FnOnce() -> D,
pub fn complete_or_else<F>(self, f: F) -> Dwhere
F: FnOnce() -> D,
Returns the complete value or computes it from a closure.
§Examples
use sans::Step;
let x: Step<i32, &str> = Step::Complete("complete");
assert_eq!(x.complete_or_else(|| "default"), "complete");
let y: Step<i32, &str> = Step::Yielded(42);
assert_eq!(y.complete_or_else(|| "default"), "default");Sourcepub const fn as_ref(&self) -> Step<&Y, &D>
pub const fn as_ref(&self) -> Step<&Y, &D>
Converts from &Step<Y, D> to Step<&Y, &D>.
§Examples
use sans::Step;
let x: Step<i32, String> = Step::Yielded(42);
assert_eq!(x.as_ref(), Step::Yielded(&42));
let y: Step<i32, String> = Step::Complete("complete".to_string());
assert_eq!(y.as_ref(), Step::Complete(&"complete".to_string()));Sourcepub fn as_mut(&mut self) -> Step<&mut Y, &mut D>
pub fn as_mut(&mut self) -> Step<&mut Y, &mut D>
Converts from &mut Step<Y, D> to Step<&mut Y, &mut D>.
§Examples
use sans::Step;
let mut x: Step<i32, String> = Step::Yielded(42);
if let Step::Yielded(y) = x.as_mut() {
*y = 100;
}
assert_eq!(x, Step::Yielded(100));Sourcepub fn flip(self) -> Step<D, Y>
pub fn flip(self) -> Step<D, Y>
Converts from Step<Y, D> to Step<D, Y> by swapping variants.
§Examples
use sans::Step;
let x: Step<i32, &str> = Step::Yielded(42);
assert_eq!(x.flip(), Step::Complete(42));
let y: Step<i32, &str> = Step::Complete("complete");
assert_eq!(y.flip(), Step::Yielded("complete"));Sourcepub fn contains_yielded<U>(&self, y: &U) -> boolwhere
U: PartialEq<Y>,
pub fn contains_yielded<U>(&self, y: &U) -> boolwhere
U: PartialEq<Y>,
Returns true if the step is a Yielded value containing the given value.
§Examples
use sans::Step;
let x: Step<i32, &str> = Step::Yielded(42);
assert!(x.contains_yielded(&42));
assert!(!x.contains_yielded(&100));
let y: Step<i32, &str> = Step::Complete("complete");
assert!(!y.contains_yielded(&42));Sourcepub fn contains_complete<U>(&self, d: &U) -> boolwhere
U: PartialEq<D>,
pub fn contains_complete<U>(&self, d: &U) -> boolwhere
U: PartialEq<D>,
Returns true if the step is a Complete value containing the given value.
§Examples
use sans::Step;
let x: Step<i32, &str> = Step::Complete("complete");
assert!(x.contains_complete(&"complete"));
assert!(!x.contains_complete(&"other"));
let y: Step<i32, &str> = Step::Yielded(42);
assert!(!y.contains_complete(&"complete"));Sourcepub fn expect_yielded(self, msg: &str) -> Y
pub fn expect_yielded(self, msg: &str) -> Y
Returns the contained Yielded value, consuming the self value.
§Panics
Panics if the value is a Complete with a custom panic message provided by msg.
§Examples
use sans::Step;
let x: Step<i32, &str> = Step::Yielded(42);
assert_eq!(x.expect_yielded("was complete"), 42);use sans::Step;
let x: Step<i32, &str> = Step::Complete("complete");
x.expect_yielded("the world is ending"); // panics with "the world is ending"Sourcepub fn expect_complete(self, msg: &str) -> D
pub fn expect_complete(self, msg: &str) -> D
Returns the contained Complete value, consuming the self value.
§Panics
Panics if the value is a Yielded with a custom panic message provided by msg.
§Examples
use sans::Step;
let x: Step<i32, &str> = Step::Complete("complete");
assert_eq!(x.expect_complete("was yielding"), "complete");use sans::Step;
let x: Step<i32, &str> = Step::Yielded(42);
x.expect_complete("the world is ending"); // panics with "the world is ending"Sourcepub fn unwrap_yielded(self) -> Y
pub fn unwrap_yielded(self) -> Y
Returns the contained Yielded value, consuming the self value.
§Panics
Panics if the value is a Complete.
§Examples
use sans::Step;
let x: Step<i32, &str> = Step::Yielded(42);
assert_eq!(x.unwrap_yielded(), 42);use sans::Step;
let x: Step<i32, &str> = Step::Complete("complete");
x.unwrap_yielded(); // panicsSourcepub fn unwrap_complete(self) -> D
pub fn unwrap_complete(self) -> D
Returns the contained Complete value, consuming the self value.
§Panics
Panics if the value is a Yielded.
§Examples
use sans::Step;
let x: Step<i32, &str> = Step::Complete("complete");
assert_eq!(x.unwrap_complete(), "complete");use sans::Step;
let x: Step<i32, &str> = Step::Yielded(42);
x.unwrap_complete(); // panicsTrait Implementations§
Source§impl<I, O, S> InitSans<I, O> for Step<(O, S), S::Return>where
S: Sans<I, O>,
impl<I, O, S> InitSans<I, O> for Step<(O, S), S::Return>where
S: Sans<I, O>,
type Next = S
Source§fn chain_once<F>(self, f: F) -> Chain<Self, Once<F>>
fn chain_once<F>(self, f: F) -> Chain<Self, Once<F>>
Source§fn chain_repeat<F>(self, f: F) -> Chain<Self, Repeat<F>>
fn chain_repeat<F>(self, f: F) -> Chain<Self, Repeat<F>>
Source§fn map_input<I2, F>(self, f: F) -> MapInput<Self, F>
fn map_input<I2, F>(self, f: F) -> MapInput<Self, F>
Source§fn map_yield<O2, F>(self, f: F) -> MapYield<Self, F, I, O>
fn map_yield<O2, F>(self, f: F) -> MapYield<Self, F, I, O>
Source§impl<Y: Ord, D: Ord> Ord for Step<Y, D>
impl<Y: Ord, D: Ord> Ord for Step<Y, D>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<Y: PartialOrd, D: PartialOrd> PartialOrd for Step<Y, D>
impl<Y: PartialOrd, D: PartialOrd> PartialOrd for Step<Y, D>
impl<Y: Copy, D: Copy> Copy for Step<Y, D>
impl<Y: Eq, D: Eq> Eq for Step<Y, D>
impl<Y, D> StructuralPartialEq for Step<Y, D>
Auto Trait Implementations§
impl<Y, D> Freeze for Step<Y, D>
impl<Y, D> RefUnwindSafe for Step<Y, D>where
Y: RefUnwindSafe,
D: RefUnwindSafe,
impl<Y, D> Send for Step<Y, D>
impl<Y, D> Sync for Step<Y, D>
impl<Y, D> Unpin for Step<Y, D>
impl<Y, D> UnwindSafe for Step<Y, D>where
Y: UnwindSafe,
D: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<I, O, S> TryInitSans<I, O> for Swhere
S: InitSans<I, O>,
impl<I, O, S> TryInitSans<I, O> for Swhere
S: InitSans<I, O>,
Source§fn ok_map<P, E, T, F>(self, f: F) -> OkMap<Self, T::Next, F>
fn ok_map<P, E, T, F>(self, f: F) -> OkMap<Self, T::Next, F>
Ok return values through a function that produces an InitSans.Source§fn ok_and_then<P, Q, E, T, F>(self, f: F) -> OkAndThen<Self, T::Next, F>
fn ok_and_then<P, Q, E, T, F>(self, f: F) -> OkAndThen<Self, T::Next, F>
InitSans with a Result return type.