1use crate::{DataType, Op, Script, TaggedOp};
2use std::borrow::Cow;
3
4pub trait Ops {
5 fn ops(&self) -> Cow<[TaggedOp]>;
6}
7
8pub trait InputScript: Ops {
9 fn types(variant_name: Option<&str>) -> Vec<DataType>;
10 fn names(variant_name: Option<&str>) -> &'static [&'static str];
11}
12
13pub struct TaggedScript<I: InputScript> {
14 tagged_ops: Vec<TaggedOp>,
15 input_params: std::marker::PhantomData<I>,
16}
17
18impl<I: InputScript> TaggedScript<I> {
19 pub fn new(tagged_ops: Vec<TaggedOp>) -> Self {
20 TaggedScript {
21 tagged_ops,
22 input_params: std::marker::PhantomData,
23 }
24 }
25
26 pub fn script_ops(&self) -> impl Iterator<Item = &Op> {
27 self.tagged_ops.iter().map(|op| &op.op)
28 }
29}
30
31impl<I: InputScript> Ops for TaggedScript<I> {
32 fn ops(&self) -> Cow<[TaggedOp]> {
33 self.tagged_ops.as_slice().into()
34 }
35}
36
37impl<I: InputScript> Clone for TaggedScript<I> {
38 fn clone(&self) -> Self {
39 TaggedScript::new(self.tagged_ops.clone())
40 }
41}
42
43impl<I: InputScript> From<TaggedScript<I>> for Script {
44 fn from(script: TaggedScript<I>) -> Self {
45 Script::new(script.tagged_ops)
46 }
47}