foch_annotation/
schema.rs1use crate::value::ValueType;
5use serde::Serialize;
6
7#[derive(Clone, Copy, Debug, Serialize)]
8pub struct ParamSchema {
9 pub name: &'static str,
10 pub value_type: ValueType,
11 pub required: bool,
12 pub description: &'static str,
13 pub example: &'static str,
14}
15
16#[derive(Clone, Copy, Debug, Serialize)]
18pub struct PositionalSchema {
19 pub description: &'static str,
20 pub example: &'static str,
21}
22
23#[derive(Clone, Copy, Debug, Serialize)]
25pub struct TargetRule {
26 pub key: &'static str,
28 pub required_yes: &'static [&'static str],
30}
31
32#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize)]
33#[serde(tag = "kind", rename_all = "snake_case")]
34pub enum AnnotationKind {
35 Primary,
37 Modifier { of: &'static str },
40}
41
42#[derive(Clone, Copy, Debug, Serialize)]
43pub struct AnnotationSchema {
44 pub name: &'static str,
45 pub kind: AnnotationKind,
46 pub description: &'static str,
47 pub params: &'static [ParamSchema],
48 pub positional: Option<PositionalSchema>,
49 pub target: Option<TargetRule>,
50}
51
52impl AnnotationSchema {
53 pub fn param(&self, name: &str) -> Option<&'static ParamSchema> {
54 self.params.iter().find(|param| param.name == name)
55 }
56}
57
58#[derive(Clone, Copy, Debug)]
60pub struct Registry {
61 pub schemas: &'static [AnnotationSchema],
62}
63
64impl Registry {
65 pub fn get(&self, name: &str) -> Option<&'static AnnotationSchema> {
66 self.schemas.iter().find(|schema| schema.name == name)
67 }
68}