From 9f25a1967adb7975491bee37e43457c9dcdfc5de Mon Sep 17 00:00:00 2001 From: ljedrz Date: Wed, 19 Jun 2024 15:33:30 +0200 Subject: [PATCH] refactor: use type_name instead of literals for LiteralType::parse Signed-off-by: ljedrz --- .../src/data_types/literal_type/mod.rs | 2 +- .../src/data_types/literal_type/parse.rs | 34 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/console/program/src/data_types/literal_type/mod.rs b/console/program/src/data_types/literal_type/mod.rs index 4d0c765edb..8f1fcab4f0 100644 --- a/console/program/src/data_types/literal_type/mod.rs +++ b/console/program/src/data_types/literal_type/mod.rs @@ -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", diff --git a/console/program/src/data_types/literal_type/parse.rs b/console/program/src/data_types/literal_type/parse.rs index be4b875445..ecb1347bfe 100644 --- a/console/program/src/data_types/literal_type/parse.rs +++ b/console/program/src/data_types/literal_type/parse.rs @@ -21,23 +21,23 @@ impl Parser for LiteralType { fn parse(string: &str) -> ParserResult { // 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) } }