ensnare-org / ensnare-v1

A library for generating digital audio.
https://ensnare.me
Other
2 stars 1 forks source link

An Acts trait #2

Closed sowbug closed 9 months ago

sowbug commented 9 months ago

The idea is a replacement for the old show(ui) -> (Response, SomeCustomAction) pattern, which sucked. New one is just to implement Displays, but also have a field that contains the action that should be dealt with after calling ui(). The trait would look something like this:

trait Acts {
  type Action;

  // Returns the pending action, if any, and resets it to None.
  fn take_action(&mut self) -> Option<Action>;
}

// callers
let response = entity.ui(ui);
if let Some(action) = entity.take_action() {
  // deal with it
}