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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
use super::*; #[derive(Debug, Clone)] pub struct ArgumentSpec { pub modifiers: Modifiers, pub ty: Type, pub name: String, pub annotations: Vec<AnnotationSpec>, } impl ArgumentSpec { pub fn new<I>(modifiers: Modifiers, ty: I, name: &str) -> ArgumentSpec where I: Into<Type> { ArgumentSpec { modifiers: modifiers, ty: ty.into(), name: name.to_owned(), annotations: Vec::new(), } } pub fn push_annotation(&mut self, annotation: &AnnotationSpec) { self.annotations.push(annotation.clone()); } } impl<'a, A> From<&'a A> for ArgumentSpec where A: Into<ArgumentSpec> + Clone { fn from(value: &'a A) -> ArgumentSpec { value.clone().into() } } impl From<ArgumentSpec> for Variable { fn from(value: ArgumentSpec) -> Variable { Variable::Literal(value.name) } } impl From<ArgumentSpec> for Statement { fn from(value: ArgumentSpec) -> Statement { let mut s = Statement::new(); for a in &value.annotations { s.push(Variable::Statement(a.into())); s.push(" "); } if !value.modifiers.is_empty() { s.push(value.modifiers); s.push(" "); } s.push(value.ty); s.push(" "); s.push(value.name); s } }