[][src]Enum cala::Loop

pub enum Loop<T> {
    Exit,
    Continue,
    Back,
    Append(fn(_: &mut T) -> Loop<T>),
    Replace(fn(_: &mut T) -> Loop<T>),
    ReplaceWithBack(fn(_: &mut T) -> Loop<T>, fn(_: &mut T) -> Loop<T>),
}

Cala program control flow loop.

Variants

Exit

Exit the program.

Usage

// Set the home loop to `do_nothing()`.
cala::init!(do_nothing, ());
  
// This program just quits right away.
pub fn do_nothing(_: &mut ()) -> cala::Loop<()> {
    // Exit.
    cala::Exit
}
Continue

Keep the program running.

Usage

// Set the home loop to `infinite_loop()`.
cala::init!(infinite_loop, ());
  
// This program runs until the user interupts it.
pub fn infinite_loop(_: &mut ()) -> cala::Loop<()> {
    // Run this function again.
    cala::Continue
}
Back

Go back one activity.

Usage

// Set the home loop to `home()`.
cala::init!(home, ());
  
// This program creates 2 new activities, which both go back right away.
pub fn home(_: &mut ()) -> cala::Loop<()> {
    // `activity_a` is first, because it will be on the top of the activity stack.
    cala::ReplaceWithBack(activity_a, activity_b)
}

pub fn activity_a(_: &mut ()) -> cala::Loop<()> {
    println!("First");
    // Go to activity_b
    cala::Back
}

pub fn activity_b(_: &mut ()) -> cala::Loop<()> {
    println!("Last");
    // Quit
    cala::Back
}
Append(fn(_: &mut T) -> Loop<T>)

Add new activities to the activity stack (new activity loop).

Usage

// Set the home loop to `home()`.
cala::init!(home, ());
  
// Infinite loop.
pub fn home(_: &mut ()) -> cala::Loop<()> {
    // `activity_a` is first, because it will be on the top of the activity stack.
    cala::Append(activity_a)
}

pub fn activity_a(_: &mut ()) -> cala::Loop<()> {
    // Go to activity `home()`
    cala::Back
}
Replace(fn(_: &mut T) -> Loop<T>)

Add a new activity to the activity stack (new activity loop), throwing away the one on top (the current activity).

Usage

// Set the home loop to `home()`.
cala::init!(home, ());
  
// This program creates 1 new activity, which quits right away.
pub fn home(_: &mut ()) -> cala::Loop<()> {
    // Replace our `home()` activity with `activity_a()`.
    cala::Replace(activity_a)
}

pub fn activity_a(_: &mut ()) -> cala::Loop<()> {
    // Quit
    cala::Exit
}
ReplaceWithBack(fn(_: &mut T) -> Loop<T>, fn(_: &mut T) -> Loop<T>)

Add 2 new activities to the activity stack (new activity loop), throwing away the one on top (the current activity). First parameter is the activity that the user will enter, and the second is the one they will enter when they go back.

Usage

// Set the home loop to `home()`.
cala::init!(home, ());
  
// This program creates 2 new activities, which both go back right away.
pub fn home(_: &mut ()) -> cala::Loop<()> {
    // `activity_a` is first, because it will be on the top of the activity stack.
    cala::ReplaceWithBack(activity_a, activity_b)
}

pub fn activity_a(_: &mut ()) -> cala::Loop<()> {
    println!("First");
    // Go to activity_b
    cala::Back
}

pub fn activity_b(_: &mut ()) -> cala::Loop<()> {
    println!("Last");
    // Quit
    cala::Back
}

Auto Trait Implementations

impl<T> Sync for Loop<T>

impl<T> Send for Loop<T>

impl<T> Unpin for Loop<T>

impl<T> RefUnwindSafe for Loop<T>

impl<T> UnwindSafe for Loop<T>

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]