diff --git a/.tool-versions b/.tool-versions index ebe254233..f239fe235 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -scarb 2.5.3 +scarb 2.6.3 diff --git a/listings/ch02-common-programming-concepts/listing_01_statement/Scarb.lock b/listings/ch02-common-programming-concepts/listing_01_statement/Scarb.lock deleted file mode 100644 index 9d1736381..000000000 --- a/listings/ch02-common-programming-concepts/listing_01_statement/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "listing_01_statement" -version = "0.1.0" diff --git a/listings/ch02-common-programming-concepts/listing_01_statement/.gitignore b/listings/ch02-common-programming-concepts/no_listing_18_named_parameters/.gitignore similarity index 100% rename from listings/ch02-common-programming-concepts/listing_01_statement/.gitignore rename to listings/ch02-common-programming-concepts/no_listing_18_named_parameters/.gitignore diff --git a/listings/ch02-common-programming-concepts/no_listing_32_named_parameters/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_18_named_parameters/Scarb.toml similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_32_named_parameters/Scarb.toml rename to listings/ch02-common-programming-concepts/no_listing_18_named_parameters/Scarb.toml diff --git a/listings/ch02-common-programming-concepts/no_listing_32_named_parameters/src/lib.cairo b/listings/ch02-common-programming-concepts/no_listing_18_named_parameters/src/lib.cairo similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_32_named_parameters/src/lib.cairo rename to listings/ch02-common-programming-concepts/no_listing_18_named_parameters/src/lib.cairo diff --git a/listings/ch02-common-programming-concepts/no_listing_18_statements_dont_return_values/Scarb.lock b/listings/ch02-common-programming-concepts/no_listing_18_statements_dont_return_values/Scarb.lock deleted file mode 100644 index e7eeff3dc..000000000 --- a/listings/ch02-common-programming-concepts/no_listing_18_statements_dont_return_values/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_18_statements_dont_return_values" -version = "0.1.0" diff --git a/listings/ch02-common-programming-concepts/no_listing_19_blocks_are_expressions/Scarb.lock b/listings/ch02-common-programming-concepts/no_listing_19_blocks_are_expressions/Scarb.lock deleted file mode 100644 index 7bef8b9a1..000000000 --- a/listings/ch02-common-programming-concepts/no_listing_19_blocks_are_expressions/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_19_blocks_are_expressions" -version = "0.1.0" diff --git a/listings/ch02-common-programming-concepts/no_listing_18_statements_dont_return_values/.gitignore b/listings/ch02-common-programming-concepts/no_listing_19_statement/.gitignore similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_18_statements_dont_return_values/.gitignore rename to listings/ch02-common-programming-concepts/no_listing_19_statement/.gitignore diff --git a/listings/ch02-common-programming-concepts/listing_01_statement/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_19_statement/Scarb.toml similarity index 100% rename from listings/ch02-common-programming-concepts/listing_01_statement/Scarb.toml rename to listings/ch02-common-programming-concepts/no_listing_19_statement/Scarb.toml diff --git a/listings/ch02-common-programming-concepts/listing_01_statement/src/lib.cairo b/listings/ch02-common-programming-concepts/no_listing_19_statement/src/lib.cairo similarity index 100% rename from listings/ch02-common-programming-concepts/listing_01_statement/src/lib.cairo rename to listings/ch02-common-programming-concepts/no_listing_19_statement/src/lib.cairo diff --git a/listings/ch02-common-programming-concepts/no_listing_20_function_return_values/Scarb.lock b/listings/ch02-common-programming-concepts/no_listing_20_function_return_values/Scarb.lock deleted file mode 100644 index c811cbd02..000000000 --- a/listings/ch02-common-programming-concepts/no_listing_20_function_return_values/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_20_function_return_values" -version = "0.1.0" diff --git a/listings/ch02-common-programming-concepts/no_listing_19_blocks_are_expressions/.gitignore b/listings/ch02-common-programming-concepts/no_listing_20_statements_dont_return_values/.gitignore similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_19_blocks_are_expressions/.gitignore rename to listings/ch02-common-programming-concepts/no_listing_20_statements_dont_return_values/.gitignore diff --git a/listings/ch02-common-programming-concepts/no_listing_18_statements_dont_return_values/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_20_statements_dont_return_values/Scarb.toml similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_18_statements_dont_return_values/Scarb.toml rename to listings/ch02-common-programming-concepts/no_listing_20_statements_dont_return_values/Scarb.toml diff --git a/listings/ch02-common-programming-concepts/no_listing_18_statements_dont_return_values/src/lib.cairo b/listings/ch02-common-programming-concepts/no_listing_20_statements_dont_return_values/src/lib.cairo similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_18_statements_dont_return_values/src/lib.cairo rename to listings/ch02-common-programming-concepts/no_listing_20_statements_dont_return_values/src/lib.cairo diff --git a/listings/ch02-common-programming-concepts/no_listing_20_function_return_values/.gitignore b/listings/ch02-common-programming-concepts/no_listing_21_blocks_are_expressions/.gitignore similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_20_function_return_values/.gitignore rename to listings/ch02-common-programming-concepts/no_listing_21_blocks_are_expressions/.gitignore diff --git a/listings/ch02-common-programming-concepts/no_listing_19_blocks_are_expressions/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_21_blocks_are_expressions/Scarb.toml similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_19_blocks_are_expressions/Scarb.toml rename to listings/ch02-common-programming-concepts/no_listing_21_blocks_are_expressions/Scarb.toml diff --git a/listings/ch02-common-programming-concepts/no_listing_19_blocks_are_expressions/src/lib.cairo b/listings/ch02-common-programming-concepts/no_listing_21_blocks_are_expressions/src/lib.cairo similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_19_blocks_are_expressions/src/lib.cairo rename to listings/ch02-common-programming-concepts/no_listing_21_blocks_are_expressions/src/lib.cairo diff --git a/listings/ch02-common-programming-concepts/no_listing_21_function_return_values_2/Scarb.lock b/listings/ch02-common-programming-concepts/no_listing_21_function_return_values_2/Scarb.lock deleted file mode 100644 index 3fabebd72..000000000 --- a/listings/ch02-common-programming-concepts/no_listing_21_function_return_values_2/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_21_function_return_values_2" -version = "0.1.0" diff --git a/listings/ch02-common-programming-concepts/no_listing_22_function_return_invalid/Scarb.lock b/listings/ch02-common-programming-concepts/no_listing_22_function_return_invalid/Scarb.lock deleted file mode 100644 index 22254edb8..000000000 --- a/listings/ch02-common-programming-concepts/no_listing_22_function_return_invalid/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_22_function_return_invalid" -version = "0.1.0" diff --git a/listings/ch02-common-programming-concepts/no_listing_21_function_return_values_2/.gitignore b/listings/ch02-common-programming-concepts/no_listing_22_function_return_values/.gitignore similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_21_function_return_values_2/.gitignore rename to listings/ch02-common-programming-concepts/no_listing_22_function_return_values/.gitignore diff --git a/listings/ch02-common-programming-concepts/no_listing_20_function_return_values/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_22_function_return_values/Scarb.toml similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_20_function_return_values/Scarb.toml rename to listings/ch02-common-programming-concepts/no_listing_22_function_return_values/Scarb.toml diff --git a/listings/ch02-common-programming-concepts/no_listing_20_function_return_values/src/lib.cairo b/listings/ch02-common-programming-concepts/no_listing_22_function_return_values/src/lib.cairo similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_20_function_return_values/src/lib.cairo rename to listings/ch02-common-programming-concepts/no_listing_22_function_return_values/src/lib.cairo diff --git a/listings/ch02-common-programming-concepts/no_listing_23_comments/Scarb.lock b/listings/ch02-common-programming-concepts/no_listing_23_comments/Scarb.lock deleted file mode 100644 index a6def423c..000000000 --- a/listings/ch02-common-programming-concepts/no_listing_23_comments/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_23_comments" -version = "0.1.0" diff --git a/listings/ch02-common-programming-concepts/no_listing_23_comments_2/Scarb.lock b/listings/ch02-common-programming-concepts/no_listing_23_comments_2/Scarb.lock deleted file mode 100644 index 923e5865f..000000000 --- a/listings/ch02-common-programming-concepts/no_listing_23_comments_2/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_23_comments_2" -version = "0.1.0" diff --git a/listings/ch02-common-programming-concepts/no_listing_22_function_return_invalid/.gitignore b/listings/ch02-common-programming-concepts/no_listing_23_function_return_values_2/.gitignore similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_22_function_return_invalid/.gitignore rename to listings/ch02-common-programming-concepts/no_listing_23_function_return_values_2/.gitignore diff --git a/listings/ch02-common-programming-concepts/no_listing_21_function_return_values_2/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_23_function_return_values_2/Scarb.toml similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_21_function_return_values_2/Scarb.toml rename to listings/ch02-common-programming-concepts/no_listing_23_function_return_values_2/Scarb.toml diff --git a/listings/ch02-common-programming-concepts/no_listing_21_function_return_values_2/src/lib.cairo b/listings/ch02-common-programming-concepts/no_listing_23_function_return_values_2/src/lib.cairo similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_21_function_return_values_2/src/lib.cairo rename to listings/ch02-common-programming-concepts/no_listing_23_function_return_values_2/src/lib.cairo diff --git a/listings/ch02-common-programming-concepts/no_listing_24_bis_if_not_bool/Scarb.lock b/listings/ch02-common-programming-concepts/no_listing_24_bis_if_not_bool/Scarb.lock deleted file mode 100644 index 5a19df5bd..000000000 --- a/listings/ch02-common-programming-concepts/no_listing_24_bis_if_not_bool/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_24_bis_if_not_bool" -version = "0.1.0" diff --git a/listings/ch02-common-programming-concepts/no_listing_23_comments/.gitignore b/listings/ch02-common-programming-concepts/no_listing_24_function_return_invalid/.gitignore similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_23_comments/.gitignore rename to listings/ch02-common-programming-concepts/no_listing_24_function_return_invalid/.gitignore diff --git a/listings/ch02-common-programming-concepts/no_listing_22_function_return_invalid/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_24_function_return_invalid/Scarb.toml similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_22_function_return_invalid/Scarb.toml rename to listings/ch02-common-programming-concepts/no_listing_24_function_return_invalid/Scarb.toml diff --git a/listings/ch02-common-programming-concepts/no_listing_22_function_return_invalid/src/lib.cairo b/listings/ch02-common-programming-concepts/no_listing_24_function_return_invalid/src/lib.cairo similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_22_function_return_invalid/src/lib.cairo rename to listings/ch02-common-programming-concepts/no_listing_24_function_return_invalid/src/lib.cairo diff --git a/listings/ch02-common-programming-concepts/no_listing_24_if/Scarb.lock b/listings/ch02-common-programming-concepts/no_listing_24_if/Scarb.lock deleted file mode 100644 index 4d7a286d4..000000000 --- a/listings/ch02-common-programming-concepts/no_listing_24_if/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_24_if" -version = "0.1.0" diff --git a/listings/ch02-common-programming-concepts/no_listing_24_ter_if_not_equal_zero/Scarb.lock b/listings/ch02-common-programming-concepts/no_listing_24_ter_if_not_equal_zero/Scarb.lock deleted file mode 100644 index 5a48384c8..000000000 --- a/listings/ch02-common-programming-concepts/no_listing_24_ter_if_not_equal_zero/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_24_ter_if_not_equal_zero" -version = "0.1.0" diff --git a/listings/ch02-common-programming-concepts/no_listing_23_comments_2/.gitignore b/listings/ch02-common-programming-concepts/no_listing_25_comments/.gitignore similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_23_comments_2/.gitignore rename to listings/ch02-common-programming-concepts/no_listing_25_comments/.gitignore diff --git a/listings/ch02-common-programming-concepts/no_listing_23_comments/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_25_comments/Scarb.toml similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_23_comments/Scarb.toml rename to listings/ch02-common-programming-concepts/no_listing_25_comments/Scarb.toml diff --git a/listings/ch02-common-programming-concepts/no_listing_23_comments/src/lib.cairo b/listings/ch02-common-programming-concepts/no_listing_25_comments/src/lib.cairo similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_23_comments/src/lib.cairo rename to listings/ch02-common-programming-concepts/no_listing_25_comments/src/lib.cairo diff --git a/listings/ch02-common-programming-concepts/no_listing_25_else_if/Scarb.lock b/listings/ch02-common-programming-concepts/no_listing_25_else_if/Scarb.lock deleted file mode 100644 index 681ef8692..000000000 --- a/listings/ch02-common-programming-concepts/no_listing_25_else_if/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_25_else_if" -version = "0.1.0" diff --git a/listings/ch02-common-programming-concepts/no_listing_24_bis_if_not_bool/.gitignore b/listings/ch02-common-programming-concepts/no_listing_26_comments_2/.gitignore similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_24_bis_if_not_bool/.gitignore rename to listings/ch02-common-programming-concepts/no_listing_26_comments_2/.gitignore diff --git a/listings/ch02-common-programming-concepts/no_listing_23_comments_2/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_26_comments_2/Scarb.toml similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_23_comments_2/Scarb.toml rename to listings/ch02-common-programming-concepts/no_listing_26_comments_2/Scarb.toml diff --git a/listings/ch02-common-programming-concepts/no_listing_23_comments_2/src/lib.cairo b/listings/ch02-common-programming-concepts/no_listing_26_comments_2/src/lib.cairo similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_23_comments_2/src/lib.cairo rename to listings/ch02-common-programming-concepts/no_listing_26_comments_2/src/lib.cairo diff --git a/listings/ch02-common-programming-concepts/no_listing_26_if_let/Scarb.lock b/listings/ch02-common-programming-concepts/no_listing_26_if_let/Scarb.lock deleted file mode 100644 index e563b3d11..000000000 --- a/listings/ch02-common-programming-concepts/no_listing_26_if_let/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_26_if_let" -version = "0.1.0" diff --git a/listings/ch02-common-programming-concepts/no_listing_24_if/.gitignore b/listings/ch02-common-programming-concepts/no_listing_27_if/.gitignore similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_24_if/.gitignore rename to listings/ch02-common-programming-concepts/no_listing_27_if/.gitignore diff --git a/listings/ch02-common-programming-concepts/no_listing_24_if/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_27_if/Scarb.toml similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_24_if/Scarb.toml rename to listings/ch02-common-programming-concepts/no_listing_27_if/Scarb.toml diff --git a/listings/ch02-common-programming-concepts/no_listing_24_if/src/lib.cairo b/listings/ch02-common-programming-concepts/no_listing_27_if/src/lib.cairo similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_24_if/src/lib.cairo rename to listings/ch02-common-programming-concepts/no_listing_27_if/src/lib.cairo diff --git a/listings/ch02-common-programming-concepts/no_listing_27_infinite_loop/Scarb.lock b/listings/ch02-common-programming-concepts/no_listing_27_infinite_loop/Scarb.lock deleted file mode 100644 index f3791d5dd..000000000 --- a/listings/ch02-common-programming-concepts/no_listing_27_infinite_loop/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_27_infinite_loop" -version = "0.1.0" diff --git a/listings/ch02-common-programming-concepts/no_listing_24_ter_if_not_equal_zero/.gitignore b/listings/ch02-common-programming-concepts/no_listing_28_bis_if_not_bool/.gitignore similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_24_ter_if_not_equal_zero/.gitignore rename to listings/ch02-common-programming-concepts/no_listing_28_bis_if_not_bool/.gitignore diff --git a/listings/ch02-common-programming-concepts/no_listing_24_bis_if_not_bool/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_28_bis_if_not_bool/Scarb.toml similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_24_bis_if_not_bool/Scarb.toml rename to listings/ch02-common-programming-concepts/no_listing_28_bis_if_not_bool/Scarb.toml diff --git a/listings/ch02-common-programming-concepts/no_listing_24_bis_if_not_bool/src/lib.cairo b/listings/ch02-common-programming-concepts/no_listing_28_bis_if_not_bool/src/lib.cairo similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_24_bis_if_not_bool/src/lib.cairo rename to listings/ch02-common-programming-concepts/no_listing_28_bis_if_not_bool/src/lib.cairo diff --git a/listings/ch02-common-programming-concepts/no_listing_28_loop_break/Scarb.lock b/listings/ch02-common-programming-concepts/no_listing_28_loop_break/Scarb.lock deleted file mode 100644 index 3605bf451..000000000 --- a/listings/ch02-common-programming-concepts/no_listing_28_loop_break/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_28_loop_break" -version = "0.1.0" diff --git a/listings/ch02-common-programming-concepts/no_listing_29_loop_continue/Scarb.lock b/listings/ch02-common-programming-concepts/no_listing_29_loop_continue/Scarb.lock deleted file mode 100644 index 67ad580b1..000000000 --- a/listings/ch02-common-programming-concepts/no_listing_29_loop_continue/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_29_loop_continue" -version = "0.1.0" diff --git a/listings/ch02-common-programming-concepts/no_listing_25_else_if/.gitignore b/listings/ch02-common-programming-concepts/no_listing_29_ter_if_not_equal_zero/.gitignore similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_25_else_if/.gitignore rename to listings/ch02-common-programming-concepts/no_listing_29_ter_if_not_equal_zero/.gitignore diff --git a/listings/ch02-common-programming-concepts/no_listing_24_ter_if_not_equal_zero/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_29_ter_if_not_equal_zero/Scarb.toml similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_24_ter_if_not_equal_zero/Scarb.toml rename to listings/ch02-common-programming-concepts/no_listing_29_ter_if_not_equal_zero/Scarb.toml diff --git a/listings/ch02-common-programming-concepts/no_listing_24_ter_if_not_equal_zero/src/lib.cairo b/listings/ch02-common-programming-concepts/no_listing_29_ter_if_not_equal_zero/src/lib.cairo similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_24_ter_if_not_equal_zero/src/lib.cairo rename to listings/ch02-common-programming-concepts/no_listing_29_ter_if_not_equal_zero/src/lib.cairo diff --git a/listings/ch02-common-programming-concepts/no_listing_26_if_let/.gitignore b/listings/ch02-common-programming-concepts/no_listing_30_else_if/.gitignore similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_26_if_let/.gitignore rename to listings/ch02-common-programming-concepts/no_listing_30_else_if/.gitignore diff --git a/listings/ch02-common-programming-concepts/no_listing_25_else_if/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_30_else_if/Scarb.toml similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_25_else_if/Scarb.toml rename to listings/ch02-common-programming-concepts/no_listing_30_else_if/Scarb.toml diff --git a/listings/ch02-common-programming-concepts/no_listing_25_else_if/src/lib.cairo b/listings/ch02-common-programming-concepts/no_listing_30_else_if/src/lib.cairo similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_25_else_if/src/lib.cairo rename to listings/ch02-common-programming-concepts/no_listing_30_else_if/src/lib.cairo diff --git a/listings/ch02-common-programming-concepts/no_listing_30_loop_return_values/Scarb.lock b/listings/ch02-common-programming-concepts/no_listing_30_loop_return_values/Scarb.lock deleted file mode 100644 index 4cc52f71a..000000000 --- a/listings/ch02-common-programming-concepts/no_listing_30_loop_return_values/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_30_loop_return_values" -version = "0.1.0" diff --git a/listings/ch02-common-programming-concepts/no_listing_27_infinite_loop/.gitignore b/listings/ch02-common-programming-concepts/no_listing_31_if_let/.gitignore similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_27_infinite_loop/.gitignore rename to listings/ch02-common-programming-concepts/no_listing_31_if_let/.gitignore diff --git a/listings/ch02-common-programming-concepts/no_listing_26_if_let/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_31_if_let/Scarb.toml similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_26_if_let/Scarb.toml rename to listings/ch02-common-programming-concepts/no_listing_31_if_let/Scarb.toml diff --git a/listings/ch02-common-programming-concepts/no_listing_26_if_let/src/lib.cairo b/listings/ch02-common-programming-concepts/no_listing_31_if_let/src/lib.cairo similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_26_if_let/src/lib.cairo rename to listings/ch02-common-programming-concepts/no_listing_31_if_let/src/lib.cairo diff --git a/listings/ch02-common-programming-concepts/no_listing_31_while_loop/Scarb.lock b/listings/ch02-common-programming-concepts/no_listing_31_while_loop/Scarb.lock deleted file mode 100644 index bbb318c89..000000000 --- a/listings/ch02-common-programming-concepts/no_listing_31_while_loop/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_31_while_loop" -version = "0.1.0" diff --git a/listings/ch02-common-programming-concepts/no_listing_28_loop_break/.gitignore b/listings/ch02-common-programming-concepts/no_listing_32_infinite_loop/.gitignore similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_28_loop_break/.gitignore rename to listings/ch02-common-programming-concepts/no_listing_32_infinite_loop/.gitignore diff --git a/listings/ch02-common-programming-concepts/no_listing_27_infinite_loop/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_32_infinite_loop/Scarb.toml similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_27_infinite_loop/Scarb.toml rename to listings/ch02-common-programming-concepts/no_listing_32_infinite_loop/Scarb.toml diff --git a/listings/ch02-common-programming-concepts/no_listing_27_infinite_loop/src/lib.cairo b/listings/ch02-common-programming-concepts/no_listing_32_infinite_loop/src/lib.cairo similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_27_infinite_loop/src/lib.cairo rename to listings/ch02-common-programming-concepts/no_listing_32_infinite_loop/src/lib.cairo diff --git a/listings/ch02-common-programming-concepts/no_listing_32_named_parameters/Scarb.lock b/listings/ch02-common-programming-concepts/no_listing_32_named_parameters/Scarb.lock deleted file mode 100644 index 5715fd79c..000000000 --- a/listings/ch02-common-programming-concepts/no_listing_32_named_parameters/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_32_named_parameters" -version = "0.1.0" diff --git a/listings/ch02-common-programming-concepts/no_listing_29_loop_continue/.gitignore b/listings/ch02-common-programming-concepts/no_listing_33_loop_break/.gitignore similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_29_loop_continue/.gitignore rename to listings/ch02-common-programming-concepts/no_listing_33_loop_break/.gitignore diff --git a/listings/ch02-common-programming-concepts/no_listing_28_loop_break/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_33_loop_break/Scarb.toml similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_28_loop_break/Scarb.toml rename to listings/ch02-common-programming-concepts/no_listing_33_loop_break/Scarb.toml diff --git a/listings/ch02-common-programming-concepts/no_listing_28_loop_break/src/lib.cairo b/listings/ch02-common-programming-concepts/no_listing_33_loop_break/src/lib.cairo similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_28_loop_break/src/lib.cairo rename to listings/ch02-common-programming-concepts/no_listing_33_loop_break/src/lib.cairo diff --git a/listings/ch02-common-programming-concepts/no_listing_30_loop_return_values/.gitignore b/listings/ch02-common-programming-concepts/no_listing_34_loop_continue/.gitignore similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_30_loop_return_values/.gitignore rename to listings/ch02-common-programming-concepts/no_listing_34_loop_continue/.gitignore diff --git a/listings/ch02-common-programming-concepts/no_listing_29_loop_continue/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_34_loop_continue/Scarb.toml similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_29_loop_continue/Scarb.toml rename to listings/ch02-common-programming-concepts/no_listing_34_loop_continue/Scarb.toml diff --git a/listings/ch02-common-programming-concepts/no_listing_29_loop_continue/src/lib.cairo b/listings/ch02-common-programming-concepts/no_listing_34_loop_continue/src/lib.cairo similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_29_loop_continue/src/lib.cairo rename to listings/ch02-common-programming-concepts/no_listing_34_loop_continue/src/lib.cairo diff --git a/listings/ch02-common-programming-concepts/no_listing_32_named_parameters/.gitignore b/listings/ch02-common-programming-concepts/no_listing_35_loop_return_values/.gitignore similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_32_named_parameters/.gitignore rename to listings/ch02-common-programming-concepts/no_listing_35_loop_return_values/.gitignore diff --git a/listings/ch02-common-programming-concepts/no_listing_30_loop_return_values/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_35_loop_return_values/Scarb.toml similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_30_loop_return_values/Scarb.toml rename to listings/ch02-common-programming-concepts/no_listing_35_loop_return_values/Scarb.toml diff --git a/listings/ch02-common-programming-concepts/no_listing_30_loop_return_values/src/lib.cairo b/listings/ch02-common-programming-concepts/no_listing_35_loop_return_values/src/lib.cairo similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_30_loop_return_values/src/lib.cairo rename to listings/ch02-common-programming-concepts/no_listing_35_loop_return_values/src/lib.cairo diff --git a/listings/ch02-common-programming-concepts/no_listing_31_while_loop/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_36_while_loop/Scarb.toml similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_31_while_loop/Scarb.toml rename to listings/ch02-common-programming-concepts/no_listing_36_while_loop/Scarb.toml diff --git a/listings/ch02-common-programming-concepts/no_listing_31_while_loop/src/lib.cairo b/listings/ch02-common-programming-concepts/no_listing_36_while_loop/src/lib.cairo similarity index 100% rename from listings/ch02-common-programming-concepts/no_listing_31_while_loop/src/lib.cairo rename to listings/ch02-common-programming-concepts/no_listing_36_while_loop/src/lib.cairo diff --git a/listings/ch03-common-collections/no_listing_00_array_new_append/Scarb.lock b/listings/ch03-common-collections/no_listing_00_array_new_append/Scarb.lock deleted file mode 100644 index 9f56d31e3..000000000 --- a/listings/ch03-common-collections/no_listing_00_array_new_append/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_00_array_new_append" -version = "0.1.0" diff --git a/listings/ch03-common-collections/no_listing_00_array_new_append/.gitignore b/listings/ch03-common-collections/no_listing_01_array_new_append/.gitignore similarity index 100% rename from listings/ch03-common-collections/no_listing_00_array_new_append/.gitignore rename to listings/ch03-common-collections/no_listing_01_array_new_append/.gitignore diff --git a/listings/ch03-common-collections/no_listing_00_array_new_append/Scarb.toml b/listings/ch03-common-collections/no_listing_01_array_new_append/Scarb.toml similarity index 100% rename from listings/ch03-common-collections/no_listing_00_array_new_append/Scarb.toml rename to listings/ch03-common-collections/no_listing_01_array_new_append/Scarb.toml diff --git a/listings/ch03-common-collections/no_listing_00_array_new_append/src/lib.cairo b/listings/ch03-common-collections/no_listing_01_array_new_append/src/lib.cairo similarity index 100% rename from listings/ch03-common-collections/no_listing_00_array_new_append/src/lib.cairo rename to listings/ch03-common-collections/no_listing_01_array_new_append/src/lib.cairo diff --git a/listings/ch03-common-collections/no_listing_01_array_pop_front/Scarb.lock b/listings/ch03-common-collections/no_listing_01_array_pop_front/Scarb.lock deleted file mode 100644 index 28227c9e8..000000000 --- a/listings/ch03-common-collections/no_listing_01_array_pop_front/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_01_array_pop_front" -version = "0.1.0" diff --git a/listings/ch03-common-collections/no_listing_02_array_at/Scarb.lock b/listings/ch03-common-collections/no_listing_02_array_at/Scarb.lock deleted file mode 100644 index 8a63194ff..000000000 --- a/listings/ch03-common-collections/no_listing_02_array_at/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_02_array_at" -version = "0.1.0" diff --git a/listings/ch03-common-collections/no_listing_02_array_at_2/Scarb.lock b/listings/ch03-common-collections/no_listing_02_array_at_2/Scarb.lock deleted file mode 100644 index 91e85ec49..000000000 --- a/listings/ch03-common-collections/no_listing_02_array_at_2/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_02_array_at_2" -version = "0.1.0" diff --git a/listings/ch03-common-collections/no_listing_01_array_pop_front/.gitignore b/listings/ch03-common-collections/no_listing_02_array_pop_front/.gitignore similarity index 100% rename from listings/ch03-common-collections/no_listing_01_array_pop_front/.gitignore rename to listings/ch03-common-collections/no_listing_02_array_pop_front/.gitignore diff --git a/listings/ch03-common-collections/no_listing_01_array_pop_front/Scarb.toml b/listings/ch03-common-collections/no_listing_02_array_pop_front/Scarb.toml similarity index 100% rename from listings/ch03-common-collections/no_listing_01_array_pop_front/Scarb.toml rename to listings/ch03-common-collections/no_listing_02_array_pop_front/Scarb.toml diff --git a/listings/ch03-common-collections/no_listing_01_array_pop_front/src/lib.cairo b/listings/ch03-common-collections/no_listing_02_array_pop_front/src/lib.cairo similarity index 100% rename from listings/ch03-common-collections/no_listing_01_array_pop_front/src/lib.cairo rename to listings/ch03-common-collections/no_listing_02_array_pop_front/src/lib.cairo diff --git a/listings/ch03-common-collections/no_listing_02_array_at/.gitignore b/listings/ch03-common-collections/no_listing_04_array_at/.gitignore similarity index 100% rename from listings/ch03-common-collections/no_listing_02_array_at/.gitignore rename to listings/ch03-common-collections/no_listing_04_array_at/.gitignore diff --git a/listings/ch03-common-collections/no_listing_02_array_at/Scarb.toml b/listings/ch03-common-collections/no_listing_04_array_at/Scarb.toml similarity index 100% rename from listings/ch03-common-collections/no_listing_02_array_at/Scarb.toml rename to listings/ch03-common-collections/no_listing_04_array_at/Scarb.toml diff --git a/listings/ch03-common-collections/no_listing_02_array_at/src/lib.cairo b/listings/ch03-common-collections/no_listing_04_array_at/src/lib.cairo similarity index 100% rename from listings/ch03-common-collections/no_listing_02_array_at/src/lib.cairo rename to listings/ch03-common-collections/no_listing_04_array_at/src/lib.cairo diff --git a/listings/ch03-common-collections/no_listing_04_array_with_enums/Scarb.lock b/listings/ch03-common-collections/no_listing_04_array_with_enums/Scarb.lock deleted file mode 100644 index 6e598ba72..000000000 --- a/listings/ch03-common-collections/no_listing_04_array_with_enums/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_04_array_with_enums" -version = "0.1.0" diff --git a/listings/ch03-common-collections/no_listing_02_array_at_2/.gitignore b/listings/ch03-common-collections/no_listing_05_array_at_2/.gitignore similarity index 100% rename from listings/ch03-common-collections/no_listing_02_array_at_2/.gitignore rename to listings/ch03-common-collections/no_listing_05_array_at_2/.gitignore diff --git a/listings/ch03-common-collections/no_listing_02_array_at_2/Scarb.toml b/listings/ch03-common-collections/no_listing_05_array_at_2/Scarb.toml similarity index 100% rename from listings/ch03-common-collections/no_listing_02_array_at_2/Scarb.toml rename to listings/ch03-common-collections/no_listing_05_array_at_2/Scarb.toml diff --git a/listings/ch03-common-collections/no_listing_02_array_at_2/src/lib.cairo b/listings/ch03-common-collections/no_listing_05_array_at_2/src/lib.cairo similarity index 100% rename from listings/ch03-common-collections/no_listing_02_array_at_2/src/lib.cairo rename to listings/ch03-common-collections/no_listing_05_array_at_2/src/lib.cairo diff --git a/listings/ch03-common-collections/no_listing_05_array_span/Scarb.lock b/listings/ch03-common-collections/no_listing_05_array_span/Scarb.lock deleted file mode 100644 index 07294c3f0..000000000 --- a/listings/ch03-common-collections/no_listing_05_array_span/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_05_array_span" -version = "0.1.0" diff --git a/listings/ch03-common-collections/no_listing_04_array_with_enums/.gitignore b/listings/ch03-common-collections/no_listing_06_array_macro/.gitignore similarity index 100% rename from listings/ch03-common-collections/no_listing_04_array_with_enums/.gitignore rename to listings/ch03-common-collections/no_listing_06_array_macro/.gitignore diff --git a/listings/ch11-advanced-features/no_listing_02_array_macro/Scarb.toml b/listings/ch03-common-collections/no_listing_06_array_macro/Scarb.toml similarity index 100% rename from listings/ch11-advanced-features/no_listing_02_array_macro/Scarb.toml rename to listings/ch03-common-collections/no_listing_06_array_macro/Scarb.toml diff --git a/listings/ch11-advanced-features/no_listing_02_array_macro/src/lib.cairo b/listings/ch03-common-collections/no_listing_06_array_macro/src/lib.cairo similarity index 100% rename from listings/ch11-advanced-features/no_listing_02_array_macro/src/lib.cairo rename to listings/ch03-common-collections/no_listing_06_array_macro/src/lib.cairo diff --git a/listings/ch03-common-collections/no_listing_05_array_span/.gitignore b/listings/ch03-common-collections/no_listing_07_array_with_enums/.gitignore similarity index 100% rename from listings/ch03-common-collections/no_listing_05_array_span/.gitignore rename to listings/ch03-common-collections/no_listing_07_array_with_enums/.gitignore diff --git a/listings/ch03-common-collections/no_listing_04_array_with_enums/Scarb.toml b/listings/ch03-common-collections/no_listing_07_array_with_enums/Scarb.toml similarity index 100% rename from listings/ch03-common-collections/no_listing_04_array_with_enums/Scarb.toml rename to listings/ch03-common-collections/no_listing_07_array_with_enums/Scarb.toml diff --git a/listings/ch03-common-collections/no_listing_04_array_with_enums/src/lib.cairo b/listings/ch03-common-collections/no_listing_07_array_with_enums/src/lib.cairo similarity index 100% rename from listings/ch03-common-collections/no_listing_04_array_with_enums/src/lib.cairo rename to listings/ch03-common-collections/no_listing_07_array_with_enums/src/lib.cairo diff --git a/listings/ch03-common-collections/no_listing_07_intro/Scarb.lock b/listings/ch03-common-collections/no_listing_07_intro/Scarb.lock deleted file mode 100644 index 90ed47e5d..000000000 --- a/listings/ch03-common-collections/no_listing_07_intro/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_07_intro" -version = "0.1.0" diff --git a/listings/ch03-common-collections/no_listing_07_intro/.gitignore b/listings/ch03-common-collections/no_listing_08_array_span/.gitignore similarity index 100% rename from listings/ch03-common-collections/no_listing_07_intro/.gitignore rename to listings/ch03-common-collections/no_listing_08_array_span/.gitignore diff --git a/listings/ch03-common-collections/no_listing_05_array_span/Scarb.toml b/listings/ch03-common-collections/no_listing_08_array_span/Scarb.toml similarity index 100% rename from listings/ch03-common-collections/no_listing_05_array_span/Scarb.toml rename to listings/ch03-common-collections/no_listing_08_array_span/Scarb.toml diff --git a/listings/ch03-common-collections/no_listing_05_array_span/src/lib.cairo b/listings/ch03-common-collections/no_listing_08_array_span/src/lib.cairo similarity index 100% rename from listings/ch03-common-collections/no_listing_05_array_span/src/lib.cairo rename to listings/ch03-common-collections/no_listing_08_array_span/src/lib.cairo diff --git a/listings/ch03-common-collections/no_listing_08_intro_rewrite/Scarb.lock b/listings/ch03-common-collections/no_listing_08_intro_rewrite/Scarb.lock deleted file mode 100644 index 25065ae8b..000000000 --- a/listings/ch03-common-collections/no_listing_08_intro_rewrite/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_08_intro_rewrite" -version = "0.1.0" diff --git a/listings/ch03-common-collections/no_listing_09_entries/Scarb.lock b/listings/ch03-common-collections/no_listing_09_entries/Scarb.lock deleted file mode 100644 index cf529bb65..000000000 --- a/listings/ch03-common-collections/no_listing_09_entries/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_09_entries" -version = "0.1.0" diff --git a/listings/ch03-common-collections/no_listing_08_intro_rewrite/.gitignore b/listings/ch03-common-collections/no_listing_09_intro/.gitignore similarity index 100% rename from listings/ch03-common-collections/no_listing_08_intro_rewrite/.gitignore rename to listings/ch03-common-collections/no_listing_09_intro/.gitignore diff --git a/listings/ch03-common-collections/no_listing_07_intro/Scarb.toml b/listings/ch03-common-collections/no_listing_09_intro/Scarb.toml similarity index 100% rename from listings/ch03-common-collections/no_listing_07_intro/Scarb.toml rename to listings/ch03-common-collections/no_listing_09_intro/Scarb.toml diff --git a/listings/ch03-common-collections/no_listing_07_intro/src/lib.cairo b/listings/ch03-common-collections/no_listing_09_intro/src/lib.cairo similarity index 100% rename from listings/ch03-common-collections/no_listing_07_intro/src/lib.cairo rename to listings/ch03-common-collections/no_listing_09_intro/src/lib.cairo diff --git a/listings/ch03-common-collections/no_listing_10_custom_methods/Scarb.lock b/listings/ch03-common-collections/no_listing_10_custom_methods/Scarb.lock deleted file mode 100644 index 44585ce75..000000000 --- a/listings/ch03-common-collections/no_listing_10_custom_methods/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_10_custom_methods" -version = "0.1.0" diff --git a/listings/ch03-common-collections/no_listing_09_entries/.gitignore b/listings/ch03-common-collections/no_listing_10_intro_rewrite/.gitignore similarity index 100% rename from listings/ch03-common-collections/no_listing_09_entries/.gitignore rename to listings/ch03-common-collections/no_listing_10_intro_rewrite/.gitignore diff --git a/listings/ch03-common-collections/no_listing_08_intro_rewrite/Scarb.toml b/listings/ch03-common-collections/no_listing_10_intro_rewrite/Scarb.toml similarity index 100% rename from listings/ch03-common-collections/no_listing_08_intro_rewrite/Scarb.toml rename to listings/ch03-common-collections/no_listing_10_intro_rewrite/Scarb.toml diff --git a/listings/ch03-common-collections/no_listing_08_intro_rewrite/src/lib.cairo b/listings/ch03-common-collections/no_listing_10_intro_rewrite/src/lib.cairo similarity index 100% rename from listings/ch03-common-collections/no_listing_08_intro_rewrite/src/lib.cairo rename to listings/ch03-common-collections/no_listing_10_intro_rewrite/src/lib.cairo diff --git a/listings/ch03-common-collections/no_listing_11_dict_of_complex/Scarb.lock b/listings/ch03-common-collections/no_listing_11_dict_of_complex/Scarb.lock deleted file mode 100644 index d717544d3..000000000 --- a/listings/ch03-common-collections/no_listing_11_dict_of_complex/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_11_dict_of_complex" -version = "0.1.0" diff --git a/listings/ch03-common-collections/no_listing_10_custom_methods/.gitignore b/listings/ch03-common-collections/no_listing_11_entries/.gitignore similarity index 100% rename from listings/ch03-common-collections/no_listing_10_custom_methods/.gitignore rename to listings/ch03-common-collections/no_listing_11_entries/.gitignore diff --git a/listings/ch03-common-collections/no_listing_09_entries/Scarb.toml b/listings/ch03-common-collections/no_listing_11_entries/Scarb.toml similarity index 100% rename from listings/ch03-common-collections/no_listing_09_entries/Scarb.toml rename to listings/ch03-common-collections/no_listing_11_entries/Scarb.toml diff --git a/listings/ch03-common-collections/no_listing_09_entries/src/lib.cairo b/listings/ch03-common-collections/no_listing_11_entries/src/lib.cairo similarity index 100% rename from listings/ch03-common-collections/no_listing_09_entries/src/lib.cairo rename to listings/ch03-common-collections/no_listing_11_entries/src/lib.cairo diff --git a/listings/ch03-common-collections/no_listing_11_dict_of_complex/.gitignore b/listings/ch03-common-collections/no_listing_12_custom_methods/.gitignore similarity index 100% rename from listings/ch03-common-collections/no_listing_11_dict_of_complex/.gitignore rename to listings/ch03-common-collections/no_listing_12_custom_methods/.gitignore diff --git a/listings/ch03-common-collections/no_listing_10_custom_methods/Scarb.toml b/listings/ch03-common-collections/no_listing_12_custom_methods/Scarb.toml similarity index 100% rename from listings/ch03-common-collections/no_listing_10_custom_methods/Scarb.toml rename to listings/ch03-common-collections/no_listing_12_custom_methods/Scarb.toml diff --git a/listings/ch03-common-collections/no_listing_10_custom_methods/src/lib.cairo b/listings/ch03-common-collections/no_listing_12_custom_methods/src/lib.cairo similarity index 100% rename from listings/ch03-common-collections/no_listing_10_custom_methods/src/lib.cairo rename to listings/ch03-common-collections/no_listing_12_custom_methods/src/lib.cairo diff --git a/listings/ch04-understanding-ownership/listing_04_01/.gitignore b/listings/ch03-common-collections/no_listing_13_dict_of_complex/.gitignore similarity index 100% rename from listings/ch04-understanding-ownership/listing_04_01/.gitignore rename to listings/ch03-common-collections/no_listing_13_dict_of_complex/.gitignore diff --git a/listings/ch03-common-collections/no_listing_11_dict_of_complex/Scarb.toml b/listings/ch03-common-collections/no_listing_13_dict_of_complex/Scarb.toml similarity index 100% rename from listings/ch03-common-collections/no_listing_11_dict_of_complex/Scarb.toml rename to listings/ch03-common-collections/no_listing_13_dict_of_complex/Scarb.toml diff --git a/listings/ch03-common-collections/no_listing_11_dict_of_complex/src/lib.cairo b/listings/ch03-common-collections/no_listing_13_dict_of_complex/src/lib.cairo similarity index 99% rename from listings/ch03-common-collections/no_listing_11_dict_of_complex/src/lib.cairo rename to listings/ch03-common-collections/no_listing_13_dict_of_complex/src/lib.cairo index 632ca2535..5628abe01 100644 --- a/listings/ch03-common-collections/no_listing_11_dict_of_complex/src/lib.cairo +++ b/listings/ch03-common-collections/no_listing_13_dict_of_complex/src/lib.cairo @@ -1,5 +1,4 @@ // ANCHOR: all - // ANCHOR: imports use core::nullable::{NullableTrait, match_nullable, FromNullableResult}; // ANCHOR_END: imports diff --git a/listings/ch04-understanding-ownership/listing_04_02/.gitignore b/listings/ch04-understanding-ownership/listing_01_variable_and_scope/.gitignore similarity index 100% rename from listings/ch04-understanding-ownership/listing_04_02/.gitignore rename to listings/ch04-understanding-ownership/listing_01_variable_and_scope/.gitignore diff --git a/listings/ch04-understanding-ownership/listing_04_01/Scarb.toml b/listings/ch04-understanding-ownership/listing_01_variable_and_scope/Scarb.toml similarity index 100% rename from listings/ch04-understanding-ownership/listing_04_01/Scarb.toml rename to listings/ch04-understanding-ownership/listing_01_variable_and_scope/Scarb.toml diff --git a/listings/ch04-understanding-ownership/listing_04_01/src/lib.cairo b/listings/ch04-understanding-ownership/listing_01_variable_and_scope/src/lib.cairo similarity index 100% rename from listings/ch04-understanding-ownership/listing_04_01/src/lib.cairo rename to listings/ch04-understanding-ownership/listing_01_variable_and_scope/src/lib.cairo diff --git a/listings/ch04-understanding-ownership/listing_04_03/.gitignore b/listings/ch04-understanding-ownership/listing_02_moving_return_values/.gitignore similarity index 100% rename from listings/ch04-understanding-ownership/listing_04_03/.gitignore rename to listings/ch04-understanding-ownership/listing_02_moving_return_values/.gitignore diff --git a/listings/ch04-understanding-ownership/listing_04_02/Scarb.toml b/listings/ch04-understanding-ownership/listing_02_moving_return_values/Scarb.toml similarity index 100% rename from listings/ch04-understanding-ownership/listing_04_02/Scarb.toml rename to listings/ch04-understanding-ownership/listing_02_moving_return_values/Scarb.toml diff --git a/listings/ch04-understanding-ownership/listing_04_02/src/lib.cairo b/listings/ch04-understanding-ownership/listing_02_moving_return_values/src/lib.cairo similarity index 100% rename from listings/ch04-understanding-ownership/listing_04_02/src/lib.cairo rename to listings/ch04-understanding-ownership/listing_02_moving_return_values/src/lib.cairo diff --git a/listings/ch04-understanding-ownership/listing_04_04/.gitignore b/listings/ch04-understanding-ownership/listing_03_returning_many_values/.gitignore similarity index 100% rename from listings/ch04-understanding-ownership/listing_04_04/.gitignore rename to listings/ch04-understanding-ownership/listing_03_returning_many_values/.gitignore diff --git a/listings/ch04-understanding-ownership/listing_04_03/Scarb.toml b/listings/ch04-understanding-ownership/listing_03_returning_many_values/Scarb.toml similarity index 100% rename from listings/ch04-understanding-ownership/listing_04_03/Scarb.toml rename to listings/ch04-understanding-ownership/listing_03_returning_many_values/Scarb.toml diff --git a/listings/ch04-understanding-ownership/listing_04_03/src/lib.cairo b/listings/ch04-understanding-ownership/listing_03_returning_many_values/src/lib.cairo similarity index 100% rename from listings/ch04-understanding-ownership/listing_04_03/src/lib.cairo rename to listings/ch04-understanding-ownership/listing_03_returning_many_values/src/lib.cairo diff --git a/listings/ch04-understanding-ownership/listing_04_01/Scarb.lock b/listings/ch04-understanding-ownership/listing_04_01/Scarb.lock deleted file mode 100644 index 845d6e67e..000000000 --- a/listings/ch04-understanding-ownership/listing_04_01/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "listing_04_01" -version = "0.1.0" diff --git a/listings/ch04-understanding-ownership/listing_04_02/Scarb.lock b/listings/ch04-understanding-ownership/listing_04_02/Scarb.lock deleted file mode 100644 index daa1c6a45..000000000 --- a/listings/ch04-understanding-ownership/listing_04_02/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "listing_04_02" -version = "0.1.0" diff --git a/listings/ch04-understanding-ownership/listing_04_03/Scarb.lock b/listings/ch04-understanding-ownership/listing_04_03/Scarb.lock deleted file mode 100644 index e65bbd616..000000000 --- a/listings/ch04-understanding-ownership/listing_04_03/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "listing_04_03" -version = "0.1.0" diff --git a/listings/ch04-understanding-ownership/listing_04_05/Scarb.lock b/listings/ch04-understanding-ownership/listing_04_05/Scarb.lock deleted file mode 100644 index 471fe41b1..000000000 --- a/listings/ch04-understanding-ownership/listing_04_05/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "listing_04_05" -version = "0.1.0" diff --git a/listings/ch04-understanding-ownership/listing_04_05/.gitignore b/listings/ch04-understanding-ownership/listing_04_attempt_modifying_snapshot/.gitignore similarity index 100% rename from listings/ch04-understanding-ownership/listing_04_05/.gitignore rename to listings/ch04-understanding-ownership/listing_04_attempt_modifying_snapshot/.gitignore diff --git a/listings/ch04-understanding-ownership/listing_04_04/Scarb.toml b/listings/ch04-understanding-ownership/listing_04_attempt_modifying_snapshot/Scarb.toml similarity index 100% rename from listings/ch04-understanding-ownership/listing_04_04/Scarb.toml rename to listings/ch04-understanding-ownership/listing_04_attempt_modifying_snapshot/Scarb.toml diff --git a/listings/ch04-understanding-ownership/listing_04_04/src/lib.cairo b/listings/ch04-understanding-ownership/listing_04_attempt_modifying_snapshot/src/lib.cairo similarity index 100% rename from listings/ch04-understanding-ownership/listing_04_04/src/lib.cairo rename to listings/ch04-understanding-ownership/listing_04_attempt_modifying_snapshot/src/lib.cairo diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_01_user_struct/.gitignore b/listings/ch04-understanding-ownership/listing_05_mutable_reference/.gitignore similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_01_user_struct/.gitignore rename to listings/ch04-understanding-ownership/listing_05_mutable_reference/.gitignore diff --git a/listings/ch04-understanding-ownership/listing_04_05/Scarb.toml b/listings/ch04-understanding-ownership/listing_05_mutable_reference/Scarb.toml similarity index 100% rename from listings/ch04-understanding-ownership/listing_04_05/Scarb.toml rename to listings/ch04-understanding-ownership/listing_05_mutable_reference/Scarb.toml diff --git a/listings/ch04-understanding-ownership/listing_04_05/src/lib.cairo b/listings/ch04-understanding-ownership/listing_05_mutable_reference/src/lib.cairo similarity index 100% rename from listings/ch04-understanding-ownership/listing_04_05/src/lib.cairo rename to listings/ch04-understanding-ownership/listing_05_mutable_reference/src/lib.cairo diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_02_mut_struct/.gitignore b/listings/ch05-using-structs-to-structure-related-data/listing_01_user_struct/.gitignore similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_02_mut_struct/.gitignore rename to listings/ch05-using-structs-to-structure-related-data/listing_01_user_struct/.gitignore diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_01_user_struct/Scarb.toml b/listings/ch05-using-structs-to-structure-related-data/listing_01_user_struct/Scarb.toml similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_01_user_struct/Scarb.toml rename to listings/ch05-using-structs-to-structure-related-data/listing_01_user_struct/Scarb.toml diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_01_user_struct/src/lib.cairo b/listings/ch05-using-structs-to-structure-related-data/listing_01_user_struct/src/lib.cairo similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_01_user_struct/src/lib.cairo rename to listings/ch05-using-structs-to-structure-related-data/listing_01_user_struct/src/lib.cairo diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_06_no_struct/.gitignore b/listings/ch05-using-structs-to-structure-related-data/listing_02_mut_struct/.gitignore similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_06_no_struct/.gitignore rename to listings/ch05-using-structs-to-structure-related-data/listing_02_mut_struct/.gitignore diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_02_mut_struct/Scarb.toml b/listings/ch05-using-structs-to-structure-related-data/listing_02_mut_struct/Scarb.toml similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_02_mut_struct/Scarb.toml rename to listings/ch05-using-structs-to-structure-related-data/listing_02_mut_struct/Scarb.toml diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_02_mut_struct/src/lib.cairo b/listings/ch05-using-structs-to-structure-related-data/listing_02_mut_struct/src/lib.cairo similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_02_mut_struct/src/lib.cairo rename to listings/ch05-using-structs-to-structure-related-data/listing_02_mut_struct/src/lib.cairo diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_07_w_tuples/.gitignore b/listings/ch05-using-structs-to-structure-related-data/listing_03_no_struct/.gitignore similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_07_w_tuples/.gitignore rename to listings/ch05-using-structs-to-structure-related-data/listing_03_no_struct/.gitignore diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_06_no_struct/Scarb.toml b/listings/ch05-using-structs-to-structure-related-data/listing_03_no_struct/Scarb.toml similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_06_no_struct/Scarb.toml rename to listings/ch05-using-structs-to-structure-related-data/listing_03_no_struct/Scarb.toml diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_06_no_struct/src/lib.cairo b/listings/ch05-using-structs-to-structure-related-data/listing_03_no_struct/src/lib.cairo similarity index 99% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_06_no_struct/src/lib.cairo rename to listings/ch05-using-structs-to-structure-related-data/listing_03_no_struct/src/lib.cairo index 008fd013e..bbbdd8820 100644 --- a/listings/ch05-using-structs-to-structure-related-data/listing_05_06_no_struct/src/lib.cairo +++ b/listings/ch05-using-structs-to-structure-related-data/listing_03_no_struct/src/lib.cairo @@ -1,5 +1,4 @@ //ANCHOR:all - fn main() { let width1 = 30; let height1 = 10; diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_08_w_structs/.gitignore b/listings/ch05-using-structs-to-structure-related-data/listing_04_w_tuples/.gitignore similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_08_w_structs/.gitignore rename to listings/ch05-using-structs-to-structure-related-data/listing_04_w_tuples/.gitignore diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_07_w_tuples/Scarb.toml b/listings/ch05-using-structs-to-structure-related-data/listing_04_w_tuples/Scarb.toml similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_07_w_tuples/Scarb.toml rename to listings/ch05-using-structs-to-structure-related-data/listing_04_w_tuples/Scarb.toml diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_07_w_tuples/src/lib.cairo b/listings/ch05-using-structs-to-structure-related-data/listing_04_w_tuples/src/lib.cairo similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_07_w_tuples/src/lib.cairo rename to listings/ch05-using-structs-to-structure-related-data/listing_04_w_tuples/src/lib.cairo diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_10_define_methods/.gitignore b/listings/ch05-using-structs-to-structure-related-data/listing_05_w_structs/.gitignore similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_10_define_methods/.gitignore rename to listings/ch05-using-structs-to-structure-related-data/listing_05_w_structs/.gitignore diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_08_w_structs/Scarb.toml b/listings/ch05-using-structs-to-structure-related-data/listing_05_w_structs/Scarb.toml similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_08_w_structs/Scarb.toml rename to listings/ch05-using-structs-to-structure-related-data/listing_05_w_structs/Scarb.toml diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_08_w_structs/src/lib.cairo b/listings/ch05-using-structs-to-structure-related-data/listing_05_w_structs/src/lib.cairo similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_08_w_structs/src/lib.cairo rename to listings/ch05-using-structs-to-structure-related-data/listing_05_w_structs/src/lib.cairo diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_11_references/.gitignore b/listings/ch05-using-structs-to-structure-related-data/no_listing_01_define_methods/.gitignore similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_11_references/.gitignore rename to listings/ch05-using-structs-to-structure-related-data/no_listing_01_define_methods/.gitignore diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_10_define_methods/Scarb.toml b/listings/ch05-using-structs-to-structure-related-data/no_listing_01_define_methods/Scarb.toml similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_10_define_methods/Scarb.toml rename to listings/ch05-using-structs-to-structure-related-data/no_listing_01_define_methods/Scarb.toml diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_10_define_methods/src/lib.cairo b/listings/ch05-using-structs-to-structure-related-data/no_listing_01_define_methods/src/lib.cairo similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_10_define_methods/src/lib.cairo rename to listings/ch05-using-structs-to-structure-related-data/no_listing_01_define_methods/src/lib.cairo diff --git a/listings/ch05-using-structs-to-structure-related-data/no_listing_01_implementation_functions/Scarb.lock b/listings/ch05-using-structs-to-structure-related-data/no_listing_01_implementation_functions/Scarb.lock deleted file mode 100644 index 5f56ba4bc..000000000 --- a/listings/ch05-using-structs-to-structure-related-data/no_listing_01_implementation_functions/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_01_implementation_functions" -version = "0.1.0" diff --git a/listings/ch05-using-structs-to-structure-related-data/no_listing_01_implementation_functions/Scarb.toml b/listings/ch05-using-structs-to-structure-related-data/no_listing_01_implementation_functions/Scarb.toml deleted file mode 100644 index 6ede9e4cb..000000000 --- a/listings/ch05-using-structs-to-structure-related-data/no_listing_01_implementation_functions/Scarb.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "no_listing_01_implementation_functions" -version = "0.1.0" -edition = "2023_11" - -# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest - -[dependencies] -# foo = { path = "vendor/foo" } diff --git a/listings/ch05-using-structs-to-structure-related-data/no_listing_01_implementation_functions/src/lib.cairo b/listings/ch05-using-structs-to-structure-related-data/no_listing_01_implementation_functions/src/lib.cairo deleted file mode 100644 index ae36b7418..000000000 --- a/listings/ch05-using-structs-to-structure-related-data/no_listing_01_implementation_functions/src/lib.cairo +++ /dev/null @@ -1,19 +0,0 @@ -#[derive(Copy, Drop)] -struct Rectangle { - width: u64, - height: u64, -} - -// ANCHOR: here -trait RectangleTrait { - fn square(size: u64) -> Rectangle; -} - -impl RectangleImpl of RectangleTrait { - fn square(size: u64) -> Rectangle { - Rectangle { width: size, height: size } - } -} -// ANCHOR_END: here - - diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_12_some_params/.gitignore b/listings/ch05-using-structs-to-structure-related-data/no_listing_02_gen_trait/.gitignore similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_12_some_params/.gitignore rename to listings/ch05-using-structs-to-structure-related-data/no_listing_02_gen_trait/.gitignore diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_12_some_params/Scarb.toml b/listings/ch05-using-structs-to-structure-related-data/no_listing_02_gen_trait/Scarb.toml similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_12_some_params/Scarb.toml rename to listings/ch05-using-structs-to-structure-related-data/no_listing_02_gen_trait/Scarb.toml diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_15_gen_trait/src/lib.cairo b/listings/ch05-using-structs-to-structure-related-data/no_listing_02_gen_trait/src/lib.cairo similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_15_gen_trait/src/lib.cairo rename to listings/ch05-using-structs-to-structure-related-data/no_listing_02_gen_trait/src/lib.cairo diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_13_class_methods/.gitignore b/listings/ch05-using-structs-to-structure-related-data/no_listing_03_references/.gitignore similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_13_class_methods/.gitignore rename to listings/ch05-using-structs-to-structure-related-data/no_listing_03_references/.gitignore diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_11_references/Scarb.toml b/listings/ch05-using-structs-to-structure-related-data/no_listing_03_references/Scarb.toml similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_11_references/Scarb.toml rename to listings/ch05-using-structs-to-structure-related-data/no_listing_03_references/Scarb.toml diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_11_references/src/lib.cairo b/listings/ch05-using-structs-to-structure-related-data/no_listing_03_references/src/lib.cairo similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_11_references/src/lib.cairo rename to listings/ch05-using-structs-to-structure-related-data/no_listing_03_references/src/lib.cairo diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_14_multiple_traits/.gitignore b/listings/ch05-using-structs-to-structure-related-data/no_listing_04_some_params/.gitignore similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_14_multiple_traits/.gitignore rename to listings/ch05-using-structs-to-structure-related-data/no_listing_04_some_params/.gitignore diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_13_class_methods/Scarb.toml b/listings/ch05-using-structs-to-structure-related-data/no_listing_04_some_params/Scarb.toml similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_13_class_methods/Scarb.toml rename to listings/ch05-using-structs-to-structure-related-data/no_listing_04_some_params/Scarb.toml diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_12_some_params/src/lib.cairo b/listings/ch05-using-structs-to-structure-related-data/no_listing_04_some_params/src/lib.cairo similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_12_some_params/src/lib.cairo rename to listings/ch05-using-structs-to-structure-related-data/no_listing_04_some_params/src/lib.cairo diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_15_gen_trait/.gitignore b/listings/ch05-using-structs-to-structure-related-data/no_listing_05_class_methods/.gitignore similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_15_gen_trait/.gitignore rename to listings/ch05-using-structs-to-structure-related-data/no_listing_05_class_methods/.gitignore diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_15_gen_trait/Scarb.toml b/listings/ch05-using-structs-to-structure-related-data/no_listing_05_class_methods/Scarb.toml similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_15_gen_trait/Scarb.toml rename to listings/ch05-using-structs-to-structure-related-data/no_listing_05_class_methods/Scarb.toml diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_13_class_methods/src/lib.cairo b/listings/ch05-using-structs-to-structure-related-data/no_listing_05_class_methods/src/lib.cairo similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_13_class_methods/src/lib.cairo rename to listings/ch05-using-structs-to-structure-related-data/no_listing_05_class_methods/src/lib.cairo diff --git a/listings/ch05-using-structs-to-structure-related-data/no_listing_01_implementation_functions/.gitignore b/listings/ch05-using-structs-to-structure-related-data/no_listing_06_multiple_traits/.gitignore similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/no_listing_01_implementation_functions/.gitignore rename to listings/ch05-using-structs-to-structure-related-data/no_listing_06_multiple_traits/.gitignore diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_14_multiple_traits/Scarb.toml b/listings/ch05-using-structs-to-structure-related-data/no_listing_06_multiple_traits/Scarb.toml similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_14_multiple_traits/Scarb.toml rename to listings/ch05-using-structs-to-structure-related-data/no_listing_06_multiple_traits/Scarb.toml diff --git a/listings/ch05-using-structs-to-structure-related-data/listing_05_14_multiple_traits/src/lib.cairo b/listings/ch05-using-structs-to-structure-related-data/no_listing_06_multiple_traits/src/lib.cairo similarity index 100% rename from listings/ch05-using-structs-to-structure-related-data/listing_05_14_multiple_traits/src/lib.cairo rename to listings/ch05-using-structs-to-structure-related-data/no_listing_06_multiple_traits/src/lib.cairo diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_02_enum_message/Scarb.lock b/listings/ch06-enums-and-pattern-matching/no_listing_02_enum_message/Scarb.lock deleted file mode 100644 index 2978296a6..000000000 --- a/listings/ch06-enums-and-pattern-matching/no_listing_02_enum_message/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_02_enum_message" -version = "0.1.0" diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_01_enum_with_values_example/.gitignore b/listings/ch06-enums-and-pattern-matching/no_listing_02_enum_with_values_example/.gitignore similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_01_enum_with_values_example/.gitignore rename to listings/ch06-enums-and-pattern-matching/no_listing_02_enum_with_values_example/.gitignore diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_01_enum_with_values_example/Scarb.toml b/listings/ch06-enums-and-pattern-matching/no_listing_02_enum_with_values_example/Scarb.toml similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_01_enum_with_values_example/Scarb.toml rename to listings/ch06-enums-and-pattern-matching/no_listing_02_enum_with_values_example/Scarb.toml diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_01_enum_with_values_example/src/lib.cairo b/listings/ch06-enums-and-pattern-matching/no_listing_02_enum_with_values_example/src/lib.cairo similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_01_enum_with_values_example/src/lib.cairo rename to listings/ch06-enums-and-pattern-matching/no_listing_02_enum_with_values_example/src/lib.cairo diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_02_enum_message/.gitignore b/listings/ch06-enums-and-pattern-matching/no_listing_03_enum_message/.gitignore similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_02_enum_message/.gitignore rename to listings/ch06-enums-and-pattern-matching/no_listing_03_enum_message/.gitignore diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_02_enum_message/Scarb.toml b/listings/ch06-enums-and-pattern-matching/no_listing_03_enum_message/Scarb.toml similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_02_enum_message/Scarb.toml rename to listings/ch06-enums-and-pattern-matching/no_listing_03_enum_message/Scarb.toml diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_02_enum_message/src/lib.cairo b/listings/ch06-enums-and-pattern-matching/no_listing_03_enum_message/src/lib.cairo similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_02_enum_message/src/lib.cairo rename to listings/ch06-enums-and-pattern-matching/no_listing_03_enum_message/src/lib.cairo diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_03_enum_option/Scarb.lock b/listings/ch06-enums-and-pattern-matching/no_listing_03_enum_option/Scarb.lock deleted file mode 100644 index 7797606dc..000000000 --- a/listings/ch06-enums-and-pattern-matching/no_listing_03_enum_option/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_03_enum_option" -version = "0.1.0" diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_03_enum_option/.gitignore b/listings/ch06-enums-and-pattern-matching/no_listing_04_enum_option/.gitignore similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_03_enum_option/.gitignore rename to listings/ch06-enums-and-pattern-matching/no_listing_04_enum_option/.gitignore diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_03_enum_option/Scarb.toml b/listings/ch06-enums-and-pattern-matching/no_listing_04_enum_option/Scarb.toml similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_03_enum_option/Scarb.toml rename to listings/ch06-enums-and-pattern-matching/no_listing_04_enum_option/Scarb.toml diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_03_enum_option/src/lib.cairo b/listings/ch06-enums-and-pattern-matching/no_listing_04_enum_option/src/lib.cairo similarity index 56% rename from listings/ch06-enums-and-pattern-matching/no_listing_03_enum_option/src/lib.cairo rename to listings/ch06-enums-and-pattern-matching/no_listing_04_enum_option/src/lib.cairo index 7a67efd7d..fe5e5612e 100644 --- a/listings/ch06-enums-and-pattern-matching/no_listing_03_enum_option/src/lib.cairo +++ b/listings/ch06-enums-and-pattern-matching/no_listing_04_enum_option/src/lib.cairo @@ -6,19 +6,21 @@ fn find_value_recursive(mut arr: Span, value: felt252, index: usize) -> Option::None => { return Option::None; }, }; - return find_value_recursive(arr, value, index + 1); + find_value_recursive(arr, value, index + 1) } fn find_value_iterative(mut arr: Span, value: felt252) -> Option { + let mut result = Option::None; let mut index = 0; - loop { - match arr.pop_front() { - Option::Some(array_value) => if (*array_value == value) { - break Option::Some(index); - }, - Option::None => { break Option::None; }, - } - index += 1; - } + while let Option::Some(array_value) = arr + .pop_front() { + if (*array_value == value) { + result = Option::Some(index); + }; + + index += 1; + }; + + result } diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_04_match_example/Scarb.lock b/listings/ch06-enums-and-pattern-matching/no_listing_04_match_example/Scarb.lock deleted file mode 100644 index 168527b06..000000000 --- a/listings/ch06-enums-and-pattern-matching/no_listing_04_match_example/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_04_match_example" -version = "0.1.0" diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_05_match_arms_block/Scarb.lock b/listings/ch06-enums-and-pattern-matching/no_listing_05_match_arms_block/Scarb.lock deleted file mode 100644 index ba86a08b2..000000000 --- a/listings/ch06-enums-and-pattern-matching/no_listing_05_match_arms_block/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_05_match_arms_block" -version = "0.1.0" diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_04_match_example/.gitignore b/listings/ch06-enums-and-pattern-matching/no_listing_05_match_example/.gitignore similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_04_match_example/.gitignore rename to listings/ch06-enums-and-pattern-matching/no_listing_05_match_example/.gitignore diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_04_match_example/Scarb.toml b/listings/ch06-enums-and-pattern-matching/no_listing_05_match_example/Scarb.toml similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_04_match_example/Scarb.toml rename to listings/ch06-enums-and-pattern-matching/no_listing_05_match_example/Scarb.toml diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_04_match_example/src/lib.cairo b/listings/ch06-enums-and-pattern-matching/no_listing_05_match_example/src/lib.cairo similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_04_match_example/src/lib.cairo rename to listings/ch06-enums-and-pattern-matching/no_listing_05_match_example/src/lib.cairo diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_05_match_arms_block/.gitignore b/listings/ch06-enums-and-pattern-matching/no_listing_06_match_arms_block/.gitignore similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_05_match_arms_block/.gitignore rename to listings/ch06-enums-and-pattern-matching/no_listing_06_match_arms_block/.gitignore diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_05_match_arms_block/Scarb.toml b/listings/ch06-enums-and-pattern-matching/no_listing_06_match_arms_block/Scarb.toml similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_05_match_arms_block/Scarb.toml rename to listings/ch06-enums-and-pattern-matching/no_listing_06_match_arms_block/Scarb.toml diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_05_match_arms_block/src/lib.cairo b/listings/ch06-enums-and-pattern-matching/no_listing_06_match_arms_block/src/lib.cairo similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_05_match_arms_block/src/lib.cairo rename to listings/ch06-enums-and-pattern-matching/no_listing_06_match_arms_block/src/lib.cairo diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_06_match_pattern_bind/Scarb.lock b/listings/ch06-enums-and-pattern-matching/no_listing_06_match_pattern_bind/Scarb.lock deleted file mode 100644 index 2ce16dd9f..000000000 --- a/listings/ch06-enums-and-pattern-matching/no_listing_06_match_pattern_bind/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_06_match_pattern_bind" -version = "0.1.0" diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_07_match_option/Scarb.lock b/listings/ch06-enums-and-pattern-matching/no_listing_07_match_option/Scarb.lock deleted file mode 100644 index e51576c77..000000000 --- a/listings/ch06-enums-and-pattern-matching/no_listing_07_match_option/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_07_match_option" -version = "0.1.0" diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_06_match_pattern_bind/.gitignore b/listings/ch06-enums-and-pattern-matching/no_listing_07_match_pattern_bind/.gitignore similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_06_match_pattern_bind/.gitignore rename to listings/ch06-enums-and-pattern-matching/no_listing_07_match_pattern_bind/.gitignore diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_06_match_pattern_bind/Scarb.toml b/listings/ch06-enums-and-pattern-matching/no_listing_07_match_pattern_bind/Scarb.toml similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_06_match_pattern_bind/Scarb.toml rename to listings/ch06-enums-and-pattern-matching/no_listing_07_match_pattern_bind/Scarb.toml diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_06_match_pattern_bind/src/lib.cairo b/listings/ch06-enums-and-pattern-matching/no_listing_07_match_pattern_bind/src/lib.cairo similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_06_match_pattern_bind/src/lib.cairo rename to listings/ch06-enums-and-pattern-matching/no_listing_07_match_pattern_bind/src/lib.cairo diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_07_match_option/.gitignore b/listings/ch06-enums-and-pattern-matching/no_listing_08_match_option/.gitignore similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_07_match_option/.gitignore rename to listings/ch06-enums-and-pattern-matching/no_listing_08_match_option/.gitignore diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_07_match_option/Scarb.toml b/listings/ch06-enums-and-pattern-matching/no_listing_08_match_option/Scarb.toml similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_07_match_option/Scarb.toml rename to listings/ch06-enums-and-pattern-matching/no_listing_08_match_option/Scarb.toml diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_07_match_option/src/lib.cairo b/listings/ch06-enums-and-pattern-matching/no_listing_08_match_option/src/lib.cairo similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_07_match_option/src/lib.cairo rename to listings/ch06-enums-and-pattern-matching/no_listing_08_match_option/src/lib.cairo diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_08_missing_match_arm/Scarb.lock b/listings/ch06-enums-and-pattern-matching/no_listing_08_missing_match_arm/Scarb.lock deleted file mode 100644 index c69411114..000000000 --- a/listings/ch06-enums-and-pattern-matching/no_listing_08_missing_match_arm/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_08_missing_match_arm" -version = "0.1.0" diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_09_match_catch_all/Scarb.lock b/listings/ch06-enums-and-pattern-matching/no_listing_09_match_catch_all/Scarb.lock deleted file mode 100644 index 79c492259..000000000 --- a/listings/ch06-enums-and-pattern-matching/no_listing_09_match_catch_all/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_09_match_catch_all" -version = "0.1.0" diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_08_missing_match_arm/.gitignore b/listings/ch06-enums-and-pattern-matching/no_listing_09_missing_match_arm/.gitignore similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_08_missing_match_arm/.gitignore rename to listings/ch06-enums-and-pattern-matching/no_listing_09_missing_match_arm/.gitignore diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_08_missing_match_arm/Scarb.toml b/listings/ch06-enums-and-pattern-matching/no_listing_09_missing_match_arm/Scarb.toml similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_08_missing_match_arm/Scarb.toml rename to listings/ch06-enums-and-pattern-matching/no_listing_09_missing_match_arm/Scarb.toml diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_08_missing_match_arm/src/lib.cairo b/listings/ch06-enums-and-pattern-matching/no_listing_09_missing_match_arm/src/lib.cairo similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_08_missing_match_arm/src/lib.cairo rename to listings/ch06-enums-and-pattern-matching/no_listing_09_missing_match_arm/src/lib.cairo diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_09_match_catch_all/.gitignore b/listings/ch06-enums-and-pattern-matching/no_listing_10_match_catch_all/.gitignore similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_09_match_catch_all/.gitignore rename to listings/ch06-enums-and-pattern-matching/no_listing_10_match_catch_all/.gitignore diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_09_match_catch_all/Scarb.toml b/listings/ch06-enums-and-pattern-matching/no_listing_10_match_catch_all/Scarb.toml similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_09_match_catch_all/Scarb.toml rename to listings/ch06-enums-and-pattern-matching/no_listing_10_match_catch_all/Scarb.toml diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_09_match_catch_all/src/lib.cairo b/listings/ch06-enums-and-pattern-matching/no_listing_10_match_catch_all/src/lib.cairo similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_09_match_catch_all/src/lib.cairo rename to listings/ch06-enums-and-pattern-matching/no_listing_10_match_catch_all/src/lib.cairo diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_10_match_or/Scarb.lock b/listings/ch06-enums-and-pattern-matching/no_listing_10_match_or/Scarb.lock deleted file mode 100644 index eec70760b..000000000 --- a/listings/ch06-enums-and-pattern-matching/no_listing_10_match_or/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_10_match_or" -version = "0.1.0" diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_10_match_or/.gitignore b/listings/ch06-enums-and-pattern-matching/no_listing_11_match_or/.gitignore similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_10_match_or/.gitignore rename to listings/ch06-enums-and-pattern-matching/no_listing_11_match_or/.gitignore diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_10_match_or/Scarb.toml b/listings/ch06-enums-and-pattern-matching/no_listing_11_match_or/Scarb.toml similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_10_match_or/Scarb.toml rename to listings/ch06-enums-and-pattern-matching/no_listing_11_match_or/Scarb.toml diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_10_match_or/src/lib.cairo b/listings/ch06-enums-and-pattern-matching/no_listing_11_match_or/src/lib.cairo similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_10_match_or/src/lib.cairo rename to listings/ch06-enums-and-pattern-matching/no_listing_11_match_or/src/lib.cairo diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_11_match_tuple/Scarb.lock b/listings/ch06-enums-and-pattern-matching/no_listing_11_match_tuple/Scarb.lock deleted file mode 100644 index 62eac44be..000000000 --- a/listings/ch06-enums-and-pattern-matching/no_listing_11_match_tuple/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_11_match_tuple" -version = "0.1.0" diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_12_match_integers/Scarb.lock b/listings/ch06-enums-and-pattern-matching/no_listing_12_match_integers/Scarb.lock deleted file mode 100644 index b7006e9d9..000000000 --- a/listings/ch06-enums-and-pattern-matching/no_listing_12_match_integers/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_12_match_integers" -version = "0.1.0" diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_11_match_tuple/.gitignore b/listings/ch06-enums-and-pattern-matching/no_listing_12_match_tuple/.gitignore similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_11_match_tuple/.gitignore rename to listings/ch06-enums-and-pattern-matching/no_listing_12_match_tuple/.gitignore diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_11_match_tuple/Scarb.toml b/listings/ch06-enums-and-pattern-matching/no_listing_12_match_tuple/Scarb.toml similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_11_match_tuple/Scarb.toml rename to listings/ch06-enums-and-pattern-matching/no_listing_12_match_tuple/Scarb.toml diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_11_match_tuple/src/lib.cairo b/listings/ch06-enums-and-pattern-matching/no_listing_12_match_tuple/src/lib.cairo similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_11_match_tuple/src/lib.cairo rename to listings/ch06-enums-and-pattern-matching/no_listing_12_match_tuple/src/lib.cairo diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_12_match_integers/.gitignore b/listings/ch06-enums-and-pattern-matching/no_listing_13_match_integers/.gitignore similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_12_match_integers/.gitignore rename to listings/ch06-enums-and-pattern-matching/no_listing_13_match_integers/.gitignore diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_12_match_integers/Scarb.toml b/listings/ch06-enums-and-pattern-matching/no_listing_13_match_integers/Scarb.toml similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_12_match_integers/Scarb.toml rename to listings/ch06-enums-and-pattern-matching/no_listing_13_match_integers/Scarb.toml diff --git a/listings/ch06-enums-and-pattern-matching/no_listing_12_match_integers/src/lib.cairo b/listings/ch06-enums-and-pattern-matching/no_listing_13_match_integers/src/lib.cairo similarity index 100% rename from listings/ch06-enums-and-pattern-matching/no_listing_12_match_integers/src/lib.cairo rename to listings/ch06-enums-and-pattern-matching/no_listing_13_match_integers/src/lib.cairo diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_01/.gitignore b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_01_basic_nested_modules/.gitignore similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_01/.gitignore rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_01_basic_nested_modules/.gitignore diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_01/Scarb.toml b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_01_basic_nested_modules/Scarb.toml similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_01/Scarb.toml rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_01_basic_nested_modules/Scarb.toml diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_01/src/lib.cairo b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_01_basic_nested_modules/src/lib.cairo similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_01/src/lib.cairo rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_01_basic_nested_modules/src/lib.cairo diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_02/.gitignore b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_02_paths/.gitignore similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_02/.gitignore rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_02_paths/.gitignore diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_02/Scarb.toml b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_02_paths/Scarb.toml similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_02/Scarb.toml rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_02_paths/Scarb.toml diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_02/src/lib.cairo b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_02_paths/src/lib.cairo similarity index 72% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_02/src/lib.cairo rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_02_paths/src/lib.cairo index 408497369..4eada1dfb 100644 --- a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_02/src/lib.cairo +++ b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_02_paths/src/lib.cairo @@ -19,10 +19,10 @@ mod front_of_house { pub fn eat_at_restaurant() { // Absolute path - restaurant::front_of_house::hosting::add_to_waitlist(); // ✅ Compiles + restaurant::front_of_house::hosting::add_to_waitlist(); // Relative path - front_of_house::hosting::add_to_waitlist(); // ✅ Compiles + front_of_house::hosting::add_to_waitlist(); } // ANCHOR_END: paths diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_03/.gitignore b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_03_pub_keyword/.gitignore similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_03/.gitignore rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_03_pub_keyword/.gitignore diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/no_listing_03_pub/Scarb.toml b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_03_pub_keyword/Scarb.toml similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/no_listing_03_pub/Scarb.toml rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_03_pub_keyword/Scarb.toml diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/no_listing_03_pub/src/lib.cairo b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_03_pub_keyword/src/lib.cairo similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/no_listing_03_pub/src/lib.cairo rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_03_pub_keyword/src/lib.cairo diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_04/.gitignore b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_04_pub_compiles/.gitignore similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_04/.gitignore rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_04_pub_compiles/.gitignore diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_pub_compiles/Scarb.toml b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_04_pub_compiles/Scarb.toml similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_pub_compiles/Scarb.toml rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_04_pub_compiles/Scarb.toml diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_pub_compiles/src/lib.cairo b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_04_pub_compiles/src/lib.cairo similarity index 53% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_pub_compiles/src/lib.cairo rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_04_pub_compiles/src/lib.cairo index 2e6bdf968..eb1967dbb 100644 --- a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_pub_compiles/src/lib.cairo +++ b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_04_pub_compiles/src/lib.cairo @@ -6,8 +6,8 @@ mod front_of_house { pub fn eat_at_restaurant() { // Absolute path - restaurant::front_of_house::hosting::add_to_waitlist(); + restaurant::front_of_house::hosting::add_to_waitlist(); // ✅ Compiles // Relative path - front_of_house::hosting::add_to_waitlist(); + front_of_house::hosting::add_to_waitlist(); // ✅ Compiles } diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_05/.gitignore b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_05_super/.gitignore similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_05/.gitignore rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_05_super/.gitignore diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_03/Scarb.toml b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_05_super/Scarb.toml similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_03/Scarb.toml rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_05_super/Scarb.toml diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_03/src/lib.cairo b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_05_super/src/lib.cairo similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_03/src/lib.cairo rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_05_super/src/lib.cairo diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_06/.gitignore b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_06_use/.gitignore similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_06/.gitignore rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_06_use/.gitignore diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_04/Scarb.toml b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_06_use/Scarb.toml similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_04/Scarb.toml rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_06_use/Scarb.toml diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_04/src/lib.cairo b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_06_use/src/lib.cairo similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_04/src/lib.cairo rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_06_use/src/lib.cairo diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_07/.gitignore b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_use_and_scope/.gitignore similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_07/.gitignore rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_use_and_scope/.gitignore diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_05/Scarb.toml b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_use_and_scope/Scarb.toml similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_05/Scarb.toml rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_use_and_scope/Scarb.toml diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_05/src/lib.cairo b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_use_and_scope/src/lib.cairo similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_05/src/lib.cairo rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_use_and_scope/src/lib.cairo diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_08/.gitignore b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_08_unidiomatic_use/.gitignore similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_08/.gitignore rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_08_unidiomatic_use/.gitignore diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_06/Scarb.toml b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_08_unidiomatic_use/Scarb.toml similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_06/Scarb.toml rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_08_unidiomatic_use/Scarb.toml diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_06/src/lib.cairo b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_08_unidiomatic_use/src/lib.cairo similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_06/src/lib.cairo rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_08_unidiomatic_use/src/lib.cairo diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_09/.gitignore b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_09_idiomatic_import/.gitignore similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_09/.gitignore rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_09_idiomatic_import/.gitignore diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_07/Scarb.toml b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_09_idiomatic_import/Scarb.toml similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_07/Scarb.toml rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_09_idiomatic_import/Scarb.toml diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_07/src/lib.cairo b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_09_idiomatic_import/src/lib.cairo similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_07/src/lib.cairo rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_09_idiomatic_import/src/lib.cairo diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_10/.gitignore b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_10_as_keyword/.gitignore similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_10/.gitignore rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_10_as_keyword/.gitignore diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_08/Scarb.toml b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_10_as_keyword/Scarb.toml similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_08/Scarb.toml rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_10_as_keyword/Scarb.toml diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_08/src/lib.cairo b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_10_as_keyword/src/lib.cairo similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_08/src/lib.cairo rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_10_as_keyword/src/lib.cairo diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_11/.gitignore b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_11_multiple_items/.gitignore similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_11/.gitignore rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_11_multiple_items/.gitignore diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_09/Scarb.toml b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_11_multiple_items/Scarb.toml similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_09/Scarb.toml rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_11_multiple_items/Scarb.toml diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_09/src/lib.cairo b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_11_multiple_items/src/lib.cairo similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_09/src/lib.cairo rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_11_multiple_items/src/lib.cairo diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_12/.gitignore b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_12_pub_use/.gitignore similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_12/.gitignore rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_12_pub_use/.gitignore diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_10/Scarb.toml b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_12_pub_use/Scarb.toml similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_10/Scarb.toml rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_12_pub_use/Scarb.toml diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_10/src/lib.cairo b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_12_pub_use/src/lib.cairo similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_10/src/lib.cairo rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_12_pub_use/src/lib.cairo diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_pub_compiles/.gitignore b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_13_front_extraction/.gitignore similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_pub_compiles/.gitignore rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_13_front_extraction/.gitignore diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_11/Scarb.toml b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_13_front_extraction/Scarb.toml similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_11/Scarb.toml rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_13_front_extraction/Scarb.toml diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_11/src/lib.cairo b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_13_front_extraction/src/lib.cairo similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_11/src/lib.cairo rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_13_front_extraction/src/lib.cairo diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/no_listing_03_pub/.gitignore b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_14_front_definition/.gitignore similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/no_listing_03_pub/.gitignore rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_14_front_definition/.gitignore diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_12/Scarb.toml b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_14_front_definition/Scarb.toml similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_12/Scarb.toml rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_14_front_definition/Scarb.toml diff --git a/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_12/src/lib.cairo b/listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_14_front_definition/src/lib.cairo similarity index 100% rename from listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_12/src/lib.cairo rename to listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_14_front_definition/src/lib.cairo diff --git a/listings/ch11-advanced-features/no_listing_02_array_macro/.gitignore b/listings/ch11-advanced-features/no_listing_02_array_macro/.gitignore deleted file mode 100644 index eb5a316cb..000000000 --- a/listings/ch11-advanced-features/no_listing_02_array_macro/.gitignore +++ /dev/null @@ -1 +0,0 @@ -target diff --git a/listings/ch11-advanced-features/no_listing_02_array_macro/Scarb.lock b/listings/ch11-advanced-features/no_listing_02_array_macro/Scarb.lock deleted file mode 100644 index 503016343..000000000 --- a/listings/ch11-advanced-features/no_listing_02_array_macro/Scarb.lock +++ /dev/null @@ -1,6 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "no_listing_02_array_macro" -version = "0.1.0" diff --git a/src/ch01-01-installation.md b/src/ch01-01-installation.md index 5ee0319ac..c0edd3ea9 100644 --- a/src/ch01-01-installation.md +++ b/src/ch01-01-installation.md @@ -33,13 +33,13 @@ asdf plugin add scarb This will allow you to download specific versions: ```bash -asdf install scarb 2.5.3 +asdf install scarb 2.6.3 ``` and set a global version: ```bash -asdf global scarb 2.5.3 +asdf global scarb 2.6.3 ``` Otherwise, you can simply run the following command in your terminal, and follow the onscreen instructions. This will install the latest stable release of Scarb. @@ -53,9 +53,9 @@ In both cases, you can verify installation by running the following command in a ```bash $ scarb --version -scarb 2.5.3 (46d5d5cea 2024-02-01) -cairo: 2.5.3 (https://crates.io/crates/cairo-lang-compiler/2.5.3) -sierra: 1.4.0 +scarb 2.6.3 (e6f921dfd 2024-03-13) +cairo: 2.6.3 (https://crates.io/crates/cairo-lang-compiler/2.6.3) +sierra: 1.5.0 ``` {{#quiz ../quizzes/ch01-01-installation.toml}} diff --git a/src/ch02-01-variables-and-mutability.md b/src/ch02-01-variables-and-mutability.md index aace49f28..f6d83286f 100644 --- a/src/ch02-01-variables-and-mutability.md +++ b/src/ch02-01-variables-and-mutability.md @@ -74,8 +74,6 @@ level, the variable is not redeclared so its type cannot change. For example, let’s change _src/lib.cairo_ to the following: -Filename: src/lib.cairo - ```rust {{#include ../listings/ch02-common-programming-concepts/no_listing_02_adding_mut/src/lib.cairo}} ``` @@ -127,8 +125,7 @@ const ONE_HOUR_IN_SECONDS: u32 = consteval_int!(60 * 60); We will dive into more detail about macros in the [dedicated section](./ch11-06-macros.md). -Cairo's naming convention for constants is to use all uppercase with -underscores between words. +Cairo's naming convention for constants is to use all uppercase with underscores between words. Constants are valid for the entire time a program runs, within the scope in which they were declared. This property makes constants useful for values in @@ -152,8 +149,6 @@ variable name to itself until either it itself is shadowed or the scope ends. We can shadow a variable by using the same variable’s name and repeating the use of the `let` keyword as follows: -Filename: src/lib.cairo - ```rust {{#include ../listings/ch02-common-programming-concepts/no_listing_03_shadowing/src/lib.cairo}} ``` @@ -213,8 +208,7 @@ error: The value does not fit within the range of type core::integer::u64. error: could not compile `variables` due to previous error ``` -Now that we’ve explored how variables work, let’s look at more data types they -can have. +Now that we’ve explored how variables work, let’s look at more data types they can have. {{#quiz ../quizzes/ch02-01-variables-and-mutability.toml}} diff --git a/src/ch02-02-data-types.md b/src/ch02-02-data-types.md index 7e7edf2cd..429aa019d 100644 --- a/src/ch02-02-data-types.md +++ b/src/ch02-02-data-types.md @@ -4,8 +4,7 @@ Every value in Cairo is of a certain _data type_, which tells Cairo what kind of data is being specified so it knows how to work with that data. This section covers two subsets of data types: scalars and compounds. Keep in mind that Cairo is a _statically typed_ language, which means that it -must know the types of all variables at compile time. The compiler can usually infer the desired type based on the value and its usage. In cases -when many types are possible, we can use a cast method where we specify the desired output type. +must know the types of all variables at compile time. The compiler can usually infer the desired type based on the value and its usage. In cases when many types are possible, we can use a cast method where we specify the desired output type. ```rust {{#include ../listings/ch02-common-programming-concepts/no_listing_06_data_types/src/lib.cairo}} @@ -138,14 +137,12 @@ Here are some examples of declaring short strings in Cairo: #### Byte Array strings -With the `ByteArray` struct added in Cairo 2.4.0 you are not limited to 31 characters anymore. These `ByteArray` strings are written in double quotes like in the following example: +With the `ByteArray` struct added in Cairo 2.4.0, you are not limited to 31 characters anymore. These `ByteArray` strings are written in double quotes like in the following example: ```rust {{#rustdoc_include ../listings/ch02-common-programming-concepts/no_listing_10_short_string_type/src/lib.cairo:8:8}} ``` - - ## Type casting In Cairo, you can convert scalar types from one type to another by using the `try_into` and `into` methods provided by the `TryInto` and `Into` traits from the core library. diff --git a/src/ch02-03-functions.md b/src/ch02-03-functions.md index fe8ee8fae..26f2adeba 100644 --- a/src/ch02-03-functions.md +++ b/src/ch02-03-functions.md @@ -103,7 +103,7 @@ If you want to use named parameters, you need to specify the name of the paramet Here is an example: ```rust -{{#include ../listings/ch02-common-programming-concepts/no_listing_32_named_parameters/src/lib.cairo}} +{{#include ../listings/ch02-common-programming-concepts/no_listing_18_named_parameters/src/lib.cairo}} ``` ## Statements and Expressions @@ -125,20 +125,19 @@ assigning a value to it with the `let` keyword is a statement. In Listing {{#ref `let y = 6;` is a statement. ```rust -{{#include ../listings/ch02-common-programming-concepts/listing_01_statement/src/lib.cairo}} +{{#include ../listings/ch02-common-programming-concepts/no_listing_19_statement/src/lib.cairo}} ``` {{#label fn-main}} -Listing {{#ref fn-main}}: A `main` function declaration containing one statement +Listing {{#ref fn-main}}: A `main` function declaration containing one statement. -Function definitions are also statements; the entire preceding example is a -statement in itself. +Function definitions are also statements; the entire preceding example is a statement in itself. Statements do not return values. Therefore, you can’t assign a `let` statement to another variable, as the following code tries to do; you’ll get an error: ```rust, noplayground -{{#include ../listings/ch02-common-programming-concepts/no_listing_18_statements_dont_return_values/src/lib.cairo}} +{{#include ../listings/ch02-common-programming-concepts/no_listing_20_statements_dont_return_values/src/lib.cairo}} ``` When you run this program, the error you’ll get looks like this: @@ -182,13 +181,13 @@ Calling a function is an expression since it always evaluates to a value: the fu A new scope block created with curly brackets is an expression, for example: ```rust -{{#include ../listings/ch02-common-programming-concepts/no_listing_19_blocks_are_expressions/src/lib.cairo:all}} +{{#include ../listings/ch02-common-programming-concepts/no_listing_21_blocks_are_expressions/src/lib.cairo:all}} ``` This expression: ```rust, noplayground -{{#include ../listings/ch02-common-programming-concepts/no_listing_19_blocks_are_expressions/src/lib.cairo:block_expr}} +{{#include ../listings/ch02-common-programming-concepts/no_listing_21_blocks_are_expressions/src/lib.cairo:block_expr}} ``` is a block that, in this case, evaluates to `4`. That value gets bound to `y` @@ -210,7 +209,7 @@ functions return the last expression implicitly. Here’s an example of a function that returns a value: ```rust -{{#include ../listings/ch02-common-programming-concepts/no_listing_20_function_return_values/src/lib.cairo}} +{{#include ../listings/ch02-common-programming-concepts/no_listing_22_function_return_values/src/lib.cairo}} ``` There are no function calls, or even `let` statements in the `five` @@ -240,7 +239,7 @@ because it’s an expression whose value we want to return. Let’s look at another example: ```rust -{{#include ../listings/ch02-common-programming-concepts/no_listing_21_function_return_values_2/src/lib.cairo}} +{{#include ../listings/ch02-common-programming-concepts/no_listing_23_function_return_values_2/src/lib.cairo}} ``` Running this code will print `x = 6`. But if we place a @@ -248,7 +247,7 @@ semicolon at the end of the line containing `x + 1`, changing it from an expression to a statement, we’ll get an error: ```rust,does_not_compile -{{#include ../listings/ch02-common-programming-concepts/no_listing_22_function_return_invalid/src/lib.cairo}} +{{#include ../listings/ch02-common-programming-concepts/no_listing_24_function_return_invalid/src/lib.cairo}} ``` ```shell diff --git a/src/ch02-04-comments.md b/src/ch02-04-comments.md index 0c5bdb631..a75d8fcfe 100644 --- a/src/ch02-04-comments.md +++ b/src/ch02-04-comments.md @@ -18,18 +18,14 @@ In Cairo, the idiomatic comment style starts a comment with two slashes, and the Comments can also be placed at the end of lines containing code: -Filename: src/lib.cairo - ```rust -{{#include ../listings/ch02-common-programming-concepts/no_listing_23_comments/src/lib.cairo}} +{{#include ../listings/ch02-common-programming-concepts/no_listing_25_comments/src/lib.cairo}} ``` But you’ll more often see them used in this format, with the comment on a separate line above the code it’s annotating: -Filename: src/lib.cairo - ```rust -{{#include ../listings/ch02-common-programming-concepts/no_listing_23_comments_2/src/lib.cairo}} +{{#include ../listings/ch02-common-programming-concepts/no_listing_26_comments_2/src/lib.cairo}} ``` {{#quiz ../quizzes/ch02-04-comments.toml}} diff --git a/src/ch02-05-control-flow.md b/src/ch02-05-control-flow.md index aa7e3c8a9..ea21b8db9 100644 --- a/src/ch02-05-control-flow.md +++ b/src/ch02-05-control-flow.md @@ -8,10 +8,8 @@ An if expression allows you to branch your code depending on conditions. You pro Create a new project called _branches_ in your _cairo_projects_ directory to explore the `if` expression. In the _src/lib.cairo_ file, input the following: -Filename: src/lib.cairo - ```rust -{{#include ../listings/ch02-common-programming-concepts/no_listing_24_if/src/lib.cairo}} +{{#include ../listings/ch02-common-programming-concepts/no_listing_27_if/src/lib.cairo}} ``` All `if` expressions start with the keyword `if`, followed by a condition. In this case, the condition checks whether or not the variable `number` has a value equal to 5. We place the block of code to execute if the condition is `true` immediately after the condition inside curly brackets. @@ -40,10 +38,8 @@ Run completed successfully, returning [] It’s also worth noting that the condition in this code must be a `bool`. If the condition isn’t a `bool`, we’ll get an error. For example, try running the following code: -Filename: src/lib.cairo - ```rust -{{#include ../listings/ch02-common-programming-concepts/no_listing_24_bis_if_not_bool/src/lib.cairo}} +{{#include ../listings/ch02-common-programming-concepts/no_listing_28_bis_if_not_bool/src/lib.cairo}} ``` The `if` condition evaluates to a value of 3 this time, and Cairo throws an error: @@ -70,7 +66,7 @@ code block to run only when a number is not equal to 0, for example, we can change the if expression to the following: ```rust -{{#include ../listings/ch02-common-programming-concepts/no_listing_24_ter_if_not_equal_zero/src/lib.cairo}} +{{#include ../listings/ch02-common-programming-concepts/no_listing_29_ter_if_not_equal_zero/src/lib.cairo}} ``` @@ -80,10 +76,8 @@ Running this code will print `number was something other than zero`. You can use multiple conditions by combining `if` and `else` in an `else if` expression. For example: -Filename: src/lib.cairo - ```rust -{{#include ../listings/ch02-common-programming-concepts/no_listing_25_else_if/src/lib.cairo}} +{{#include ../listings/ch02-common-programming-concepts/no_listing_30_else_if/src/lib.cairo}} ``` This program has four possible paths it can take. After running it, you should see the following output: @@ -100,10 +94,8 @@ When this program executes, it checks each `if` expression in turn and executes Because `if` is an expression, we can use it on the right side of a `let` statement to assign the outcome to a variable. -Filename: src/lib.cairo - ```rust -{{#include ../listings/ch02-common-programming-concepts/no_listing_26_if_let/src/lib.cairo}} +{{#include ../listings/ch02-common-programming-concepts/no_listing_31_if_let/src/lib.cairo}} ``` ```shell @@ -126,10 +118,8 @@ The `loop` keyword tells Cairo to execute a block of code over and over again fo As an example, change the _src/lib.cairo_ file in your _loops_ directory to look like this: -Filename: src/lib.cairo - ```rust -{{#include ../listings/ch02-common-programming-concepts/no_listing_27_infinite_loop/src/lib.cairo}} +{{#include ../listings/ch02-common-programming-concepts/no_listing_32_infinite_loop/src/lib.cairo}} ``` > Note: This program would not compile without a break condition. For the purpose of the example, we added a `break` statement that will never be reached, but satisfies the compiler. @@ -159,14 +149,14 @@ Now, try running the same program again, but this time with the `--available-gas Fortunately, Cairo also provides a way to break out of a loop using code. You can place the `break` keyword within the loop to tell the program when to stop executing the loop. ```rust -{{#include ../listings/ch02-common-programming-concepts/no_listing_28_loop_break/src/lib.cairo}} +{{#include ../listings/ch02-common-programming-concepts/no_listing_33_loop_break/src/lib.cairo}} ``` The `continue` keyword tells the program to go to the next iteration of the loop and to skip the rest of the code in this iteration. Let's add a `continue` statement to our loop to skip the `println!` statement when `i` is equal to `5`. ```rust -{{#include ../listings/ch02-common-programming-concepts/no_listing_29_loop_continue/src/lib.cairo}} +{{#include ../listings/ch02-common-programming-concepts/no_listing_34_loop_continue/src/lib.cairo}} ``` Executing this program will not print the value of `i` when it is equal to `5`. @@ -181,7 +171,7 @@ use to stop the loop; that value will be returned out of the loop so you can use it, as shown here: ```rust -{{#include ../listings/ch02-common-programming-concepts/no_listing_30_loop_return_values/src/lib.cairo}} +{{#include ../listings/ch02-common-programming-concepts/no_listing_35_loop_return_values/src/lib.cairo}} ``` Before the loop, we declare a variable named `counter` and initialize it to @@ -202,11 +192,11 @@ However, this pattern is so common that Cairo has a built-in language construct In Listing {{#ref while-true}}, we use `while` to loop the program three times, counting down each time after printing the value of `number`, and then, after the loop, print a message and exit. ```rust -{{#include ../listings/ch02-common-programming-concepts/no_listing_31_while_loop/src/lib.cairo}} +{{#include ../listings/ch02-common-programming-concepts/no_listing_36_while_loop/src/lib.cairo}} ``` {{#label while-true}} -Listing {{#ref while-true}}: Using a `while` loop to run code while a condition holds `true` +Listing {{#ref while-true}}: Using a `while` loop to run code while a condition holds `true`. This construct eliminates a lot of nesting that would be necessary if you used `loop`, `if`, `else`, and `break`, and it’s clearer. While a condition evaluates to `true`, the code runs; otherwise, it exits the loop. diff --git a/src/ch03-01-arrays.md b/src/ch03-01-arrays.md index e77a6bf6e..3fa5451f8 100644 --- a/src/ch03-01-arrays.md +++ b/src/ch03-01-arrays.md @@ -10,7 +10,7 @@ This has to do with the fact that once a memory slot is written to, it cannot be Creating an array is done with the `ArrayTrait::new()` call. Here's an example of creating an array and appending 3 elements to it:: ```rust -{{#include ../listings/ch03-common-collections/no_listing_00_array_new_append/src/lib.cairo}} +{{#include ../listings/ch03-common-collections/no_listing_01_array_new_append/src/lib.cairo}} ``` When required, you can pass the expected type of items inside the array when instantiating the array like this, or explicitly define the type of the variable. @@ -30,7 +30,7 @@ let mut arr:Array = ArrayTrait::new(); To add an element to the end of an array, you can use the `append()` method: ```rust -{{#rustdoc_include ../listings/ch03-common-collections/no_listing_00_array_new_append/src/lib.cairo:5}} +{{#rustdoc_include ../listings/ch03-common-collections/no_listing_01_array_new_append/src/lib.cairo:5}} ``` ### Removing Elements @@ -39,7 +39,7 @@ You can only remove elements from the front of an array by using the `pop_front( This method returns an `Option` that can be unwrapped, containing the removed element, or `Option::None` if the array is empty. ```rust -{{#include ../listings/ch03-common-collections/no_listing_01_array_pop_front/src/lib.cairo}} +{{#include ../listings/ch03-common-collections/no_listing_02_array_pop_front/src/lib.cairo}} ``` The above code will print `The first value is 10` as we remove the first element that was added. @@ -67,7 +67,7 @@ The `at` function, on the other hand, directly returns a snapshot to the element Here is an example with the `at()` method: ```rust -{{#include ../listings/ch03-common-collections/no_listing_02_array_at/src/lib.cairo}} +{{#include ../listings/ch03-common-collections/no_listing_04_array_at/src/lib.cairo}} ``` In this example, the variable named `first` will get the value `0` because that @@ -77,7 +77,7 @@ the value `1` from index `1` in the array. If you want to use the subscripting operator `arr[index]`, you will need to explicitly define the type of the elements of the array, otherwise it will not compile. For example: ```rust -{{#include ../listings/ch03-common-collections/no_listing_02_array_at_2/src/lib.cairo}} +{{#include ../listings/ch03-common-collections/no_listing_05_array_at_2/src/lib.cairo}} ``` In summary, use `at` when you want to panic on out-of-bounds access attempts, and use `get` when you prefer to handle such cases gracefully without panicking. @@ -96,13 +96,13 @@ At compile-time, the compiler will expand the macro to generate the code that ap Without `array!`: ```rust -{{#include ../listings/ch11-advanced-features/no_listing_02_array_macro/src/lib.cairo:no_macro}} +{{#include ../listings/ch03-common-collections/no_listing_06_array_macro/src/lib.cairo:no_macro}} ``` With `array!`: ```rust -{{#include ../listings/ch11-advanced-features/no_listing_02_array_macro/src/lib.cairo:array_macro}} +{{#include ../listings/ch03-common-collections/no_listing_06_array_macro/src/lib.cairo:array_macro}} ``` ## Storing multiple types with Enums @@ -110,7 +110,7 @@ With `array!`: If you want to store elements of different types in an array, you can use an `Enum` to define a custom data type that can hold multiple types. Enums will be explained in more detail in the [Enums and Pattern Matching](ch06-00-enums-and-pattern-matching.md) chapter. ```rust -{{#include ../listings/ch03-common-collections/no_listing_04_array_with_enums/src/lib.cairo}} +{{#include ../listings/ch03-common-collections/no_listing_07_array_with_enums/src/lib.cairo}} ``` ## Span @@ -124,5 +124,5 @@ All methods provided by `Array` can also be used with `Span`, except for the `ap To create a `Span` of an `Array`, call the `span()` method: ```rust -{{#rustdoc_include ../listings/ch03-common-collections/no_listing_05_array_span/src/lib.cairo:3}} +{{#rustdoc_include ../listings/ch03-common-collections/no_listing_08_array_span/src/lib.cairo:3}} ``` diff --git a/src/ch03-02-dictionaries.md b/src/ch03-02-dictionaries.md index 1a7ca0d1e..61296131d 100644 --- a/src/ch03-02-dictionaries.md +++ b/src/ch03-02-dictionaries.md @@ -16,7 +16,7 @@ The core functionality of a `Felt252Dict` is implemented in the trait `Felt25 These functions allow us to manipulate dictionaries like in any other language. In the following example, we create a dictionary to represent a mapping between individuals and their balance: ```rust -{{#include ../listings/ch03-common-collections/no_listing_07_intro/src/lib.cairo}} +{{#include ../listings/ch03-common-collections/no_listing_09_intro/src/lib.cairo}} ``` We can create a new instance of `Felt252Dict` by using the `default` method of the `Default` trait and add two individuals, each one with their own balance, using the `insert` method. Finally, we check the balance of our users with the `get` method. These methods are defined in the `Felt252DictTrait` trait in the core library. @@ -26,7 +26,7 @@ Throughout the book we have talked about how Cairo's memory is immutable, meanin Building upon our previous example, let us show a code example where the balance of the same user changes: ```rust -{{#include ../listings/ch03-common-collections/no_listing_08_intro_rewrite/src/lib.cairo}} +{{#include ../listings/ch03-common-collections/no_listing_10_intro_rewrite/src/lib.cairo}} ``` Notice how in this example we added the 'Alex' individual twice, each time using a different balance and each time that we checked for its balance it had the last value inserted! `Felt252Dict` effectively allows us to "rewrite" the stored value for any given key. @@ -48,7 +48,7 @@ One of the constraints of Cairo's non-deterministic design is that its memory sy If we try implementing `Felt252Dict` using high-level structures we would internally define it as `Array>` where each `Entry` has information about what key-value pair it represents and the previous and new values it holds. The definition of `Entry` would be: ```rust,noplayground -{{#include ../listings/ch03-common-collections/no_listing_09_entries/src/lib.cairo:struct}} +{{#include ../listings/ch03-common-collections/no_listing_11_entries/src/lib.cairo:struct}} ``` For each time we interact with a `Felt252Dict`, a new `Entry` will be registered: @@ -59,7 +59,7 @@ For each time we interact with a `Felt252Dict`, a new `Entry` will be regi The use of this entry list shows how there isn't any rewriting, just the creation of new memory cells per `Felt252Dict` interaction. Let's show an example of this using the `balances` dictionary from the previous section and inserting the users 'Alex' and 'Maria': ```rust -{{#rustdoc_include ../listings/ch03-common-collections/no_listing_09_entries/src/lib.cairo:inserts}} +{{#rustdoc_include ../listings/ch03-common-collections/no_listing_11_entries/src/lib.cairo:inserts}} ``` These instructions would then produce the following list of entries: @@ -151,9 +151,9 @@ Let us see an example using `entry` and `finalize`. Imagine we would like to imp Implementing our custom get would look like this: ```rust,noplayground -{{#include ../listings/ch03-common-collections/no_listing_10_custom_methods/src/lib.cairo:imports}} +{{#include ../listings/ch03-common-collections/no_listing_12_custom_methods/src/lib.cairo:imports}} -{{#include ../listings/ch03-common-collections/no_listing_10_custom_methods/src/lib.cairo:custom_get}} +{{#include ../listings/ch03-common-collections/no_listing_12_custom_methods/src/lib.cairo:custom_get}} ``` The `ref` keyword means that the ownership of the variable will be given back at the end of @@ -162,15 +162,15 @@ the function. This concept will be explained in more detail in the [References a Implementing the `insert` method would follow a similar workflow, except for inserting a new value when finalizing. If we were to implement it, it would look like the following: ```rust,noplayground -{{#include ../listings/ch03-common-collections/no_listing_10_custom_methods/src/lib.cairo:imports}} +{{#include ../listings/ch03-common-collections/no_listing_12_custom_methods/src/lib.cairo:imports}} -{{#include ../listings/ch03-common-collections/no_listing_10_custom_methods/src/lib.cairo:custom_insert}} +{{#include ../listings/ch03-common-collections/no_listing_12_custom_methods/src/lib.cairo:custom_insert}} ``` As a finalizing note, these two methods are implemented in a similar way to how `insert` and `get` are implemented for `Felt252Dict`. This code shows some example usage: ```rust -{{#rustdoc_include ../listings/ch03-common-collections/no_listing_10_custom_methods/src/lib.cairo:main}} +{{#rustdoc_include ../listings/ch03-common-collections/no_listing_12_custom_methods/src/lib.cairo:main}} ``` ## Dictionaries of types not supported natively @@ -186,9 +186,9 @@ To compensate this, you can wrap your type inside a `Nullable`. Let's show using an example. We will try to store a `Span` inside a dictionary. For that, we will use `Nullable` and `Box`. Also, we are storing a `Span` and not an `Array` because the latter does not implement the `Copy` trait which is required for reading from a dictionary. ```rust,noplayground -{{#include ../listings/ch03-common-collections/no_listing_11_dict_of_complex/src/lib.cairo:imports}} +{{#include ../listings/ch03-common-collections/no_listing_13_dict_of_complex/src/lib.cairo:imports}} -{{#include ../listings/ch03-common-collections/no_listing_11_dict_of_complex/src/lib.cairo:header}} +{{#include ../listings/ch03-common-collections/no_listing_13_dict_of_complex/src/lib.cairo:header}} //... ``` @@ -202,7 +202,7 @@ Once the element is inside the dictionary, and we want to get it, we follow the ```rust,noplayground //... -{{#include ../listings/ch03-common-collections/no_listing_11_dict_of_complex/src/lib.cairo:footer}} +{{#include ../listings/ch03-common-collections/no_listing_13_dict_of_complex/src/lib.cairo:footer}} ``` Here we: @@ -214,5 +214,5 @@ Here we: The complete script would look like this: ```rust -{{#include ../listings/ch03-common-collections/no_listing_11_dict_of_complex/src/lib.cairo:all}} +{{#include ../listings/ch03-common-collections/no_listing_13_dict_of_complex/src/lib.cairo:all}} ``` diff --git a/src/ch03-03-custom-data-structures.md b/src/ch03-03-custom-data-structures.md deleted file mode 100644 index 26c279b9a..000000000 --- a/src/ch03-03-custom-data-structures.md +++ /dev/null @@ -1 +0,0 @@ -# Custom Data Structures diff --git a/src/ch04-01-what-is-ownership.md b/src/ch04-01-what-is-ownership.md index a623d7883..d4ae3ac69 100644 --- a/src/ch04-01-what-is-ownership.md +++ b/src/ch04-01-what-is-ownership.md @@ -46,11 +46,11 @@ which it’s declared until the end of the current _scope_. Listing {{#ref varia program with comments annotating where the variable `s` would be valid. ```rust -{{#rustdoc_include ../listings/ch04-understanding-ownership/listing_04_01/src/lib.cairo:here}} +{{#rustdoc_include ../listings/ch04-understanding-ownership/listing_01_variable_and_scope/src/lib.cairo:here}} ``` {{#label variable-scope}} -Listing {{#ref variable-scope}}: A variable and the scope in which it is valid +Listing {{#ref variable-scope}}: A variable and the scope in which it is valid. In other words, there are two important points in time here: @@ -179,11 +179,11 @@ function that returns some value, with similar annotations as those in Listing { Filename: src/lib.cairo ```rust -{{#include ../listings/ch04-understanding-ownership/listing_04_02/src/lib.cairo}} +{{#include ../listings/ch04-understanding-ownership/listing_02_moving_return_values/src/lib.cairo}} ``` {{#label move-return-values}} -Listing {{#ref move-return-values}}: Moving return values +Listing {{#ref move-return-values}}: Moving return values. While this works, moving into and out of every function is a bit tedious. What if we want to let a function use a value but not move the value? It’s quite annoying that anything we pass in also needs to be passed back if we want to use it again, in addition to any data resulting from the body of the function that we might want to return as well. @@ -192,11 +192,11 @@ Cairo does let us return multiple values using a tuple, as shown in Listing {{#r Filename: src/lib.cairo ```rust -{{#include ../listings/ch04-understanding-ownership/listing_04_03/src/lib.cairo}} +{{#include ../listings/ch04-understanding-ownership/listing_03_returning_many_values/src/lib.cairo}} ``` {{#label return-multiple-values}} -Listing {{#ref return-multiple-values}}: Returning many values +Listing {{#ref return-multiple-values}}: Returning many values. But this is too much ceremony and a lot of work for a concept that should be common. Luckily for us, Cairo has two features for passing a value without destroying or moving it, called _references_ and _snapshots_. diff --git a/src/ch04-02-references-and-snapshots.md b/src/ch04-02-references-and-snapshots.md index 22db929c1..8187d0f57 100644 --- a/src/ch04-02-references-and-snapshots.md +++ b/src/ch04-02-references-and-snapshots.md @@ -81,12 +81,12 @@ Listing {{#ref modify-snapshot}}. Spoiler alert: it doesn’t work! Filename: src/lib.cairo ```rust,does_not_compile -{{#include ../listings/ch04-understanding-ownership/listing_04_04/src/lib.cairo}} +{{#include ../listings/ch04-understanding-ownership/listing_04_attempt_modifying_snapshot/src/lib.cairo}} ``` {{#label modify-snapshot}} -Listing {{#ref modify-snapshot}}: Attempting to modify a snapshot value +Listing {{#ref modify-snapshot}}: Attempting to modify a snapshot value. Here’s the error: @@ -109,10 +109,10 @@ In Cairo, a parameter can be passed as _mutable reference_ using the `ref` modif In Listing 4-5, we use a mutable reference to modify the value of the `height` and `width` fields of the `Rectangle` instance in the `flip` function. ```rust -{{#include ../listings/ch04-understanding-ownership/listing_04_05/src/lib.cairo}} +{{#include ../listings/ch04-understanding-ownership/listing_05_mutable_reference/src/lib.cairo}} ``` -Listing 4-5: Use of a mutable reference to modify a value +Listing 4-5: Use of a mutable reference to modify a value. First, we change `rec` to be `mut`. Then we pass a mutable reference of `rec` into `flip` with `ref rec`, and update the function signature to accept a mutable reference with `ref rec: Rectangle`. This makes it very clear that the `flip` function will mutate the value of the `Rectangle` instance passed as parameter. diff --git a/src/ch05-01-defining-and-instantiating-structs.md b/src/ch05-01-defining-and-instantiating-structs.md index 0b698605b..501969daf 100644 --- a/src/ch05-01-defining-and-instantiating-structs.md +++ b/src/ch05-01-defining-and-instantiating-structs.md @@ -7,12 +7,12 @@ To define a struct, we enter the keyword `struct` and name the entire struct. A Filename: src/lib.cairo ```rust, noplayground -{{#include ../listings/ch05-using-structs-to-structure-related-data/listing_05_01_user_struct/src/lib.cairo:user}} +{{#include ../listings/ch05-using-structs-to-structure-related-data/listing_01_user_struct/src/lib.cairo:user}} ``` {{#label user-struct}} -Listing {{#ref user-struct}}: A `User` struct definition +Listing {{#ref user-struct}}: A `User` struct definition. To use a struct after we’ve defined it, we create an _instance_ of that struct by specifying concrete values for each of the fields. We create an instance by stating the name of the struct and then add curly brackets containing _key: value_ pairs, where the keys are the names of the fields and the values are the data we want to store in those fields. We don’t have to specify the fields in the same order in which we declared them in the struct. In other words, the struct definition is like a general template for the type, and instances fill in that template with particular data to create values of the type. @@ -22,22 +22,22 @@ For example, we can declare two particular users as shown in Listing {{#ref user Filename: src/lib.cairo ```rust -{{#include ../listings/ch05-using-structs-to-structure-related-data/listing_05_01_user_struct/src/lib.cairo:all}} +{{#include ../listings/ch05-using-structs-to-structure-related-data/listing_01_user_struct/src/lib.cairo:all}} ``` {{#label user-instances}} -Listing {{#ref user-instances}}: Creating two instances of the `User` struct +Listing {{#ref user-instances}}: Creating two instances of the `User` struct. To get a specific value from a struct, we use dot notation. For example, to access `user1`'s email address, we use `user1.email`. If the instance is mutable, we can change a value by using the dot notation and assigning into a particular field. Listing {{#ref user-mut}} shows how to change the value in the `email` field of a mutable `User` instance. Filename: src/lib.cairo ```rust -{{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/listing_05_02_mut_struct/src/lib.cairo:main}} +{{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/listing_02_mut_struct/src/lib.cairo:main}} ``` {{#label user-mut}} -Listing {{#ref user-mut}}: Changing the value in the email field of a `User` instance +Listing {{#ref user-mut}}: Changing the value in the email field of a `User` instance. Note that the entire instance must be mutable; Cairo doesn’t allow us to mark only certain fields as mutable. @@ -48,11 +48,11 @@ Listing {{#ref build-user}} shows a `build_user` function that returns a `User` Filename: src/lib.cairo ```rust -{{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/listing_05_02_mut_struct/src/lib.cairo:build_user}} +{{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/listing_02_mut_struct/src/lib.cairo:build_user}} ``` {{#label build-user}} -Listing {{#ref build-user}}: A `build_user` function that takes an email and username and returns a `User` instance +Listing {{#ref build-user}}: A `build_user` function that takes an email and username and returns a `User` instance. It makes sense to name the function parameters with the same name as the struct fields, but having to repeat the `email` and `username` field names and variables is a bit tedious. If the struct had more fields, repeating each name would get even more annoying. Luckily, there’s a convenient shorthand! @@ -63,10 +63,10 @@ Because the parameter names and the struct field names are exactly the same in L Filename: src/lib.cairo ```rust -{{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/listing_05_02_mut_struct/src/lib.cairo:build_user2}} +{{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/listing_02_mut_struct/src/lib.cairo:build_user2}} ``` {{#label init-shorthand}} -Listing {{#ref init-shorthand}}: A `build_user` function that uses field init shorthand because the `username` and `email` parameters have the same name as struct fields +Listing {{#ref init-shorthand}}: A `build_user` function that uses field init shorthand because the `username` and `email` parameters have the same name as struct fields. Here, we’re creating a new instance of the `User` struct, which has a field named `email`. We want to set the `email` field’s value to the value in the `email` parameter of the `build_user` function. Because the `email` field and the `email` parameter have the same name, we only need to write `email` rather than `email: email`. diff --git a/src/ch05-02-an-example-program-using-structs.md b/src/ch05-02-an-example-program-using-structs.md index c84e2c457..d891c9577 100644 --- a/src/ch05-02-an-example-program-using-structs.md +++ b/src/ch05-02-an-example-program-using-structs.md @@ -7,11 +7,11 @@ Let’s make a new project with Scarb called _rectangles_ that will take the wid Filename: src/lib.cairo ```rust -{{#include ../listings/ch05-using-structs-to-structure-related-data/listing_05_06_no_struct/src/lib.cairo:all}} +{{#include ../listings/ch05-using-structs-to-structure-related-data/listing_03_no_struct/src/lib.cairo:all}} ``` {{#label area-fn}} -Listing {{#ref area-fn}}: Calculating the area of a rectangle specified by separate width and height variables +Listing {{#ref area-fn}}: Calculating the area of a rectangle specified by separate width and height variables. Now run the program with `scarb cairo-run`: @@ -26,7 +26,7 @@ This code succeeds in figuring out the area of the rectangle by calling the `are The issue with this code is evident in the signature of `area`: ```rust,noplayground -{{#include ../listings/ch05-using-structs-to-structure-related-data/listing_05_06_no_struct/src/lib.cairo:here}} +{{#include ../listings/ch05-using-structs-to-structure-related-data/listing_03_no_struct/src/lib.cairo:here}} ``` The `area` function is supposed to calculate the area of one rectangle, but the function we wrote has two parameters, and it’s not clear anywhere in our program that the parameters are related. It would be more readable and more manageable to group width and height together. We’ve already discussed one way we might do that in the [Tuple Section of Chapter 2](ch02-02-data-types.html#the-tuple-type). @@ -38,11 +38,11 @@ Listing {{#ref rectangle-tuple}} shows another version of our program that uses Filename: src/lib.cairo ```rust -{{#include ../listings/ch05-using-structs-to-structure-related-data/listing_05_07_w_tuples/src/lib.cairo}} +{{#include ../listings/ch05-using-structs-to-structure-related-data/listing_04_w_tuples/src/lib.cairo}} ``` {{#label rectangle-tuple}} -Listing {{#ref rectangle-tuple}}: Specifying the width and height of the rectangle with a tuple +Listing {{#ref rectangle-tuple}}: Specifying the width and height of the rectangle with a tuple. In one way, this program is better. Tuples let us add a bit of structure, and we’re now passing just one argument. But in another way, this version is less clear: tuples don’t name their elements, so we have to index into the parts of the tuple, making our calculation less obvious. @@ -55,10 +55,10 @@ We use structs to add meaning by labeling the data. We can transform the tuple w Filename: src/lib.cairo ```rust -{{#include ../listings/ch05-using-structs-to-structure-related-data/listing_05_08_w_structs/src/lib.cairo}} +{{#include ../listings/ch05-using-structs-to-structure-related-data/listing_05_w_structs/src/lib.cairo}} ``` {{#label rectangle-struct}} -Listing {{#ref rectangle-struct}}: Defining a `Rectangle` struct +Listing {{#ref rectangle-struct}}: Defining a `Rectangle` struct. Here we’ve defined a struct and named it `Rectangle`. Inside the curly brackets, we defined the fields as `width` and `height`, both of which have type `u64`. Then, in `main`, we created a particular instance of `Rectangle` that has a width of `30` and a height of `10`. Our `area` function is now defined with one parameter, which we’ve named `rectangle` which is of type `Rectangle` struct. We can then access the fields of the instance with dot notation, and it gives descriptive names to the values rather than using the tuple index values of `0` and `1`. diff --git a/src/ch05-03-method-syntax.md b/src/ch05-03-method-syntax.md index 31ab623b3..f6cdb075d 100644 --- a/src/ch05-03-method-syntax.md +++ b/src/ch05-03-method-syntax.md @@ -16,19 +16,19 @@ to an `area` method for the `Rectangle` type. To do that, we first define the `RectangleTrait` trait with an `area` method taking a `Rectangle` as `self` parameter. ```rust -{{#include ../listings/ch05-using-structs-to-structure-related-data/listing_05_10_define_methods/src/lib.cairo:trait_definition}} +{{#include ../listings/ch05-using-structs-to-structure-related-data/no_listing_01_define_methods/src/lib.cairo:trait_definition}} ``` Then, we implement this trait in `RectangleImpl` with the `impl` keyword. In the body of the `area` method, we can access to the calling instance with the `self` parameter. ```rust -{{#include ../listings/ch05-using-structs-to-structure-related-data/listing_05_10_define_methods/src/lib.cairo:trait_implementation}} +{{#include ../listings/ch05-using-structs-to-structure-related-data/no_listing_01_define_methods/src/lib.cairo:trait_implementation}} ``` Finally, we call this `area` method on the `Rectangle` instance `rect1` using the `.` syntax. The instance `rect1` will be passed to the `area` method as the `self` parameter. ```rust -{{#include ../listings/ch05-using-structs-to-structure-related-data/listing_05_10_define_methods/src/lib.cairo:main}} +{{#include ../listings/ch05-using-structs-to-structure-related-data/no_listing_01_define_methods/src/lib.cairo:main}} ``` Note that: @@ -47,7 +47,7 @@ So, to avoid defining useless traits, Cairo provides the `#[generate_trait]` att The previous example can also be written as follows: ```rust -{{#include ../listings/ch05-using-structs-to-structure-related-data/listing_05_15_gen_trait/src/lib.cairo}} +{{#include ../listings/ch05-using-structs-to-structure-related-data/no_listing_02_gen_trait/src/lib.cairo}} ``` Let's use this `#[generate_trait]` in the following chapters to make our code cleaner. @@ -59,9 +59,9 @@ As the `area` method does not modify the calling instance, `self` is declared as Let's write a new method `scale` which resizes a rectangle of a `factor` given as parameter: ```rust -{{#include ../listings/ch05-using-structs-to-structure-related-data/listing_05_11_references/src/lib.cairo:trait_impl}} +{{#include ../listings/ch05-using-structs-to-structure-related-data/no_listing_03_references/src/lib.cairo:trait_impl}} -{{#include ../listings/ch05-using-structs-to-structure-related-data/listing_05_11_references/src/lib.cairo:main}} +{{#include ../listings/ch05-using-structs-to-structure-related-data/no_listing_03_references/src/lib.cairo:main}} ``` It is also possible to define a method which takes ownership of the instance by using just `self` as the first parameter but it is rare. This technique is usually used when the method transforms `self` into something else and you want to prevent the caller from using the original instance after the transformation. @@ -73,9 +73,9 @@ Look at the [Understanding Ownership](ch04-00-understanding-ownership.md) chapte Let’s practice using methods by implementing another method on the `Rectangle` struct. This time we want to write the method `can_hold` which accepts another instance of `Rectangle` and returns `true` if this rectangle can fit completely within self; otherwise, it should return false. ```rust -{{#include ../listings/ch05-using-structs-to-structure-related-data/listing_05_12_some_params/src/lib.cairo:trait_impl}} +{{#include ../listings/ch05-using-structs-to-structure-related-data/no_listing_04_some_params/src/lib.cairo:trait_impl}} -{{#include ../listings/ch05-using-structs-to-structure-related-data/listing_05_12_some_params/src/lib.cairo:main}} +{{#include ../listings/ch05-using-structs-to-structure-related-data/no_listing_04_some_params/src/lib.cairo:main}} ``` Here, we expect that `rect1` can hold `rect2` but not `rect3`. @@ -89,9 +89,9 @@ These methods are often use to build new instances but they may have a lot of di Let's create the method `new` which creates a `Rectangle` from a `width` and a `height`, and a method `compare` which compares two `Rectangle` instances, and returns `true` if both rectangle have the same area and `false` otherwise. ```rust -{{#include ../listings/ch05-using-structs-to-structure-related-data/listing_05_13_class_methods/src/lib.cairo:trait_impl}} +{{#include ../listings/ch05-using-structs-to-structure-related-data/no_listing_05_class_methods/src/lib.cairo:trait_impl}} -{{#include ../listings/ch05-using-structs-to-structure-related-data/listing_05_13_class_methods/src/lib.cairo:main}} +{{#include ../listings/ch05-using-structs-to-structure-related-data/no_listing_05_class_methods/src/lib.cairo:main}} ``` Note that the `compare` function could also be written as an _instance method_ with `self` as the first rectangle. In this case, instead of using the method with `Rectangle::compare(rect1, rect2)`, it is called with `rect1.compare(rect2)`. @@ -102,7 +102,7 @@ Each struct is allowed to have multiple `trait` and `impl` blocks. For example, the following code is equivalent to the code shown in the _Methods with several parameters_ section, which has each method in its own `trait` and `impl` blocks. ```rust -{{#include ../listings/ch05-using-structs-to-structure-related-data/listing_05_14_multiple_traits/src/lib.cairo:here}} +{{#include ../listings/ch05-using-structs-to-structure-related-data/no_listing_06_multiple_traits/src/lib.cairo:here}} ``` There’s no strong reason to separate these methods into multiple `trait` and `impl` diff --git a/src/ch06-01-enums.md b/src/ch06-01-enums.md index b20f7dfa1..4f1558668 100644 --- a/src/ch06-01-enums.md +++ b/src/ch06-01-enums.md @@ -19,13 +19,13 @@ In this example, we've defined an enum called `Direction` with four variants: `N Now let's imagine that our variants have associated values, that store the exact degree of the direction. We can define a new `Direction` enum: ```rust, noplayground -{{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/no_listing_01_enum_with_values_example/src/lib.cairo:enum_example}} +{{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/no_listing_02_enum_with_values_example/src/lib.cairo:enum_example}} ``` and instantiate it as follows: ```rust, noplayground -{{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/no_listing_01_enum_with_values_example/src/lib.cairo:here}} +{{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/no_listing_02_enum_with_values_example/src/lib.cairo:here}} ``` In this code, each variant is associated to a `u128` value, representing the direction in degrees. We will see in the next example that it is also possible to associate different data types to each variant. @@ -37,7 +37,7 @@ It's easy to write code that acts differently depending on the variant of an enu Enums can also be used to store more interesting custom data associated with each variant. For example: ```rust, noplayground -{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_02_enum_message/src/lib.cairo:message}} +{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_03_enum_message/src/lib.cairo:message}} ``` In this example, the `Message` enum has three variants: `Quit`, `Echo`, and `Move`, all with different types: @@ -53,13 +53,13 @@ You could even use a Struct or another enum you defined inside one of your enum In Cairo, you can define traits and implement them for your custom enums. This allows you to define methods and behaviors associated with the enum. Here's an example of defining a trait and implementing it for the previous `Message` enum: ```rust, noplayground -{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_02_enum_message/src/lib.cairo:trait_impl}} +{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_03_enum_message/src/lib.cairo:trait_impl}} ``` In this example, we implemented the `Processing` trait for `Message`. Here is how it could be used to process a Quit message: ```rust, noplayground -{{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/no_listing_02_enum_message/src/lib.cairo:main}} +{{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/no_listing_03_enum_message/src/lib.cairo:main}} ``` Running this code would print `quitting`. @@ -85,11 +85,9 @@ We are demonstrating two approaches for the above function: - Iterative approach with `find_value_iterative`. ```rust,noplayground -{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_03_enum_option/src/lib.cairo}} +{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_04_enum_option/src/lib.cairo}} ``` - - Enums can be useful in many situations, especially when using the `match` flow construct that we just used. We will describe it in the next section. Other enums are used very often, such as the `Result` enum, allowing to handle errors gracefully. We will explain the `Result` enum in detail in the [Error Handling](ch09-02-recoverable-errors.md) chapter. diff --git a/src/ch06-02-the-match-control-flow-construct.md b/src/ch06-02-the-match-control-flow-construct.md index 6107554cb..5f2acc207 100644 --- a/src/ch06-02-the-match-control-flow-construct.md +++ b/src/ch06-02-the-match-control-flow-construct.md @@ -7,7 +7,7 @@ Think of a `match` expression as being like a coin-sorting machine: coins slide Speaking of coins, let’s use them as an example using `match`! We can write a function that takes an unknown US coin and, in a similar way as the counting machine, determines which coin it is and returns its value in cents, as shown in Listing {{#ref match-enum}}. ```rust,noplayground -{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_04_match_example/src/lib.cairo:all}} +{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_05_match_example/src/lib.cairo:all}} ``` {{#label match-enum}} @@ -24,7 +24,7 @@ The code associated with each arm is an expression, and the resultant value of t We don’t typically use curly brackets if the `match` arm code is short, as it is in our example where each arm just returns a value. If you want to run multiple lines of code in a `match` arm, you must use curly brackets, with a comma following the arm. For example, the following code prints “Lucky penny!” every time the method is called with a `Coin::Penny`, but still returns the last value of the block, `1`: ```rust,noplayground -{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_05_match_arms_block/src/lib.cairo:here}} +{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_06_match_arms_block/src/lib.cairo:here}} ``` ## Patterns That Bind to Values @@ -34,7 +34,7 @@ Another useful feature of `match` arms is that they can bind to the parts of the As an example, let’s change one of our enum variants to hold data inside it. From 1999 through 2008, the United States minted quarters with different designs for each of the 50 states on one side. No other coins got state designs, so only quarters have this extra value. We can add this information to our `enum` by changing the `Quarter` variant to include a `UsState` value stored inside it, which we’ve done in Listing {{#ref match-pattern-bind}}. ```rust,noplayground -{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_06_match_pattern_bind/src/lib.cairo:enum_def}} +{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_07_match_pattern_bind/src/lib.cairo:enum_def}} ``` {{#label match-pattern-bind}} @@ -45,7 +45,7 @@ Let’s imagine that a friend is trying to collect all 50 state quarters. While In the `match` expression for this code, we add a variable called `state` to the pattern that matches values of the variant `Coin::Quarter`. When a `Coin::Quarter` matches, the `state` variable will bind to the value of that quarter’s state. Then we can use `state` in the code for that arm, like so: ```rust,noplayground -{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_06_match_pattern_bind/src/lib.cairo:function}} +{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_07_match_pattern_bind/src/lib.cairo:function}} ``` Because `state` is an `UsState` enum which implements the `Debug` trait, we can print `state` value with `println!` macro. @@ -63,7 +63,7 @@ Let’s say we want to write a function that takes an `Option` and, if there This function is very easy to write, thanks to `match`, and will look like Listing {{#ref match-option}}. ```rust -{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_07_match_option/src/lib.cairo:all}} +{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_08_match_option/src/lib.cairo:all}} ``` {{#label match-option}} @@ -72,7 +72,7 @@ This function is very easy to write, thanks to `match`, and will look like Listi Let’s examine the first execution of `plus_one` in more detail. When we call `plus_one(five)`, the variable `x` in the body of `plus_one` will have the value `Some(5)`. We then compare that against each `match` arm: ```rust,noplayground -{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_07_match_option/src/lib.cairo:option_some}} +{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_08_match_option/src/lib.cairo:option_some}} ``` Does `Option::Some(5)` value match the pattern `Option::Some(val)`? It does! We have the same variant. The `val` binds to the value contained in `Option::Some`, so `val` takes the value `5`. The code in the `match` arm is then executed, so we add `1` to the value of `val` and create a new `Option::Some` value with our total `6` inside. Because the first arm matched, no other arms are compared. @@ -80,13 +80,13 @@ Does `Option::Some(5)` value match the pattern `Option::Some(val)`? It does! We Now let’s consider the second call of `plus_one` in our main function, where `x` is `Option::None`. We enter the `match` and compare to the first arm: ```rust,noplayground -{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_07_match_option/src/lib.cairo:option_some}} +{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_08_match_option/src/lib.cairo:option_some}} ``` The `Option::Some(val)` value doesn’t match the pattern `Option::None`, so we continue to the next arm: ```rust -{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_07_match_option/src/lib.cairo:option_none}} +{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_08_match_option/src/lib.cairo:option_none}} ``` It matches! There’s no value to add to, so the matching construct ends and returns the `Option::None` value on the right side of `=>`. @@ -98,7 +98,7 @@ Combining `match` and enums is useful in many situations. You’ll see this patt There’s one other aspect of `match` we need to discuss: the arms’ patterns must cover all possibilities. Consider this version of our `plus_one` function, which has a bug and won’t compile: ```rust,noplayground -{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_08_missing_match_arm/src/lib.cairo:here}} +{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_09_missing_match_arm/src/lib.cairo:here}} ``` We didn’t handle the `None` case, so this code will cause a bug. @@ -127,7 +127,7 @@ We want to have a function that processes inserted coins and returns `true` only Here's a `vending_machine_accept` function that implements this logic: ```rust,noplayground -{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_09_match_catch_all/src/lib.cairo:here}} +{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_10_match_catch_all/src/lib.cairo:here}} ``` This example also meets the exhaustiveness requirement because we’re explicitly ignoring all other values in the last arm; we haven’t forgotten anything. @@ -145,7 +145,7 @@ In `match` expressions, you can match multiple patterns using the `|` syntax, wh For example, in the following code we modified the `vending_machine_accept` function to accept both `Dime` and `Quarter` coins in a single arm: ```rust,noplayground -{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_10_match_or/src/lib.cairo:here}} +{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_11_match_or/src/lib.cairo:here}} ``` ## Matching Tuples @@ -154,14 +154,14 @@ It is possible to match tuples. Let's introduce a new `DayType` enum: ```rust,noplayground -{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_11_match_tuple/src/lib.cairo:enum_def}} +{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_12_match_tuple/src/lib.cairo:enum_def}} ``` Now, let's suppose that our vending machine accepts any coin on weekdays, but only accepts quarters and dimes on weekends and holidays. We can modify the `vending_machine_accept` function to accept a tuple of a `Coin` and a `Weekday` and return `true` only if the given coin is accepted on the specified day: ```rust,noplayground -{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_11_match_tuple/src/lib.cairo:here}} +{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_12_match_tuple/src/lib.cairo:here}} ``` ## Matching `felt252` and integer variables @@ -179,7 +179,7 @@ If you have 0, 1 or 2 you win. If you have 3, you can roll again. For all other Here's a match that implements that logic: ```rust,noplayground -{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_12_match_integers/src/lib.cairo:here}} +{{#include ../listings/ch06-enums-and-pattern-matching/no_listing_13_match_integers/src/lib.cairo:here}} ``` > These restrictions are planned to be relaxed in future versions of Cairo. diff --git a/src/ch07-02-defining-modules-to-control-scope.md b/src/ch07-02-defining-modules-to-control-scope.md index afa035c72..03c1e1ec9 100644 --- a/src/ch07-02-defining-modules-to-control-scope.md +++ b/src/ch07-02-defining-modules-to-control-scope.md @@ -130,11 +130,11 @@ define some modules and function signatures. Here’s the front of house section Filename: src/lib.cairo ```rust,noplayground -{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_01/src/lib.cairo:front_of_house}} +{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_01_basic_nested_modules/src/lib.cairo:front_of_house}} ``` {{#label front_of_house}} -Listing {{#ref front_of_house}}: A `front_of_house` module containing other modules that then contain functions +Listing {{#ref front_of_house}}: A `front_of_house` module containing other modules that then contain functions. We define a module with the `mod` keyword followed by the name of the module (in this case, `front_of_house`). The body of the module then goes inside curly @@ -166,7 +166,7 @@ restaurant ``` {{#label module-tree}} -Listing {{#ref module-tree}}: The module tree for the code in Listing {{#ref front_of_house}} +Listing {{#ref module-tree}}: The module tree for the code in Listing {{#ref front_of_house}}. This tree shows how some of the modules nest inside one another; for example, `hosting` nests inside `front_of_house`. The tree also shows that some modules diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index f4c182d80..231de762c 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -14,11 +14,11 @@ To illustrate this notion let's take back our example Listing {{#ref front_of_ho Filename: src/lib.cairo ```rust,noplayground -{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_02/src/lib.cairo:paths}} +{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_02_paths/src/lib.cairo:paths}} ``` {{#label path-types}} -Listing {{#ref path-types}}: Calling the `add_to_waitlist` function using absolute and relative paths +Listing {{#ref path-types}}: Calling the `add_to_waitlist` function using absolute and relative paths. The `eat_at_restaurant` function is part of our library's public API, so we mark it with the `pub` keyword. In the [Exposing Paths with the pub Keyword](ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md#exposing-paths-with-the-pub-keyword) section, we’ll go into more detail about `pub`. @@ -67,11 +67,11 @@ Let’s return to the previous error that told us the `hosting` module and the ` Filename: src/lib.cairo ```rust,noplayground -{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/no_listing_03_pub/src/lib.cairo}} +{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_03_pub_keyword/src/lib.cairo}} ``` {{#label pub-keyword-not-compiling}} -Listing {{#ref pub-keyword-not-compiling}}: Declaring the `hosting` module as `pub` to use it from `eat_at_restaurant` +Listing {{#ref pub-keyword-not-compiling}}: Declaring the `hosting` module as `pub` to use it from `eat_at_restaurant`. Unfortunately, the code in Listing {{#ref pub-keyword-not-compiling}} still results in an error. @@ -82,11 +82,11 @@ Let’s also make the `add_to_waitlist` function public by adding the `pub` keyw Filename: src/lib.cairo ```rust,noplayground -{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_pub_compiles/src/lib.cairo}} +{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_04_pub_compiles/src/lib.cairo}} ``` {{#label pub-keyword}} -Listing {{#ref pub-keyword}}: Declaring the `hosting` module as `pub` to use it from `eat_at_restaurant` +Listing {{#ref pub-keyword}}: Declaring the `hosting` module as `pub` to use it from `eat_at_restaurant`. Now the code will compile! To see why adding the `pub` keyword lets us use these paths in `add_to_waitlist` with respect to the privacy rules, let’s look at the absolute and the relative paths. @@ -103,11 +103,11 @@ Consider the code in Listing {{#ref relative-path}} that models the situation in Filename: src/lib.cairo ```rust,noplayground -{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_03/src/lib.cairo}} +{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_05_super/src/lib.cairo}} ``` {{#label relative-path}} -Listing {{#ref relative-path}}: Calling a function using a relative path starting with `super` +Listing {{#ref relative-path}}: Calling a function using a relative path starting with `super`. Here you can see directly that you access a parent's module easily using `super`, which wasn't the case previously. Note that the `back_of_house` is kept private, as external users are not supposed to interact with the back of house directly. diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index 7a4ba7479..e4eb776f5 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -10,11 +10,11 @@ scope of the `eat_at_restaurant` function so we only have to specify Filename: src/lib.cairo ```rust -{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_04/src/lib.cairo:use}} +{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_06_use/src/lib.cairo:use}} ``` {{#label use-keyword}} -Listing {{#ref use-keyword}}: Bringing a module into scope with `use` +Listing {{#ref use-keyword}}: Bringing a module into scope with `use`. Adding `use` and a path in a scope is similar to creating a symbolic link in the filesystem. By adding `use restaurant::front_of_house::hosting;` in the crate root, `hosting` is now a valid name in that scope, just as though the `hosting` module had been defined in the crate root. @@ -24,11 +24,11 @@ statement, so the function body won’t compile: Filename: src/lib.cairo ```rust -{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_05/src/lib.cairo:wrong-path}} +{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_use_and_scope/src/lib.cairo:wrong-path}} ``` {{#label use-scope}} -Listing {{#ref use-scope}}: A `use` statement only applies in the scope it’s in +Listing {{#ref use-scope}}: A `use` statement only applies in the scope it’s in. The compiler error shows that the shortcut no longer applies within the `customer` module: @@ -50,11 +50,11 @@ the `add_to_waitlist` function to achieve the same result, as in Listing {{#ref Filename: src/lib.cairo ```rust -{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_06/src/lib.cairo:unidiomatic-path}} +{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_08_unidiomatic_use/src/lib.cairo:unidiomatic-path}} ``` {{#label unidiomatic-use}} -Listing {{#ref unidiomatic-use}}: Bringing the `add_to_waitlist` function into scope with `use`, which is unidiomatic +Listing {{#ref unidiomatic-use}}: Bringing the `add_to_waitlist` function into scope with `use`, which is unidiomatic. Although both Listing {{#ref use-keyword}} and {{#ref unidiomatic-use}} accomplish the same task, Listing {{#ref use-keyword}} is the idiomatic way to bring a function into scope with `use`. Bringing the @@ -67,11 +67,11 @@ unclear as to where `add_to_waitlist` is defined. On the other hand, when bringing in structs, enums, traits, and other items with `use`, it’s idiomatic to specify the full path. Listing {{#ref idiomatic-use}} shows the idiomatic way to bring the core library’s `BitSize` trait into the scope, allowing to call `bits` method to retrieve the size in bits of a type. ```rust -{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_07/src/lib.cairo}} +{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_09_idiomatic_import/src/lib.cairo}} ``` {{#label idiomatic-use}} -Listing {{#ref idiomatic-use}}: Bringing `BitSize` trait into scope in an idiomatic way +Listing {{#ref idiomatic-use}}: Bringing `BitSize` trait into scope in an idiomatic way. There’s no strong reason behind this idiom: it’s just the convention that has emerged in the Rust community, and folks have gotten used to reading and writing Rust code this way. @@ -89,11 +89,11 @@ local name, or _alias_, for the type. Listing {{#ref as-keyword}} shows how you Filename: src/lib.cairo ```rust -{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_08/src/lib.cairo}} +{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_10_as_keyword/src/lib.cairo}} ``` {{#label as-keyword}} -Listing {{#ref as-keyword}}: Renaming a trait when it’s brought into scope with the `as` keyword +Listing {{#ref as-keyword}}: Renaming a trait when it’s brought into scope with the `as` keyword. Here, we brought `ArrayTrait` into scope with the alias `Arr`. We can now access the trait's methods with the `Arr` identifier. @@ -113,11 +113,11 @@ use module::{item1, item2, item3}; Here is an example where we import three structures from the same module: ```rust -{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_09/src/lib.cairo}} +{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_11_multiple_items/src/lib.cairo}} ``` {{#label multiple-imports}} -Listing {{#ref multiple-imports}}: Importing multiple items from the same module +Listing {{#ref multiple-imports}}: Importing multiple items from the same module. ## Re-exporting Names in Module Files @@ -131,11 +131,11 @@ For example, let's re-export the `add_to_waitlist` function in the restaurant ex Filename: src/lib.cairo ```rust -{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_10/src/lib.cairo:reexporting}} +{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_12_pub_use/src/lib.cairo:reexporting}} ``` {{#label reexporting}} -Listing {{#ref reexporting}}: Making a name available for any code to use from a new scope with `pub use` +Listing {{#ref reexporting}}: Making a name available for any code to use from a new scope with `pub use`. Before this change, external code would have to call the `add_to_waitlist` function by using the path `restaurant::front_of_house::hosting::add_to_waitlist()`. diff --git a/src/ch07-05-separating-modules-into-different-files.md b/src/ch07-05-separating-modules-into-different-files.md index 6e8bd4a21..14f23aa64 100644 --- a/src/ch07-05-separating-modules-into-different-files.md +++ b/src/ch07-05-separating-modules-into-different-files.md @@ -18,11 +18,11 @@ _src/front_of_house.cairo_ file. Filename: src/lib.cairo ```rust,noplayground -{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_11/src/lib.cairo:front-extraction}} +{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_13_front_extraction/src/lib.cairo:front-extraction}} ``` {{#label front-extraction}} -Listing {{#ref front-extraction}}: Declaring the `front_of_house` module whose body will be in _src/front_of_house.cairo_ +Listing {{#ref front-extraction}}: Declaring the `front_of_house` module whose body will be in _src/front_of_house.cairo_. Next, place the code that was in the curly brackets into a new file named _src/front_of_house.cairo_, as shown in Listing {{#ref module-foh}}. The compiler knows to look @@ -32,11 +32,11 @@ with the name `front_of_house`. Filename: src/front_of_house.cairo ```rust,noplayground -{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_07_12/src/lib.cairo}} +{{#include ../listings/ch07-managing-cairo-projects-with-packages-crates-and-modules/listing_14_front_definition/src/lib.cairo}} ``` {{#label module-foh}} -Listing {{#ref module-foh}}: Definitions inside the `front_of_house` module in _src/front_of_house.cairo_ +Listing {{#ref module-foh}}: Definitions inside the `front_of_house` module in _src/front_of_house.cairo_. Note that you only need to load a file using a `mod` declaration _once_ in your module tree. Once the compiler knows the file is part of the project (and knows diff --git a/src/title-page.md b/src/title-page.md index 97d3c9d16..a55ba33b9 100644 --- a/src/title-page.md +++ b/src/title-page.md @@ -2,6 +2,6 @@ By the Cairo Community and its [contributors](https://github.com/cairo-book/cairo-book.github.io). Special thanks to [StarkWare](https://starkware.co/) through [OnlyDust](https://www.onlydust.xyz/), and [Voyager](https://voyager.online/) for supporting the creation of this book. -This version of the text assumes you’re using the [Cairo Compiler](https://github.com/starkware-libs/cairo) [version 2.5.3](https://github.com/starkware-libs/cairo/releases). See the [Installation](ch01-01-installation.md) section of Chapter 1 to install or update Cairo. +This version of the text assumes you’re using the [Cairo Compiler](https://github.com/starkware-libs/cairo) [version 2.6.3](https://github.com/starkware-libs/cairo/releases). See the [Installation](ch01-01-installation.md) section of Chapter 1 to install or update Cairo. If you want to play around with Cairo code and see how it compiles into Sierra (Intermediate Representation) and CASM (Cairo Assembly), you can use [cairovm.codes](https://cairovm.codes/) playground.