sim_lib_control/
prompt.rs1use sim_kernel::{
2 Cx, Ref, Result, Symbol,
3 control::{ControlPrompt as KernelControlPrompt, default_control_result_shape, prompt},
4};
5
6#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
8pub struct ControlTag {
9 symbol: Symbol,
10}
11
12impl ControlTag {
13 pub fn new(symbol: Symbol) -> Self {
15 Self { symbol }
16 }
17
18 pub fn symbol(&self) -> &Symbol {
20 &self.symbol
21 }
22
23 pub fn into_symbol(self) -> Symbol {
25 self.symbol
26 }
27}
28
29pub trait ControlPrompt {
31 fn tag(&self) -> ControlTag;
33
34 fn input(&self) -> Ref {
36 Ref::Symbol(self.tag().into_symbol())
37 }
38
39 fn result_shape(&self) -> Ref {
41 default_control_result_shape()
42 }
43}
44
45pub fn raise_prompt(cx: &mut Cx, prompt_record: &dyn ControlPrompt) -> Result<Ref> {
47 let kernel_prompt = KernelControlPrompt::new(
48 Ref::Symbol(prompt_record.tag().into_symbol()),
49 prompt_record.input(),
50 prompt_record.result_shape(),
51 );
52 let input = kernel_prompt.input.clone();
53 prompt(cx, kernel_prompt, |_cx| Ok(input))
54}