StructOp Handbook
Contents Examples Commands

Guestlist enum

Console program267 lines of .st219 lines of generated Rust
Program output
Hello, what's your name? (Leave empty and press ENTER to quit)
Welcome to the treehouse, bert
Hello, what's your name? (Leave empty and press ENTER to quit)
Welcome to the treehouse, steve
Lactose-free milk is in the fridge
Do not serve alcohol to steve
Hello, what's your name? (Leave empty and press ENTER to quit)
Do not allow fred in!
Hello, what's your name? (Leave empty and press ENTER to quit)
joebob is not on the visitor list.
Hello, what's your name? (Leave empty and press ENTER to quit)
The final list of visitors:
[
    Visitor {
        name: "bert",
        action: Accept,
        age: 45,
    },
    Visitor {
        name: "steve",
        action: AcceptWithNote {
            note: "Lactose-free milk is in the fridge",
        },
        age: 15,
    },
    Visitor {
        name: "fred",
        action: Refuse,
        age: 30,
    },
    Visitor {
        name: "joebob",
        action: Probation,
        age: 0,
    },
]
On this page

The .st files#

intent.st
structop {
    type_app {
        exec = {
            lang = "Rust"
        }
    }
}

Input, plan and generated Rust#

input.txt · typed input (5 lines)
input.txt · typed input (5 lines)
bert
steve
fred
joebob
structop plan
structop plan
  # program.app will be created
  + program.app (.structop/build/app)
      + ability.enum.VisitorAction
      + ability.struct.Visitor
      + ability.function.greet_visitor
      + ability.switch.Action
      + ability.print.Welcome
      + ability.print.WelcomeNote
      + ability.print.Note
      + ability.if.Young
      + ability.print.NoAlcohol
      + ability.print.Probation
      + ability.print.Refuse
      + ability.function.what_is_your_name
      + ability.read_line.Line
      + ability.trim.Ends
      + ability.lower.Case
      + ability.loop.Bouncer
      + ability.print.Question
      + ability.call.GetName
      + ability.set.Forget
      + ability.for.Find
      + ability.if.Same
      + ability.set.Found
      + ability.if.Match
      + ability.call.Greet
      + ability.if.Empty
      + ability.break.Quit
      + ability.print.NotOnList
      + ability.add.NewFriend
      + ability.print.Final
      + ability.for.Show
      + ability.print.Head
      + ability.if.Noted
      + ability.print.WithNote
      + ability.print.Plain
      + ability.print.Tail
      + ability.print.Close
      + ability.value.visitor_list
      + ability.value.name
      + ability.value.known_visitor
      + ability.value.i

Plan: 1 to add, 0 to change, 0 to destroy.
Generated main.rs

To inspect this generated file, select Rust in intent.st, initialize the project and export its source.

Export locally
structop init
structop apply -source -no-run
Try it
cd rust-guestlist-enum    # a folder holding the .st files above
structop init
structop plan
structop apply < input.txt