Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: struct destructuring #2243

Merged
merged 38 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
115efc3
test: struct destructuring
matt-user Jul 1, 2022
bcec9bf
feat: add print statements for debugging
matt-user Jul 1, 2022
58dfcee
debugging: add print
matt-user Jul 1, 2022
9ae75e5
Merge branch 'mattauer/struct_destructuring' of https://github.com/Fu…
matt-user Jul 1, 2022
cb889fb
Merge remote-tracking branch 'origin/master' into mattauer/struct_des…
Jul 1, 2022
483d18b
Add Forc.lock.
Jul 1, 2022
74188c1
Add descriptions.
Jul 1, 2022
e06e04b
fix: remove println! statements
matt-user Jul 5, 2022
df1d3d5
chore: update to latest version
matt-user Jul 5, 2022
69aeccc
Merge branch 'mattauer/struct_destructuring' of https://github.com/Fu…
matt-user Jul 5, 2022
2af43ac
feat: add not working Pattern:Struct branch to match
matt-user Jul 5, 2022
204a251
fix: identation in oracle json
matt-user Jul 6, 2022
bd01ad5
feat: create pattern if field has none
matt-user Jul 6, 2022
60eaa9b
refactor: remove debug prints
matt-user Jul 6, 2022
d715323
fix: warnings
matt-user Jul 6, 2022
06292e8
test: type annotations for destructure
matt-user Jul 6, 2022
9f91f64
fix: handle type annotations
matt-user Jul 6, 2022
8e159fd
chore: run formatter
matt-user Jul 6, 2022
22c76dd
fix: remove test cargo toml
matt-user Jul 6, 2022
4cad09a
Merge branch 'master' into mattauer/struct_destructuring
matt-user Jul 6, 2022
60adadb
fix: destructure test case
matt-user Jul 6, 2022
5d8b0c3
test: nested struct destructuring
matt-user Jul 6, 2022
9d6b86a
docs: add struct destructuring
matt-user Jul 6, 2022
0730cb6
refactor: fix formatting
matt-user Jul 6, 2022
32fcea7
fix: formatting
matt-user Jul 6, 2022
5350b4c
refactor examples
matt-user Jul 6, 2022
f614df8
fix: formatting
matt-user Jul 6, 2022
3904206
fix: remove mention of deleted file
matt-user Jul 6, 2022
1a5b93e
test: nested tuple in struct and vis versa
matt-user Jul 7, 2022
11c5567
docs: add nested tuple in struct and vis versa to examples
matt-user Jul 7, 2022
b48937a
fix: formatting
matt-user Jul 7, 2022
802009d
fix: formatting
matt-user Jul 7, 2022
b9a0e6a
fix: formatting
matt-user Jul 7, 2022
7cd5ad6
fix: formatting
matt-user Jul 7, 2022
9139e18
Merge branch 'master' into mattauer/struct_destructuring
matt-user Jul 7, 2022
12b6f35
Merge branch 'mattauer/struct_destructuring' of https://github.com/Fu…
matt-user Jul 7, 2022
6575499
Merge branch 'master' into mattauer/struct_destructuring
matt-user Jul 7, 2022
fd69348
Merge branch 'master' into mattauer/struct_destructuring
otrho Jul 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[[package]]
name = 'core'
source = 'path+from-root-F93ECA3248F311E3'
dependencies = []

[[package]]
name = 'struct_destructuring'
source = 'root'
dependencies = ['core']
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
name = "struct_destructuring"

[dependencies]
core = { path = "../../../../../../../sway-lib-core" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[
{
"inputs": [],
"name": "main",
"outputs": [
{
"components": null,
"name": "",
"type": "u64",
"typeArguments": null
}
],
"type": "function"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
script;

// Tests nested struct destructuring

fn main() -> u64 {
let point1 = Point { x: 0, y: 0 };
let point2 = Point { x: 1, y: 1 };
let line = Line { p1: point1, p2: point2 };
let Line { p1: Point { x: x0, y: y0 }, p2: Point { x: x1, y: y1} } = line;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright, don't hate me, but what about a nested tuple in a struct and vice versa?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I can add a test for that. Should I also include an example for the docs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs example could be cool, to show people just how deep destructuring can go!

x0
}

struct Point {
x: u64,
y: u64,
}

struct Line {
p1: Point,
p2: Point,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
category = "run"
expected_result = { action = "return", value = 0 }
validate_abi = true