hax_types/cli_options/
extension.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/// This module defines a way to extend externally the CLI of hax, via
/// the `Extension` trait. This trait defines one associated type per
/// extension point.
use crate::prelude::*;

use clap::{Parser, Subcommand};

macro_rules! trait_alias {
    ($name:ident = $($base:tt)+) => {
        pub trait $name: $($base)+ { }
        impl<T: $($base)+> $name for T { }
    };
}

trait_alias!(
    ExtensionPoint =
        std::fmt::Debug
        + for<'a> serde::Deserialize<'a>
        + serde::Serialize
        + JsonSchema
        + Clone
);

trait_alias!(SubcommandExtensionPoint = ExtensionPoint + clap::Subcommand);
trait_alias!(ArgsExtensionPoint = ExtensionPoint + clap::Args);

#[derive_group(Serializers)]
#[derive(JsonSchema, Parser, Debug, Clone)]
pub struct EmptyArgsExtension {}

#[derive_group(Serializers)]
#[derive(JsonSchema, Subcommand, Debug, Clone)]
pub enum EmptySubcommandExtension {}

pub trait Extension: 'static {
    type Options: ArgsExtensionPoint;
    type Command: SubcommandExtensionPoint;
    type BackendOptions: ArgsExtensionPoint;
    type FStarOptions: ArgsExtensionPoint;
}

impl Extension for () {
    type Options = EmptyArgsExtension;
    type Command = EmptySubcommandExtension;
    type BackendOptions = EmptyArgsExtension;
    type FStarOptions = EmptyArgsExtension;
}