jnat/
type.rs

1/// An enum representing Java types
2#[derive(Clone, Copy)]
3pub enum Type<'a> {
4  /// A boolean type
5  Boolean,
6  /// A byte type
7  Byte,
8  /// A char type
9  Char,
10  /// A short type
11  Short,
12  /// An int type
13  Int,
14  /// A long type
15  Long,
16  /// A float type
17  Float,
18  /// A double type
19  Double,
20  /// A void type
21  Void,
22  /// An object type
23  Object(&'a str),
24  /// An array type
25  Array(&'a Type<'a>),
26}
27
28impl<'a> From<Type<'a>> for String {
29  fn from(r#type: Type) -> Self {
30    let result = match r#type {
31      Type::Boolean => "Z".into(),
32      Type::Byte => "B".into(),
33      Type::Char => "C".into(),
34      Type::Short => "S".into(),
35      Type::Int => "I".into(),
36      Type::Long => "J".into(),
37      Type::Float => "F".into(),
38      Type::Double => "D".into(),
39      Type::Void => "V".into(),
40      Type::Object(s) => format!("L{};", s),
41      Type::Array(t) => format!("[{}", <Type as Into<String>>::into(*t)),
42    };
43
44    result
45  }
46}