rstgen/csharp/
argument.rs1use super::modifier::Modifier;
4use cons::Cons;
5use csharp::Csharp;
6use into_tokens::IntoTokens;
7use tokens::Tokens;
8
9#[derive(Debug, Clone)]
11pub struct Argument<'el> {
12 pub modifiers: Vec<Modifier>,
14 attributes: Tokens<'el, Csharp<'el>>,
16 ty: Csharp<'el>,
18 name: Cons<'el>,
20}
21
22impl<'el> Argument<'el> {
23 pub fn new<T, N>(ty: T, name: N) -> Argument<'el>
25 where
26 T: Into<Csharp<'el>>,
27 N: Into<Cons<'el>>,
28 {
29 Argument {
30 attributes: Tokens::new(),
31 modifiers: vec![],
32 ty: ty.into(),
33 name: name.into(),
34 }
35 }
36
37 pub fn attribute<T>(&mut self, attribute: T)
39 where
40 T: IntoTokens<'el, Csharp<'el>>,
41 {
42 self.attributes.push(attribute.into_tokens());
43 }
44
45 pub fn var(&self) -> Cons<'el> {
47 self.name.clone()
48 }
49
50 pub fn ty(&self) -> Csharp<'el> {
52 self.ty.clone()
53 }
54}
55
56into_tokens_impl_from!(Argument<'el>, Csharp<'el>);
57
58impl<'el> IntoTokens<'el, Csharp<'el>> for Argument<'el> {
59 fn into_tokens(self) -> Tokens<'el, Csharp<'el>> {
60 let mut s = Tokens::new();
61
62 s.extend(self.attributes.into_iter());
63 s.extend(self.modifiers.into_tokens());
64 s.append(self.ty);
65 s.append(self.name);
66
67 s.join_spacing()
68 }
69}