Skip to content

Commit

Permalink
fastn_continuation::Result::Init with Default
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Dec 8, 2024
1 parent 203c7b3 commit 5732434
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
32 changes: 30 additions & 2 deletions v0.5/fastn-continuation/src/result.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
pub enum Result<C: fastn_continuation::Continuation + ?Sized> {
Done(C::Output),
Init(Box<C>),
Stuck(Box<C>, C::Needed),
Done(C::Output),
}

impl<C: fastn_continuation::Continuation> Result<C> {
impl<C: fastn_continuation::Continuation> Result<C>
where
C::Found: Default,
{
pub fn consume<P>(mut self, p: P) -> C::Output
where
P: fastn_continuation::Provider<Needed = C::Needed, Found = C::Found>,
{
loop {
match self {
fastn_continuation::Result::Init(ic) => {
self = ic.continue_after(Default::default());
}
fastn_continuation::Result::Stuck(ic, needed) => {
self = ic.continue_after(p.provide(needed));
}
Expand All @@ -26,6 +33,9 @@ impl<C: fastn_continuation::Continuation> Result<C> {
{
loop {
match self {
fastn_continuation::Result::Init(ic) => {
self = ic.continue_after(Default::default());
}
fastn_continuation::Result::Stuck(ic, needed) => {
self = ic.continue_after(f(needed));
}
Expand All @@ -42,6 +52,9 @@ impl<C: fastn_continuation::Continuation> Result<C> {
{
loop {
match self {
fastn_continuation::Result::Init(ic) => {
self = ic.continue_after(Default::default());
}
fastn_continuation::Result::Stuck(mut ic, needed) => {
let o = p.provide(&mut ic, needed);
self = ic.continue_after(o);
Expand All @@ -59,6 +72,9 @@ impl<C: fastn_continuation::Continuation> Result<C> {
{
loop {
match self {
fastn_continuation::Result::Init(ic) => {
self = ic.continue_after(Default::default());
}
fastn_continuation::Result::Stuck(mut ic, needed) => {
let o = f(&mut ic, needed);
self = ic.continue_after(o);
Expand All @@ -77,6 +93,9 @@ impl<C: fastn_continuation::Continuation> Result<C> {
{
loop {
match self {
fastn_continuation::Result::Init(ic) => {
self = ic.continue_after(Default::default());
}
fastn_continuation::Result::Stuck(ic, needed) => {
self = ic.continue_after(p.provide(needed).await);
}
Expand All @@ -93,6 +112,9 @@ impl<C: fastn_continuation::Continuation> Result<C> {
{
loop {
match self {
fastn_continuation::Result::Init(ic) => {
self = ic.continue_after(Default::default());
}
fastn_continuation::Result::Stuck(ic, needed) => {
self = ic.continue_after(f(needed).await);
}
Expand All @@ -110,6 +132,9 @@ impl<C: fastn_continuation::Continuation> Result<C> {
{
loop {
match self {
fastn_continuation::Result::Init(ic) => {
self = ic.continue_after(Default::default());
}
fastn_continuation::Result::Stuck(mut ic, needed) => {
let o = p.provide(&mut ic, needed).await;
self = ic.continue_after(o);
Expand All @@ -130,6 +155,9 @@ impl<C: fastn_continuation::Continuation> Result<C> {
{
loop {
match self {
fastn_continuation::Result::Init(ic) => {
self = ic.continue_after(Default::default());
}
Result::Stuck(mut ic, needed) => {
let o = f(&mut ic, needed).await;
self = ic.continue_after(o);
Expand Down
4 changes: 2 additions & 2 deletions v0.5/fastn-package/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#![warn(clippy::used_underscore_binding)]
#![allow(dead_code)]

pub mod reader;

extern crate self as fastn_package;

pub mod reader;

pub type UR<U, R> = fastn_continuation::UR<U, R, fastn_section::Error>;

#[derive(Debug)]
Expand Down
24 changes: 11 additions & 13 deletions v0.5/fastn-package/src/reader.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
#[derive(Debug)]
pub struct State {
name: String,
systems: Vec<fastn_package::UR<fastn_package::System, ()>>,
dependencies: Vec<fastn_package::UR<fastn_package::Dependency, ()>>,
systems: Vec<fastn_package::UR<String, fastn_package::System>>,
dependencies: Vec<fastn_package::UR<String, fastn_package::Dependency>>,
pub auto_imports: Vec<fastn_package::AutoImport>,
apps: Vec<fastn_package::UR<fastn_package::App, ()>>,
apps: Vec<fastn_package::UR<String, fastn_package::App>>,
}

impl fastn_package::Package {
// s: FASTN.ftd source code
pub fn reader() -> fastn_continuation::Result<State> {
// TODO: lets make as much progress as we can
fastn_continuation::Result::Stuck(
Box::new(State {
name: "".to_string(),
systems: vec![],
dependencies: vec![],
auto_imports: vec![],
apps: vec![],
}),
Default::default(),
)
fastn_continuation::Result::Init(Box::new(State {
name: "".to_string(),
systems: vec![],
dependencies: vec![],
auto_imports: vec![],
apps: vec![],
}))
}
}

Expand Down

0 comments on commit 5732434

Please sign in to comment.