Skip to content

Commit

Permalink
refactor: use type_name instead of literals for LiteralType::parse
Browse files Browse the repository at this point in the history
Signed-off-by: ljedrz <ljedrz@users.noreply.github.com>
  • Loading branch information
ljedrz committed Nov 14, 2024
1 parent 0b391d2 commit 9f25a19
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion console/program/src/data_types/literal_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub enum LiteralType {

impl LiteralType {
/// Returns the literal type name.
pub fn type_name(&self) -> &str {
pub const fn type_name(&self) -> &str {
match self {
Self::Address => "address",
Self::Boolean => "boolean",
Expand Down
34 changes: 17 additions & 17 deletions console/program/src/data_types/literal_type/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ impl Parser for LiteralType {
fn parse(string: &str) -> ParserResult<Self> {
// Parse the type from the string.
alt((
map(tag("address"), |_| Self::Address),
map(tag("boolean"), |_| Self::Boolean),
map(tag("field"), |_| Self::Field),
map(tag("group"), |_| Self::Group),
map(tag("i8"), |_| Self::I8),
map(tag("i16"), |_| Self::I16),
map(tag("i32"), |_| Self::I32),
map(tag("i64"), |_| Self::I64),
map(tag("i128"), |_| Self::I128),
map(tag("u8"), |_| Self::U8),
map(tag("u16"), |_| Self::U16),
map(tag("u32"), |_| Self::U32),
map(tag("u64"), |_| Self::U64),
map(tag("u128"), |_| Self::U128),
map(tag("scalar"), |_| Self::Scalar),
map(tag("signature"), |_| Self::Signature),
map(tag("string"), |_| Self::String),
map(tag(Self::Address.type_name()), |_| Self::Address),
map(tag(Self::Boolean.type_name()), |_| Self::Boolean),
map(tag(Self::Field.type_name()), |_| Self::Field),
map(tag(Self::Group.type_name()), |_| Self::Group),
map(tag(Self::I8.type_name()), |_| Self::I8),
map(tag(Self::I16.type_name()), |_| Self::I16),
map(tag(Self::I32.type_name()), |_| Self::I32),
map(tag(Self::I64.type_name()), |_| Self::I64),
map(tag(Self::I128.type_name()), |_| Self::I128),
map(tag(Self::U8.type_name()), |_| Self::U8),
map(tag(Self::U16.type_name()), |_| Self::U16),
map(tag(Self::U32.type_name()), |_| Self::U32),
map(tag(Self::U64.type_name()), |_| Self::U64),
map(tag(Self::U128.type_name()), |_| Self::U128),
map(tag(Self::Scalar.type_name()), |_| Self::Scalar),
map(tag(Self::Signature.type_name()), |_| Self::Signature),
map(tag(Self::String.type_name()), |_| Self::String),
))(string)
}
}
Expand Down

0 comments on commit 9f25a19

Please sign in to comment.