From aa09f2baceee6a0747899753f3993933c3097333 Mon Sep 17 00:00:00 2001 From: Nasr Date: Fri, 5 Jan 2024 19:47:47 -0500 Subject: [PATCH] refactor: type names --- build.rs | 2 +- dojo.h | 114 +++++++++++++++++++++++++-------------------------- src/types.rs | 24 +++++------ 3 files changed, 70 insertions(+), 70 deletions(-) diff --git a/build.rs b/build.rs index a4d75fd..b8ae851 100644 --- a/build.rs +++ b/build.rs @@ -16,7 +16,7 @@ fn main() { }; config.enumeration = cbindgen::EnumConfig { derive_helper_methods: true, - prefix_with_name: true, + // prefix_with_name: true, ..Default::default() }; config.export = cbindgen::ExportConfig { diff --git a/dojo.h b/dojo.h index c7d1925..b64f99b 100644 --- a/dojo.h +++ b/dojo.h @@ -4,22 +4,22 @@ #include typedef enum BlockTag { - BlockTagLatest, - BlockTagPending, + Latest, + Pending, } BlockTag; typedef enum ComparisonOperator { - ComparisonOperatorEq, - ComparisonOperatorNeq, - ComparisonOperatorGt, - ComparisonOperatorGte, - ComparisonOperatorLt, - ComparisonOperatorLte, + Eq, + Neq, + Gt, + Gte, + Lt, + Lte, } ComparisonOperator; typedef enum LogicalOperator { - LogicalOperatorAnd, - LogicalOperatorOr, + And, + Or, } LogicalOperator; typedef struct Account Account; @@ -33,8 +33,8 @@ typedef struct Error { } Error; typedef enum ResultToriiClient_Tag { - ResultToriiClientOkToriiClient, - ResultToriiClientErrToriiClient, + OkToriiClient, + ErrToriiClient, } ResultToriiClient_Tag; typedef struct ResultToriiClient { @@ -64,22 +64,22 @@ typedef struct FieldElement { } FieldElement; typedef enum Primitive_Tag { - PrimitiveU8, - PrimitiveU16, - PrimitiveU32, - PrimitiveU64, - PrimitiveU128, + U8, + U16, + U32, + U64, + U128, #if !defined(TARGET_POINTER_WIDTH_32) - PrimitiveU256, + U256, #endif #if defined(TARGET_POINTER_WIDTH_32) - PrimitiveU256, + U256, #endif - PrimitiveUSize, - PrimitiveBool, - PrimitiveFelt252, - PrimitiveClassHash, - PrimitiveContractAddress, + USize, + Bool, + Felt252, + ClassHash, + ContractAddress, } Primitive_Tag; typedef struct Primitive { @@ -166,10 +166,10 @@ typedef struct CArrayTy { } CArrayTy; typedef enum Ty_Tag { - TyPrimitive, - TyStruct, - TyEnum, - TyTuple, + Primitive_, + Struct_, + Enum_, + Tuple_, } Ty_Tag; typedef struct Ty { @@ -191,8 +191,8 @@ typedef struct Ty { } Ty; typedef enum COptionTy_Tag { - COptionTySomeTy, - COptionTyNoneTy, + SomeTy, + NoneTy, } COptionTy_Tag; typedef struct COptionTy { @@ -205,8 +205,8 @@ typedef struct COptionTy { } COptionTy; typedef enum ResultCOptionTy_Tag { - ResultCOptionTyOkCOptionTy, - ResultCOptionTyErrCOptionTy, + OkCOptionTy, + ErrCOptionTy, } ResultCOptionTy_Tag; typedef struct ResultCOptionTy { @@ -242,8 +242,8 @@ typedef struct CArrayEntity { } CArrayEntity; typedef enum ResultCArrayEntity_Tag { - ResultCArrayEntityOkCArrayEntity, - ResultCArrayEntityErrCArrayEntity, + OkCArrayEntity, + ErrCArrayEntity, } ResultCArrayEntity_Tag; typedef struct ResultCArrayEntity { @@ -264,11 +264,11 @@ typedef struct CArrayu8 { } CArrayu8; typedef enum ValueType_Tag { - ValueTypeString, - ValueTypeInt, - ValueTypeUInt, - ValueTypeBool, - ValueTypeBytes, + String, + Int, + UInt, + Bool, + Bytes, } ValueType_Tag; typedef struct ValueType { @@ -316,9 +316,9 @@ typedef struct CompositeClause { } CompositeClause; typedef enum Clause_Tag { - ClauseKeys, - ClauseMember, - ClauseComposite, + Keys, + Member, + Composite, } Clause_Tag; typedef struct Clause { @@ -337,8 +337,8 @@ typedef struct Clause { } Clause; typedef enum COptionClause_Tag { - COptionClauseSomeClause, - COptionClauseNoneClause, + SomeClause, + NoneClause, } COptionClause_Tag; typedef struct COptionClause { @@ -362,8 +362,8 @@ typedef struct CArrayKeysClause { } CArrayKeysClause; typedef enum Resultbool_Tag { - ResultboolOkbool, - ResultboolErrbool, + Okbool, + Errbool, } Resultbool_Tag; typedef struct Resultbool { @@ -422,8 +422,8 @@ typedef struct Signature { } Signature; typedef enum ResultSignature_Tag { - ResultSignatureOkSignature, - ResultSignatureErrSignature, + OkSignature, + ErrSignature, } ResultSignature_Tag; typedef struct ResultSignature { @@ -439,8 +439,8 @@ typedef struct ResultSignature { } ResultSignature; typedef enum ResultFieldElement_Tag { - ResultFieldElementOkFieldElement, - ResultFieldElementErrFieldElement, + OkFieldElement, + ErrFieldElement, } ResultFieldElement_Tag; typedef struct ResultFieldElement { @@ -456,8 +456,8 @@ typedef struct ResultFieldElement { } ResultFieldElement; typedef enum ResultCJsonRpcClient_Tag { - ResultCJsonRpcClientOkCJsonRpcClient, - ResultCJsonRpcClientErrCJsonRpcClient, + OkCJsonRpcClient, + ErrCJsonRpcClient, } ResultCJsonRpcClient_Tag; typedef struct ResultCJsonRpcClient { @@ -473,8 +473,8 @@ typedef struct ResultCJsonRpcClient { } ResultCJsonRpcClient; typedef enum ResultAccount_Tag { - ResultAccountOkAccount, - ResultAccountErrAccount, + OkAccount, + ErrAccount, } ResultAccount_Tag; typedef struct ResultAccount { @@ -493,9 +493,9 @@ typedef struct ResultAccount { * Block hash, number or tag */ typedef enum BlockId_Tag { - BlockIdHash, - BlockIdNumber, - BlockIdBlockTag, + Hash, + Number, + BlockTag, } BlockId_Tag; typedef struct BlockId { diff --git a/src/types.rs b/src/types.rs index 0a88858..adb174b 100644 --- a/src/types.rs +++ b/src/types.rs @@ -381,10 +381,10 @@ impl From<&torii_grpc::types::ValueType> for ValueType { #[repr(C)] #[allow(clippy::enum_variant_names)] pub enum Ty { - Primitive(Primitive), - Struct(Struct), - Enum(Enum), - Tuple(CArray), + Primitive_(Primitive), + Struct_(Struct), + Enum_(Enum), + Tuple_(CArray), } impl From<&dojo_types::schema::Ty> for Ty { @@ -393,17 +393,17 @@ impl From<&dojo_types::schema::Ty> for Ty { dojo_types::schema::Ty::Primitive(primitive) => { let primitive = primitive.into(); - Ty::Primitive(primitive) + Ty::Primitive_(primitive) } - dojo_types::schema::Ty::Struct(struct_) => Ty::Struct((&struct_.clone()).into()), - dojo_types::schema::Ty::Enum(enum_) => Ty::Enum((&enum_.clone()).into()), + dojo_types::schema::Ty::Struct(struct_) => Ty::Struct_((&struct_.clone()).into()), + dojo_types::schema::Ty::Enum(enum_) => Ty::Enum_((&enum_.clone()).into()), dojo_types::schema::Ty::Tuple(tuple) => { let children = tuple .iter() .map(|c| (&c.clone()).into()) .collect::>(); - Ty::Tuple(children.into()) + Ty::Tuple_(children.into()) } } } @@ -414,12 +414,12 @@ impl From<&dojo_types::schema::Ty> for Ty { impl From<&Ty> for dojo_types::schema::Ty { fn from(value: &Ty) -> Self { match value { - Ty::Primitive(primitive) => { + Ty::Primitive_(primitive) => { dojo_types::schema::Ty::Primitive((&primitive.clone()).into()) } - Ty::Struct(struct_) => dojo_types::schema::Ty::Struct((&struct_.clone()).into()), - Ty::Enum(enum_) => dojo_types::schema::Ty::Enum((&enum_.clone()).into()), - Ty::Tuple(tuple) => { + Ty::Struct_(struct_) => dojo_types::schema::Ty::Struct((&struct_.clone()).into()), + Ty::Enum_(enum_) => dojo_types::schema::Ty::Enum((&enum_.clone()).into()), + Ty::Tuple_(tuple) => { let children = unsafe { Vec::from_raw_parts(tuple.data, tuple.data_len, tuple.data_len) .iter()