-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add timestamp support, allow tuples with single field
- Loading branch information
Michael Zaikin
committed
Jul 11, 2023
1 parent
f9c01cd
commit 6f023c5
Showing
23 changed files
with
502 additions
and
139 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# SPDX-FileCopyrightText: 2023 Baking Bad <[email protected]> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
[package] | ||
name = "michelson_derive" | ||
version = "0.1.0" | ||
|
@@ -7,8 +11,8 @@ edition = "2021" | |
proc-macro = true | ||
|
||
[dependencies] | ||
tezos_michelson = { git = "https://github.com/m-kus/tezos-rust-sdk", branch = "feat/ibig-drop-in", package = "tezos-michelson", default-features = false } | ||
tezos_core = { git = "https://github.com/m-kus/tezos-rust-sdk", branch = "feat/ibig-drop-in", package = "tezos-core", default-features = false } | ||
tezos_michelson = { git = "https://github.com/baking-bad/tezos-rust-sdk", branch = "develop", package = "tezos-michelson", default-features = false } | ||
tezos_core = { git = "https://github.com/baking-bad/tezos-rust-sdk", branch = "develop", package = "tezos-core", default-features = false } | ||
proc-macro2 = "1.0" | ||
quote = "1.0" | ||
syn = "2.0.21" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Michelson derive | ||
|
||
This crate provides two procedure macros: | ||
- #[derive(MichelsonInterop)] for `struct` and `enum` | ||
- `michelson_tuple!` for tuples | ||
|
||
#### Tuples | ||
|
||
In order to derive `MichelsonInterop` trait for generic tuples: | ||
|
||
```rust | ||
michelson_derive::michelson_tuple!(A, B, C); | ||
``` | ||
Currently up to 6 fields, extend if you need more: | ||
|
||
- `pair a b` -> `(A, B)` | ||
- `pair a b c` -> `(A, B, C)` | ||
- `pair a b c d` -> `(A, B, C, D)` | ||
- `pair a b c d e` -> `(A, B, C, D, E)` | ||
- `pair a b c d e f` -> `(A, B, C, D, E, F)` | ||
|
||
#### Structs | ||
|
||
Structs vave to have 0 (Unit) or at least 2 fields: | ||
|
||
- `struct S {}` -> `unit` | ||
- `struct S ()` -> `unit` | ||
- `struct (A, B)` -> `pair a b` | ||
- `struct { a: A, b: B }` -> `pair (a %a) (b %b)` (named tuple) | ||
|
||
Nested pairs are always expanded to right combs. | ||
|
||
#### Enums | ||
|
||
Unit, newtype, and struct variants are supported (but only with >2 fields). | ||
|
||
```rust | ||
enum E { | ||
Default, | ||
EntrypointOne(A, B), | ||
EntrypointTwo { a: A, b: B } | ||
} | ||
``` | ||
|
||
Variant names are converted to snake case: | ||
|
||
``` | ||
(or (unit %default) | ||
(or (pair %entrypoint_one a b) | ||
(pair %entrypoint_two (a %a) (b %b)))) | ||
``` | ||
|
||
Nested ors are always expanded to right combs. |
Oops, something went wrong.