valkyrie_docgen/items/definition/
parameters.rs

1use self::Parameter::*;
2use super::*;
3
4#[derive(Clone, Debug)]
5pub enum Parameter {
6    Array(Vec<Parameter>),
7    // true: mut
8    // false:
9    // none: none
10    Zelf(Option<bool>),
11    PositionOnly,
12    KeyValueOnly,
13}
14
15impl Parameter {
16    pub fn into_vec(self) -> Vec<Html> {
17        match self {
18            Array(vec) => vec.into_iter().map(|e| e.into_vec()).flatten().collect(),
19            Zelf(None) => vec![],
20            Zelf(Some(true)) => vec![html! {<span class="keyword">{"mut self"}</span>}],
21            Zelf(Some(false)) => vec![html! {<span class="keyword">{"self"}</span>}],
22            PositionOnly => vec![Tooltip::html("/", "All the previous arguments cannot be written as key-value pairs!")],
23            KeyValueOnly => vec![Tooltip::html("*", "All the following arguments must be written as key-value pairs!")],
24        }
25    }
26    pub fn length(&self) -> usize {
27        match self {
28            Array(v) => v.iter().map(|e| e.length()).sum(),
29            Zelf(None) => 0,
30            Zelf(Some(true)) => 8,
31            Zelf(Some(false)) => 4,
32            PositionOnly => 1,
33            KeyValueOnly => 1,
34        }
35    }
36}