1use crate::rust::{RustType, WithRustType};
2use crate::{CodeBuffer, Expression, WithName};
3
4#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
6pub struct Var {
7 name: String,
8 rust_type: RustType,
9}
10
11impl<S: Into<String>, T: Into<RustType>> From<(S, T)> for Var {
12 fn from(tuple: (S, T)) -> Self {
13 Self {
14 name: tuple.0.into(),
15 rust_type: tuple.1.into(),
16 }
17 }
18}
19
20impl WithName for Var {
21 fn name(&self) -> &str {
22 self.name.as_str()
23 }
24}
25
26impl WithRustType for Var {
27 fn rust_type(&self) -> &RustType {
28 &self.rust_type
29 }
30}
31
32impl Expression for Var {
33 fn write(&self, b: &mut CodeBuffer) {
34 self.write_name(b);
35 b.write(": ");
36 self.write_rust_type(b);
37 }
38}