Skip to content

Commit

Permalink
refactor: type names
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Jan 6, 2024
1 parent 03fac2e commit aa09f2b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 70 deletions.
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
114 changes: 57 additions & 57 deletions dojo.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
#include <stdlib.h>

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;
Expand All @@ -33,8 +33,8 @@ typedef struct Error {
} Error;

typedef enum ResultToriiClient_Tag {
ResultToriiClientOkToriiClient,
ResultToriiClientErrToriiClient,
OkToriiClient,
ErrToriiClient,
} ResultToriiClient_Tag;

typedef struct ResultToriiClient {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -191,8 +191,8 @@ typedef struct Ty {
} Ty;

typedef enum COptionTy_Tag {
COptionTySomeTy,
COptionTyNoneTy,
SomeTy,
NoneTy,
} COptionTy_Tag;

typedef struct COptionTy {
Expand All @@ -205,8 +205,8 @@ typedef struct COptionTy {
} COptionTy;

typedef enum ResultCOptionTy_Tag {
ResultCOptionTyOkCOptionTy,
ResultCOptionTyErrCOptionTy,
OkCOptionTy,
ErrCOptionTy,
} ResultCOptionTy_Tag;

typedef struct ResultCOptionTy {
Expand Down Expand Up @@ -242,8 +242,8 @@ typedef struct CArrayEntity {
} CArrayEntity;

typedef enum ResultCArrayEntity_Tag {
ResultCArrayEntityOkCArrayEntity,
ResultCArrayEntityErrCArrayEntity,
OkCArrayEntity,
ErrCArrayEntity,
} ResultCArrayEntity_Tag;

typedef struct ResultCArrayEntity {
Expand All @@ -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 {
Expand Down Expand Up @@ -316,9 +316,9 @@ typedef struct CompositeClause {
} CompositeClause;

typedef enum Clause_Tag {
ClauseKeys,
ClauseMember,
ClauseComposite,
Keys,
Member,
Composite,
} Clause_Tag;

typedef struct Clause {
Expand All @@ -337,8 +337,8 @@ typedef struct Clause {
} Clause;

typedef enum COptionClause_Tag {
COptionClauseSomeClause,
COptionClauseNoneClause,
SomeClause,
NoneClause,
} COptionClause_Tag;

typedef struct COptionClause {
Expand All @@ -362,8 +362,8 @@ typedef struct CArrayKeysClause {
} CArrayKeysClause;

typedef enum Resultbool_Tag {
ResultboolOkbool,
ResultboolErrbool,
Okbool,
Errbool,
} Resultbool_Tag;

typedef struct Resultbool {
Expand Down Expand Up @@ -422,8 +422,8 @@ typedef struct Signature {
} Signature;

typedef enum ResultSignature_Tag {
ResultSignatureOkSignature,
ResultSignatureErrSignature,
OkSignature,
ErrSignature,
} ResultSignature_Tag;

typedef struct ResultSignature {
Expand All @@ -439,8 +439,8 @@ typedef struct ResultSignature {
} ResultSignature;

typedef enum ResultFieldElement_Tag {
ResultFieldElementOkFieldElement,
ResultFieldElementErrFieldElement,
OkFieldElement,
ErrFieldElement,
} ResultFieldElement_Tag;

typedef struct ResultFieldElement {
Expand All @@ -456,8 +456,8 @@ typedef struct ResultFieldElement {
} ResultFieldElement;

typedef enum ResultCJsonRpcClient_Tag {
ResultCJsonRpcClientOkCJsonRpcClient,
ResultCJsonRpcClientErrCJsonRpcClient,
OkCJsonRpcClient,
ErrCJsonRpcClient,
} ResultCJsonRpcClient_Tag;

typedef struct ResultCJsonRpcClient {
Expand All @@ -473,8 +473,8 @@ typedef struct ResultCJsonRpcClient {
} ResultCJsonRpcClient;

typedef enum ResultAccount_Tag {
ResultAccountOkAccount,
ResultAccountErrAccount,
OkAccount,
ErrAccount,
} ResultAccount_Tag;

typedef struct ResultAccount {
Expand All @@ -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 {
Expand Down
24 changes: 12 additions & 12 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ty>),
Primitive_(Primitive),
Struct_(Struct),
Enum_(Enum),
Tuple_(CArray<Ty>),
}

impl From<&dojo_types::schema::Ty> for Ty {
Expand All @@ -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::<Vec<_>>();

Ty::Tuple(children.into())
Ty::Tuple_(children.into())
}
}
}
Expand All @@ -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()
Expand Down

0 comments on commit aa09f2b

Please sign in to comment.