diff --git a/.all-contributorsrc b/.all-contributorsrc
index a872eb5e2..54daa6dcc 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -123,6 +123,42 @@
"contributions": [
"code"
]
+ },
+ {
+ "login": "tiagofneto",
+ "name": "Tiago Neto",
+ "avatar_url": "https://avatars.githubusercontent.com/u/46165861?v=4",
+ "profile": "https://github.com/tiagofneto",
+ "contributions": [
+ "review"
+ ]
+ },
+ {
+ "login": "omahs",
+ "name": "omahs",
+ "avatar_url": "https://avatars.githubusercontent.com/u/73983677?v=4",
+ "profile": "https://github.com/omahs",
+ "contributions": [
+ "code"
+ ]
+ },
+ {
+ "login": "shramee",
+ "name": "Shramee Srivastav",
+ "avatar_url": "https://avatars.githubusercontent.com/u/11048263?v=4",
+ "profile": "http://shramee.me",
+ "contributions": [
+ "code"
+ ]
+ },
+ {
+ "login": "dbejarano820",
+ "name": "Daniel Bejarano",
+ "avatar_url": "https://avatars.githubusercontent.com/u/58019353?v=4",
+ "profile": "https://github.com/dbejarano820",
+ "contributions": [
+ "code"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/.github/workflows/cairo-verify/action.yml b/.github/workflows/cairo-verify/action.yml
new file mode 100644
index 000000000..5bbe4ea77
--- /dev/null
+++ b/.github/workflows/cairo-verify/action.yml
@@ -0,0 +1,19 @@
+name: Cairo Verify
+
+description: Run the cairo-verify tools on all cairo programs in the book.
+
+runs:
+ using: composite
+ steps:
+ - uses: actions/checkout@v3
+ - uses: software-mansion/setup-scarb@v1
+ with:
+ scarb-version: "0.7.0"
+
+ - name: Install cairo-verify
+ run: cargo install --path cairo-verify --locked
+ shell: bash
+
+ - name: Run cairo-verify and generate summary
+ run: cairo-verify >> $GITHUB_STEP_SUMMARY
+ shell: bash
diff --git a/.github/workflows/install-mdbook/action.yml b/.github/workflows/install-mdbook/action.yml
index bb582001b..438b2116c 100644
--- a/.github/workflows/install-mdbook/action.yml
+++ b/.github/workflows/install-mdbook/action.yml
@@ -7,13 +7,13 @@ runs:
steps:
# The --locked flag is important for reproducible builds.
- name: Install mdbook
- run: cargo install mdbook --locked --version 0.4.28
+ run: cargo install mdbook --locked --version 0.4.31
shell: bash
- name: Install mdbook-i18n-helpers
run: cargo install mdbook-i18n-helpers --locked --version 0.1.0
shell: bash
- - name: Install cairo programs verifier
+ - name: Install mdbook-cairo preprocessor
run: cargo install --path mdbook-cairo --locked
shell: bash
diff --git a/.github/workflows/mdbook.yml b/.github/workflows/mdbook.yml
index f02c9a503..99d85c812 100644
--- a/.github/workflows/mdbook.yml
+++ b/.github/workflows/mdbook.yml
@@ -36,6 +36,9 @@ jobs:
- name: Setup Rust cache
uses: ./.github/workflows/setup-rust-cache
+ - name: Cairo Verify
+ uses: ./.github/workflows/cairo-verify
+
- name: Install mdbook
uses: ./.github/workflows/install-mdbook
@@ -43,26 +46,27 @@ jobs:
run: |
mdbook build -d book
+ - name: Copy WASM-Cairo pkg
+ run: |
+ cp -r theme/pkg book
+ cp -r theme/js book
+
- name: Build all translations
run: |
for po_lang in $(cat ./LANGUAGES); do
echo "::group::Building $po_lang translation"
MDBOOK_BOOK__LANGUAGE=$po_lang \
mdbook build -d book/$po_lang
- mv book/$po_lang/html book/html/$po_lang
echo "::endgroup::"
done
- # - name: Verify Cairo programs
- # uses: ./.github/workflows/verify-cairo-programs
-
- name: Setup Pages
uses: actions/configure-pages@v3
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
- path: ./book/html
+ path: ./book
- name: Deploy to GitHub Pages
id: deployment
diff --git a/.github/workflows/verify-cairo-programs/action.yml b/.github/workflows/verify-cairo-programs/action.yml
deleted file mode 100644
index 1e727bf2a..000000000
--- a/.github/workflows/verify-cairo-programs/action.yml
+++ /dev/null
@@ -1,24 +0,0 @@
-name: Verify Cairo programs compilation
-
-description: Verify if all Cairo programs extracted from markdown can be compiled.
-
-runs:
- using: composite
- steps:
- - name: Copy Cairo program verifier script
- shell: bash
- run: |
- cp mdbook-cairo/scripts/cairo_programs_verifier.sh book/cairo/cairo-programs/
-
- - name: Verify Cairo programs
- uses: addnab/docker-run-action@v3
- with:
- image: starknet/cairo:1.1.0
- options: -v ${{ github.workspace }}/book/cairo/cairo-programs:/cairo
- run: |
- sh /cairo/cairo_programs_verifier.sh false > /cairo/summary.md
-
- - name: Generate job summary
- shell: bash
- run: cat book/cairo/cairo-programs/summary.md >> $GITHUB_STEP_SUMMARY
- if: always()
diff --git a/.github/workflows/verify_programs.yml b/.github/workflows/verify_programs.yml
new file mode 100644
index 000000000..7ed1432c1
--- /dev/null
+++ b/.github/workflows/verify_programs.yml
@@ -0,0 +1,30 @@
+name: Verify Cairo programs compilation
+
+on:
+ pull_request:
+ branches:
+ - main
+
+jobs:
+ compile_and_verify:
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v3
+
+ - name: Setup Scarb
+ uses: software-mansion/setup-scarb@v1
+ with:
+ scarb-version: "0.7.0"
+
+ - name: Setup Rust cache
+ uses: ./.github/workflows/setup-rust-cache
+
+ - name: Install cairo-verify
+ run: cargo install --path cairo-verify --locked
+ shell: bash
+
+ - name: Run cairo-verify and generate summary
+ run: cairo-verify >> $GITHUB_STEP_SUMMARY
+ shell: bash
diff --git a/.github/workflows/verify_programs.yml.old b/.github/workflows/verify_programs.yml.old
deleted file mode 100644
index 0303d9925..000000000
--- a/.github/workflows/verify_programs.yml.old
+++ /dev/null
@@ -1,42 +0,0 @@
-name: Verify Cairo programs compilation
-
-on:
- pull_request:
- branches:
- - main
-
-jobs:
- compile_and_verify:
- runs-on: ubuntu-latest
-
- steps:
- - name: Checkout
- uses: actions/checkout@v3
-
- - name: Setup Rust cache
- uses: ./.github/workflows/setup-rust-cache
-
- - name: Install mdbook
- uses: ./.github/workflows/install-mdbook
-
- - name: Build in English
- run: |
- mdbook build -d book
-
- - name: Copy Cairo program verifier script
- run: |
- cp mdbook-cairo/scripts/cairo_programs_verifier.sh book/cairo/cairo-programs/
- shell: bash
-
- - name: Verify Cairo programs
- uses: addnab/docker-run-action@v3
- with:
- image: starknet/cairo:1.1.0
- options: -v ${{ github.workspace }}/book/cairo/cairo-programs:/cairo
- run: |
- sh /cairo/cairo_programs_verifier.sh false > /cairo/summary.md
-
- - name: Generate job summary
- run: cat book/cairo/cairo-programs/summary.md >> $GITHUB_STEP_SUMMARY
- shell: bash
- if: always()
diff --git a/.gitignore b/.gitignore
index f1797da84..e9cb13199 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ output
# Editors tmp files.
*~
+.idea/
diff --git a/.tool-versions b/.tool-versions
new file mode 100644
index 000000000..2175a337d
--- /dev/null
+++ b/.tool-versions
@@ -0,0 +1 @@
+scarb 0.7.0
diff --git a/Cargo.lock b/Cargo.lock
index e4fdc74be..5a9f8d79d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -13,9 +13,9 @@ dependencies = [
[[package]]
name = "aho-corasick"
-version = "1.0.1"
+version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "67fc08ce920c31afb70f013dcce1bfc3a3195de6a228474e45e1f145b36f8d04"
+checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41"
dependencies = [
"memchr",
]
@@ -33,6 +33,12 @@ dependencies = [
"url",
]
+[[package]]
+name = "android-tzdata"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
+
[[package]]
name = "android_system_properties"
version = "0.1.5"
@@ -59,15 +65,15 @@ dependencies = [
[[package]]
name = "anstyle"
-version = "1.0.0"
+version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d"
+checksum = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd"
[[package]]
name = "anstyle-parse"
-version = "0.2.0"
+version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e765fd216e48e067936442276d1d57399e37bce53c264d6fefbe298080cb57ee"
+checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333"
dependencies = [
"utf8parse",
]
@@ -97,6 +103,17 @@ version = "1.0.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
+[[package]]
+name = "atty"
+version = "0.2.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
+dependencies = [
+ "hermit-abi 0.1.19",
+ "libc",
+ "winapi",
+]
+
[[package]]
name = "autocfg"
version = "1.1.0"
@@ -111,9 +128,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
[[package]]
name = "base64"
-version = "0.21.0"
+version = "0.21.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a"
+checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d"
[[package]]
name = "bitflags"
@@ -132,9 +149,9 @@ dependencies = [
[[package]]
name = "bstr"
-version = "1.4.0"
+version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c3d4260bcc2e8fc9df1eac4919a720effeb63a3f0952f5bf4944adfa18897f09"
+checksum = "a246e68bb43f6cd9db24bea052a53e40405417c5fb372e3d1a8a7f770a564ef5"
dependencies = [
"memchr",
"once_cell",
@@ -144,9 +161,9 @@ dependencies = [
[[package]]
name = "bumpalo"
-version = "3.12.2"
+version = "3.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3c6ed94e98ecff0c12dd1b04c15ec0d7d9458ca8fe806cea6f12954efe74c63b"
+checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1"
[[package]]
name = "byteorder"
@@ -160,6 +177,21 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be"
+[[package]]
+name = "cairo-verify"
+version = "0.1.0"
+dependencies = [
+ "clap",
+ "colored",
+ "env_logger",
+ "indicatif",
+ "lazy_static",
+ "log",
+ "regex",
+ "serde",
+ "walkdir",
+]
+
[[package]]
name = "cc"
version = "1.0.79"
@@ -174,30 +206,32 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
-version = "0.4.24"
+version = "0.4.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4e3c5919066adf22df73762e50cffcde3a758f2a848b113b586d1f86728b673b"
+checksum = "ec837a71355b28f6556dbd569b37b3f363091c0bd4b2e735674521b4c5fd9bc5"
dependencies = [
+ "android-tzdata",
"iana-time-zone",
- "num-integer",
"num-traits",
"winapi",
]
[[package]]
name = "clap"
-version = "4.2.7"
+version = "4.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "34d21f9bf1b425d2968943631ec91202fe5e837264063503708b83013f8fc938"
+checksum = "2686c4115cb0810d9a984776e197823d08ec94f176549a89a9efded477c456dc"
dependencies = [
"clap_builder",
+ "clap_derive",
+ "once_cell",
]
[[package]]
name = "clap_builder"
-version = "4.2.7"
+version = "4.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "914c8c79fb560f238ef6429439a30023c862f7a28e688c58f7203f12b29970bd"
+checksum = "2e53afce1efce6ed1f633cf0e57612fe51db54a1ee4fd8f8503d078fe02d69ae"
dependencies = [
"anstream",
"anstyle",
@@ -210,18 +244,30 @@ dependencies = [
[[package]]
name = "clap_complete"
-version = "4.2.3"
+version = "4.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1594fe2312ec4abf402076e407628f5c313e54c32ade058521df4ee34ecac8a8"
+checksum = "7f6b5c519bab3ea61843a7923d074b04245624bb84a64a8c150f5deb014e388b"
dependencies = [
"clap",
]
+[[package]]
+name = "clap_derive"
+version = "4.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b8cd2b2a819ad6eec39e8f1d6b53001af1e5469f8c177579cdaeb313115b825f"
+dependencies = [
+ "heck",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.18",
+]
+
[[package]]
name = "clap_lex"
-version = "0.4.1"
+version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1"
+checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"
[[package]]
name = "colorchoice"
@@ -229,6 +275,30 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
+[[package]]
+name = "colored"
+version = "2.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd"
+dependencies = [
+ "atty",
+ "lazy_static",
+ "winapi",
+]
+
+[[package]]
+name = "console"
+version = "0.15.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c926e00cc70edefdc64d3a5ff31cc65bb97a3460097762bd23afb4d8145fccf8"
+dependencies = [
+ "encode_unicode",
+ "lazy_static",
+ "libc",
+ "unicode-width",
+ "windows-sys 0.45.0",
+]
+
[[package]]
name = "core-foundation-sys"
version = "0.8.4"
@@ -237,9 +307,9 @@ checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
[[package]]
name = "cpufeatures"
-version = "0.2.7"
+version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3e4c1eaa2012c47becbbad2ab175484c2a84d1185b566fb2cc5b8707343dfe58"
+checksum = "03e69e28e9f7f77debdedbaafa2866e1de9ba56df55a8bd7cfc724c25a09987c"
dependencies = [
"libc",
]
@@ -256,9 +326,9 @@ dependencies = [
[[package]]
name = "crossbeam-utils"
-version = "0.8.15"
+version = "0.8.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b"
+checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294"
dependencies = [
"cfg-if",
]
@@ -275,9 +345,9 @@ dependencies = [
[[package]]
name = "digest"
-version = "0.10.6"
+version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f"
+checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [
"block-buffer",
"crypto-common",
@@ -295,6 +365,12 @@ dependencies = [
"serde_json",
]
+[[package]]
+name = "encode_unicode"
+version = "0.3.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
+
[[package]]
name = "env_logger"
version = "0.10.0"
@@ -358,9 +434,9 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "form_urlencoded"
-version = "1.1.0"
+version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8"
+checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652"
dependencies = [
"percent-encoding",
]
@@ -408,7 +484,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.15",
+ "syn 2.0.18",
]
[[package]]
@@ -450,9 +526,9 @@ dependencies = [
[[package]]
name = "getrandom"
-version = "0.2.9"
+version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4"
+checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
dependencies = [
"cfg-if",
"libc",
@@ -536,6 +612,21 @@ dependencies = [
"http",
]
+[[package]]
+name = "heck"
+version = "0.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
+
+[[package]]
+name = "hermit-abi"
+version = "0.1.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
+dependencies = [
+ "libc",
+]
+
[[package]]
name = "hermit-abi"
version = "0.2.6"
@@ -631,9 +722,9 @@ dependencies = [
[[package]]
name = "iana-time-zone"
-version = "0.1.56"
+version = "0.1.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0722cd7114b7de04316e7ea5456a0bbb20e4adb46fd27a3697adb812cff0f37c"
+checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613"
dependencies = [
"android_system_properties",
"core-foundation-sys",
@@ -654,9 +745,9 @@ dependencies = [
[[package]]
name = "idna"
-version = "0.3.0"
+version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6"
+checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c"
dependencies = [
"unicode-bidi",
"unicode-normalization",
@@ -689,6 +780,19 @@ dependencies = [
"hashbrown",
]
+[[package]]
+name = "indicatif"
+version = "0.17.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8ff8cc23a7393a397ed1d7f56e6365cba772aba9f9912ab968b03043c395d057"
+dependencies = [
+ "console",
+ "instant",
+ "number_prefix",
+ "portable-atomic",
+ "unicode-width",
+]
+
[[package]]
name = "inotify"
version = "0.9.6"
@@ -720,9 +824,9 @@ dependencies = [
[[package]]
name = "io-lifetimes"
-version = "1.0.10"
+version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9c66c74d2ae7e79a5a8f7ac924adbe38ee42a859c6539ad869eb51f0b52dc220"
+checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2"
dependencies = [
"hermit-abi 0.3.1",
"libc",
@@ -749,9 +853,9 @@ checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6"
[[package]]
name = "js-sys"
-version = "0.3.62"
+version = "0.3.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "68c16e1bfd491478ab155fd8b4896b86f9ede344949b641e61501e07c2b8b4d5"
+checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a"
dependencies = [
"wasm-bindgen",
]
@@ -784,21 +888,21 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
-version = "0.2.144"
+version = "0.2.146"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1"
+checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b"
[[package]]
name = "linux-raw-sys"
-version = "0.3.7"
+version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ece97ea872ece730aed82664c424eb4c8291e1ff2480247ccf7409044bc6479f"
+checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519"
[[package]]
name = "lock_api"
-version = "0.4.9"
+version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df"
+checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16"
dependencies = [
"autocfg",
"scopeguard",
@@ -806,12 +910,9 @@ dependencies = [
[[package]]
name = "log"
-version = "0.4.17"
+version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
-dependencies = [
- "cfg-if",
-]
+checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4"
[[package]]
name = "mac"
@@ -841,9 +942,9 @@ dependencies = [
[[package]]
name = "mdbook"
-version = "0.4.29"
+version = "0.4.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d317294c6e3d7f9d2e60dfd20932bec627f86c76ec101a5da0110fc0fbe06266"
+checksum = "7b67ee4a744f36e6280792016c17e69921b51df357181d1eb17d620fcc3609f3"
dependencies = [
"ammonia",
"anyhow",
@@ -875,14 +976,14 @@ dependencies = [
[[package]]
name = "mdbook-cairo"
-version = "0.1.0"
+version = "0.2.0"
dependencies = [
+ "clap",
"lazy_static",
"mdbook",
- "pulldown-cmark",
"regex",
- "serde",
- "serde_derive",
+ "semver",
+ "serde_json",
]
[[package]]
@@ -909,14 +1010,14 @@ dependencies = [
[[package]]
name = "mio"
-version = "0.8.6"
+version = "0.8.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9"
+checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2"
dependencies = [
"libc",
"log",
"wasi",
- "windows-sys 0.45.0",
+ "windows-sys 0.48.0",
]
[[package]]
@@ -927,9 +1028,9 @@ checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54"
[[package]]
name = "notify"
-version = "5.1.0"
+version = "5.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "58ea850aa68a06e48fdb069c0ec44d0d64c8dbffa49bf3b6f7f0a901fdea1ba9"
+checksum = "729f63e1ca555a43fe3efa4f3efdf4801c479da85b432242a7b726f353c88486"
dependencies = [
"bitflags",
"crossbeam-channel",
@@ -940,7 +1041,7 @@ dependencies = [
"libc",
"mio",
"walkdir",
- "windows-sys 0.42.0",
+ "windows-sys 0.45.0",
]
[[package]]
@@ -953,16 +1054,6 @@ dependencies = [
"notify",
]
-[[package]]
-name = "num-integer"
-version = "0.1.45"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
-dependencies = [
- "autocfg",
- "num-traits",
-]
-
[[package]]
name = "num-traits"
version = "0.2.15"
@@ -982,11 +1073,17 @@ dependencies = [
"libc",
]
+[[package]]
+name = "number_prefix"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
+
[[package]]
name = "once_cell"
-version = "1.17.1"
+version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
+checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
[[package]]
name = "opener"
@@ -1010,28 +1107,28 @@ dependencies = [
[[package]]
name = "parking_lot_core"
-version = "0.9.7"
+version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521"
+checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447"
dependencies = [
"cfg-if",
"libc",
- "redox_syscall 0.2.16",
+ "redox_syscall 0.3.5",
"smallvec",
- "windows-sys 0.45.0",
+ "windows-targets 0.48.0",
]
[[package]]
name = "percent-encoding"
-version = "2.2.0"
+version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e"
+checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94"
[[package]]
name = "pest"
-version = "2.6.0"
+version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e68e84bfb01f0507134eac1e9b410a12ba379d064eab48c50ba4ce329a527b70"
+checksum = "f73935e4d55e2abf7f130186537b19e7a4abc886a0252380b59248af473a3fc9"
dependencies = [
"thiserror",
"ucd-trie",
@@ -1039,9 +1136,9 @@ dependencies = [
[[package]]
name = "pest_derive"
-version = "2.6.0"
+version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6b79d4c71c865a25a4322296122e3924d30bc8ee0834c8bfc8b95f7f054afbfb"
+checksum = "aef623c9bbfa0eedf5a0efba11a5ee83209c326653ca31ff019bec3a95bfff2b"
dependencies = [
"pest",
"pest_generator",
@@ -1049,22 +1146,22 @@ dependencies = [
[[package]]
name = "pest_generator"
-version = "2.6.0"
+version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6c435bf1076437b851ebc8edc3a18442796b30f1728ffea6262d59bbe28b077e"
+checksum = "b3e8cba4ec22bada7fc55ffe51e2deb6a0e0db2d0b7ab0b103acc80d2510c190"
dependencies = [
"pest",
"pest_meta",
"proc-macro2",
"quote",
- "syn 2.0.15",
+ "syn 2.0.18",
]
[[package]]
name = "pest_meta"
-version = "2.6.0"
+version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "745a452f8eb71e39ffd8ee32b3c5f51d03845f99786fa9b68db6ff509c505411"
+checksum = "a01f71cb40bd8bb94232df14b946909e14660e33fc05db3e50ae2a82d7ea0ca0"
dependencies = [
"once_cell",
"pest",
@@ -1126,7 +1223,7 @@ checksum = "39407670928234ebc5e6e580247dd567ad73a3578460c5990f9503df207e8f07"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.15",
+ "syn 2.0.18",
]
[[package]]
@@ -1141,6 +1238,12 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
+[[package]]
+name = "portable-atomic"
+version = "1.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "767eb9f07d4a5ebcb39bbf2d452058a93c011373abf6832e24194a1c3f004794"
+
[[package]]
name = "ppv-lite86"
version = "0.2.17"
@@ -1155,18 +1258,18 @@ checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
[[package]]
name = "proc-macro2"
-version = "1.0.56"
+version = "1.0.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435"
+checksum = "dec2b086b7a862cf4de201096214fa870344cf922b2b30c167badb3af3195406"
dependencies = [
"unicode-ident",
]
[[package]]
name = "pulldown-cmark"
-version = "0.9.2"
+version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2d9cc634bc78768157b5cbfe988ffcd1dcba95cd2b2f03a88316c08c6d00ed63"
+checksum = "77a1a2f1f0a7ecff9c31abbe177637be0e97a0aef46cf8738ece09327985d998"
dependencies = [
"bitflags",
"memchr",
@@ -1175,9 +1278,9 @@ dependencies = [
[[package]]
name = "quote"
-version = "1.0.27"
+version = "1.0.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8f4f29d145265ec1c483c7c654450edde0bfe043d3938d6972630663356d9500"
+checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488"
dependencies = [
"proc-macro2",
]
@@ -1232,11 +1335,11 @@ dependencies = [
[[package]]
name = "regex"
-version = "1.8.1"
+version = "1.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "af83e617f331cc6ae2da5443c602dfa5af81e517212d9d611a5b3ba1777b5370"
+checksum = "d0ab3ca65655bb1e41f2a8c8cd662eb4fb035e67c3f78da1d61dffe89d07300f"
dependencies = [
- "aho-corasick 1.0.1",
+ "aho-corasick 1.0.2",
"memchr",
"regex-syntax",
]
@@ -1249,15 +1352,15 @@ checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
[[package]]
name = "regex-syntax"
-version = "0.7.1"
+version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a5996294f19bd3aae0453a862ad728f60e6600695733dd5df01da90c54363a3c"
+checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78"
[[package]]
name = "rustix"
-version = "0.37.19"
+version = "0.37.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d"
+checksum = "b96e891d04aa506a6d1f318d2771bcb1c7dfda84e126660ace067c9b474bb2c0"
dependencies = [
"bitflags",
"errno",
@@ -1273,7 +1376,7 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d194b56d58803a43635bdc398cd17e383d6f71f9182b9a192c127ca42494a59b"
dependencies = [
- "base64 0.21.0",
+ "base64 0.21.2",
]
[[package]]
@@ -1303,31 +1406,37 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
+[[package]]
+name = "semver"
+version = "1.0.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed"
+
[[package]]
name = "serde"
-version = "1.0.163"
+version = "1.0.164"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2"
+checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
-version = "1.0.163"
+version = "1.0.164"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e"
+checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.15",
+ "syn 2.0.18",
]
[[package]]
name = "serde_json"
-version = "1.0.96"
+version = "1.0.97"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1"
+checksum = "bdf3bf93142acad5821c99197022e170842cdbc1c30482b98750c688c640842a"
dependencies = [
"itoa",
"ryu",
@@ -1359,9 +1468,9 @@ dependencies = [
[[package]]
name = "sha2"
-version = "0.10.6"
+version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0"
+checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8"
dependencies = [
"cfg-if",
"cpufeatures",
@@ -1450,9 +1559,9 @@ dependencies = [
[[package]]
name = "syn"
-version = "2.0.15"
+version = "2.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822"
+checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e"
dependencies = [
"proc-macro2",
"quote",
@@ -1461,15 +1570,16 @@ dependencies = [
[[package]]
name = "tempfile"
-version = "3.5.0"
+version = "3.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998"
+checksum = "31c0432476357e58790aaa47a8efb0c5138f137343f3b5f23bd36a27e3b0a6d6"
dependencies = [
+ "autocfg",
"cfg-if",
"fastrand",
"redox_syscall 0.3.5",
"rustix",
- "windows-sys 0.45.0",
+ "windows-sys 0.48.0",
]
[[package]]
@@ -1519,7 +1629,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.15",
+ "syn 2.0.18",
]
[[package]]
@@ -1549,9 +1659,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
-version = "1.28.1"
+version = "1.28.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0aa32867d44e6f2ce3385e89dceb990188b8bb0fb25b0cf576647a6f98ac5105"
+checksum = "94d7b1cfd2aa4011f2de74c2c4c63665e27a71006b0a192dcd2710272e73dfa2"
dependencies = [
"autocfg",
"bytes",
@@ -1572,7 +1682,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.15",
+ "syn 2.0.18",
]
[[package]]
@@ -1708,9 +1818,9 @@ checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460"
[[package]]
name = "unicode-ident"
-version = "1.0.8"
+version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
+checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0"
[[package]]
name = "unicode-normalization"
@@ -1721,11 +1831,17 @@ dependencies = [
"tinyvec",
]
+[[package]]
+name = "unicode-width"
+version = "0.1.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
+
[[package]]
name = "url"
-version = "2.3.1"
+version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643"
+checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb"
dependencies = [
"form_urlencoded",
"idna",
@@ -1762,11 +1878,10 @@ dependencies = [
[[package]]
name = "want"
-version = "0.3.0"
+version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0"
+checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e"
dependencies = [
- "log",
"try-lock",
]
@@ -1808,9 +1923,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-bindgen"
-version = "0.2.85"
+version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5b6cb788c4e39112fbe1822277ef6fb3c55cd86b95cb3d3c4c1c9597e4ac74b4"
+checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
@@ -1818,24 +1933,24 @@ dependencies = [
[[package]]
name = "wasm-bindgen-backend"
-version = "0.2.85"
+version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "35e522ed4105a9d626d885b35d62501b30d9666283a5c8be12c14a8bdafe7822"
+checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd"
dependencies = [
"bumpalo",
"log",
"once_cell",
"proc-macro2",
"quote",
- "syn 2.0.15",
+ "syn 2.0.18",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
-version = "0.2.85"
+version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "358a79a0cb89d21db8120cbfb91392335913e4890665b1a7981d9e956903b434"
+checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@@ -1843,22 +1958,22 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
-version = "0.2.85"
+version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4783ce29f09b9d93134d41297aded3a712b7b979e9c6f28c32cb88c973a94869"
+checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.15",
+ "syn 2.0.18",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
-version = "0.2.85"
+version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a901d592cafaa4d711bc324edfaff879ac700b19c3dfd60058d2b445be2691eb"
+checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1"
[[package]]
name = "winapi"
@@ -1900,21 +2015,6 @@ dependencies = [
"windows-targets 0.48.0",
]
-[[package]]
-name = "windows-sys"
-version = "0.42.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
-dependencies = [
- "windows_aarch64_gnullvm 0.42.2",
- "windows_aarch64_msvc 0.42.2",
- "windows_i686_gnu 0.42.2",
- "windows_i686_msvc 0.42.2",
- "windows_x86_64_gnu 0.42.2",
- "windows_x86_64_gnullvm 0.42.2",
- "windows_x86_64_msvc 0.42.2",
-]
-
[[package]]
name = "windows-sys"
version = "0.45.0"
diff --git a/Cargo.toml b/Cargo.toml
index 68d56b2a4..0c7ff2e0a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,4 +1,5 @@
[workspace]
members = [
"mdbook-cairo",
-]
+ "cairo-verify"
+]
\ No newline at end of file
diff --git a/README.md b/README.md
index cb94bc086..da8b3fe21 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,9 @@
-[](#contributors)
+
+[](#contributors)
+
The Cairo Programming Language Book
@@ -34,6 +36,7 @@ This repository contains the source of "The Cairo Programming Language" book, a
`sudo apt install gettext`.
3. Clone this repository.
+
4. Install mdbook-cairo [for Cairo code blocks](#work-locally-cairo-programs-verification)
```
cargo install --path mdbook-cairo
@@ -69,47 +72,89 @@ To work with translations, those are the steps to update the translated content:
The translation work is inspired from [Comprehensive Rust repository](https://github.com/google/comprehensive-rust/blob/main/TRANSLATIONS.md).
#### Initiate a new translation for your language
+
If you wish to initiate a new translation for your language without running a local server, consider the following tips:
+
- Execute the command `./translations.sh new xx` (replace `xx` with your language code). This method can generate the `xx.po` file of your language for you.
- To update your `xx.po` file, execute the command `./translations.sh xx` (replace `xx` with your language code), as mentioned in the previous chapter.
- If the `xx.po` file already exists (which means you are not initiating a new translation), you should not run this command.
### Work locally (Cairo programs verification)
-The current book has a mdbook backend to extract Cairo programs from the markdown sources. Currently, for each program it test two things: if it compiles and if it adheres to the `cairo-format` coding style. You can run this locally and test if a Cairo program you have written in the book passes these tests.
+The `cairo-verify` tool is designed to wrap all cairo and starknet plugins for quickly verifying cairo programs.
-The mdbook-cairo backend is working as following:
+#### Setup
-1. It takes every code blocks in the markdown source and parse all of them.
-2. Code blocks with a main function `fn main()` are extracted into Cairo programs.
-3. The extracted programs are named based on the chapter they belong to, and a consecutive
- number of the `fn main()` found in the chapter.
-4. If you have a code block with a `fn main()` function that you know does not compile,
- you can indicate it by adding the `does_not_compile` attribute to the code block, like this:
+Firstly, you need to have `scarb` resolved in your path:
- ````
- ```rust,does_not_compile
- fn main() {
- }
- ```
- ````
+They should be available after installing cairo, see [here](https://cairo-book.github.io/ch01-01-installation.html) for more details.
- This main function will still count in the consecutive number of `fn main()` in the chapter file,
- but will not be extracted into a Cairo program.
+To run the `cairo-verify` helper tool, ensure that you are at the root of the repository (same directory of this `README.md` file), and run:
-5. Alternatively, if you want to disable the format check using `cairo-format`,
- you can add the `ignore_format` attribute to the code block, like this:
+```sh
+cargo run --bin cairo-verify
+```
- ````
- ```rust,ignore_format
- fn main() {
- }
- ```
- ````
+Alternatively, you can also install the tool with:
+
+```sh
+cargo install --path cairo-verify
+```
+
+#### Usage
+
+The tool scans for all `*.cairo` files in the specified directory and performs the following actions:
+
+For a Starknet contract:
+
+- `scarb build`
+- If it has tests: `scarb test`
-To run the CI locally, ensure that you are at the root of the repository (same directory of this `README.md` file), and run:
+Cairo program:
-`bash mdbook-cairo/scripts/cairo_local_verify.sh`
+- If it has a `main` function: `scarb cairo-run`
+- Else, `scarb build`
+- If it has tests: `scarb test`
+- `scarb fmt -c`
+
+To specify which tests to run, you can add a comment at the top of your file with the following format:
+
+```rust
+// TAG:
+// TAGS: ,
+```
+
+Here is a list of available tags:
+
+- `does_not_compile`: don't run `scarb build`
+- `does_not_run`: don't run `scarb cairo-run`
+- `ignore_fmt`: don't run `scarb fmt`
+- `tests_fail`: don't run `scarb test`
+
+You can skip and ignore a specific test by adding the corresponding flag:
+
+```sh
+$ cairo-verify --help
+
+Usage: cairo-verify [OPTIONS]
+
+Options:
+ -p, --path The path to explore for *.cairo files [default: ./listings]
+ -v, --verbose Print more information
+ -q, --quiet Only print final results
+ -f, --formats-skip Skip cairo-format checks
+ -s, --starknet-skip Skip starknet-compile checks
+ -c, --compile-skip Skip cairo-compile checks
+ -r, --run-skip Skip cairo-run checks
+ -t, --test-skip Skip cairo-test checks
+ --file Specify file to check
+ -h, --help Print help
+ -V, --version Print version
+```
+
+In CI, it's preferable to reduce output, so run `cairo-verify` with the `--quiet` flag.
+
+The mdbook-cairo is a mdbook preprocessor that only removes the `// TAG` lines in code blocks.
## Contributors
@@ -133,6 +178,12 @@ To run the CI locally, ensure that you are at the root of the repository (same d
 julio4 💻 🔧 |
 Haresh Gedia 📖 |
 Darlington Nnam 💻 |
+  Tiago Neto 👀 |
+  omahs 💻 |
+
+
+  Shramee Srivastav 💻 |
+  Daniel Bejarano 💻 |
diff --git a/Scarb.toml b/Scarb.toml
index dde7cb8f1..46b75662b 100644
--- a/Scarb.toml
+++ b/Scarb.toml
@@ -1,5 +1,5 @@
[package]
-name = "cairo-book"
+name = "cairo_book"
version = "0.1.0"
# Only required to have LS enabled in this directory.
diff --git a/book.toml b/book.toml
index dc64bb550..9e8fef44a 100644
--- a/book.toml
+++ b/book.toml
@@ -8,13 +8,13 @@ title = "The Cairo Programming Language"
[build]
extra-watch-dirs = ["po"]
-[preprocessor.gettext]
+[preprocessor.cairo]
after = ["links"]
+[preprocessor.gettext]
+after = ["cairo"]
+
[output.html]
git-repository-url = "https://github.com/cairo-book/cairo-book.github.io/"
edit-url-template = "https://github.com/cairo-book/cairo-book.github.io/edit/main/{path}"
-playground.runnable = false
-
-[output.cairo]
-output-dir = "cairo-programs"
+playground.runnable = true
diff --git a/cairo-verify/Cargo.toml b/cairo-verify/Cargo.toml
new file mode 100644
index 000000000..68db90c33
--- /dev/null
+++ b/cairo-verify/Cargo.toml
@@ -0,0 +1,19 @@
+[package]
+name = "cairo-verify"
+version = "0.1.0"
+edition = "2021"
+license = "MIT"
+authors = ["Cairo-book community"]
+description = "A tool for running adequate cairo tests tools on cairo files."
+repository = "https://github.com/cairo-book/cairo-book.github.io"
+
+[dependencies]
+clap = { version = "4.3.4", features = ["derive"] }
+colored = "2.0.0"
+env_logger = "0.10.0"
+indicatif = "0.17.5"
+lazy_static = "1.4.0"
+log = "0.4.19"
+regex = "1.8.4"
+serde = "1.0.164"
+walkdir = "2.3.3"
diff --git a/cairo-verify/README.md b/cairo-verify/README.md
new file mode 100644
index 000000000..9a6c6ab82
--- /dev/null
+++ b/cairo-verify/README.md
@@ -0,0 +1,7 @@
+# Cli tool to verify cairo programs
+
+This tool is designed to wrap all cairo and starknet plugins for quickly verifying cairo programs.
+
+# Useful links:
+
+- https://github.com/cairo-book/cairo-book.github.io/pull/209
\ No newline at end of file
diff --git a/cairo-verify/src/cmd.rs b/cairo-verify/src/cmd.rs
new file mode 100644
index 000000000..46e9ee99d
--- /dev/null
+++ b/cairo-verify/src/cmd.rs
@@ -0,0 +1,57 @@
+use std::process::Command;
+
+pub enum Cmd {
+ ScarbFormat(),
+ ScarbBuild(),
+ ScarbCairoRun(),
+ ScarbTest(),
+}
+
+impl Cmd {
+ pub fn as_str(&self) -> String {
+ let command = match self {
+ Cmd::ScarbFormat() => "fmt",
+ Cmd::ScarbBuild() => "build",
+ Cmd::ScarbCairoRun() => "cairo-run",
+ Cmd::ScarbTest() => "test",
+ };
+ command.into()
+ }
+
+ fn manifest_option(&self, manifest_path: &str) -> Vec {
+ vec!["--manifest-path".to_string(), manifest_path.to_string()]
+ }
+
+ fn args(&self) -> Vec<&str> {
+ match self {
+ Cmd::ScarbFormat() => vec!["-c"],
+ Cmd::ScarbBuild() => vec![],
+ Cmd::ScarbCairoRun() => vec!["--available-gas=20000000"],
+ Cmd::ScarbTest() => vec![],
+ }
+ }
+
+ pub fn test(&self, manifest_path: &str) -> Result<(), String> {
+ // Temporary workaround that compiles before trying to run
+ // Until Scarb does it by default.
+ if let Cmd::ScarbCairoRun() = self {
+ let mut command = Command::new("scarb");
+ command.args(self.manifest_option(manifest_path));
+ command.arg("build");
+
+ let _output = command.output().expect("Failed to execute scarb");
+ }
+ let mut command = Command::new("scarb");
+ command.args(self.manifest_option(manifest_path));
+ command.arg(self.as_str());
+ command.args(self.args());
+
+ let output = command.output().expect("Failed to execute scarb");
+
+ if !output.status.success() {
+ return Err(String::from_utf8_lossy(&output.stderr).to_string());
+ }
+
+ Ok(())
+ }
+}
diff --git a/cairo-verify/src/config.rs b/cairo-verify/src/config.rs
new file mode 100644
index 000000000..bd44b5654
--- /dev/null
+++ b/cairo-verify/src/config.rs
@@ -0,0 +1,56 @@
+use clap::Parser;
+use regex::Regex;
+
+#[derive(Parser, Debug)]
+#[command(author, version, about, long_about = None)]
+pub struct Config {
+ /// The path to explore for *.cairo files.
+ #[arg(short, long, default_value = "./listings")]
+ pub path: String,
+
+ /// Print more information.
+ #[arg(short, long)]
+ pub verbose: bool,
+
+ /// Only print final results.
+ #[arg(short, long)]
+ pub quiet: bool,
+
+ /// Skip cairo-format checks
+ #[arg(short, long)]
+ pub formats_skip: bool,
+
+ /// Skip starknet-compile checks
+ #[arg(short, long)]
+ pub starknet_skip: bool,
+
+ /// Skip cairo-compile checks
+ #[arg(short, long)]
+ pub compile_skip: bool,
+
+ /// Skip cairo-run checks
+ #[arg(short, long)]
+ pub run_skip: bool,
+
+ /// Skip cairo-test checks
+ #[arg(short, long)]
+ pub test_skip: bool,
+
+ /// Specify file to check
+ #[arg(long)]
+ pub file: Option,
+}
+
+/// Expected statement in a cairo program for it to be runnable.
+pub const STATEMENT_IS_RUNNABLE: &str = "fn main()";
+/// Expected statement in a starknet contract for it to compile.
+pub const STATEMENT_IS_CONTRACT: &str = "#[starknet::contract]";
+/// Expected statement in a cairo program containing tests.
+pub const STATEMENT_IS_TESTABLE: &str = "#[test]";
+/// Expected regex for tags
+const TAG_REGEX_PATTERN: &str = r"^//\s*TAG(S)?\s*(:)?\s*";
+
+lazy_static! {
+ pub static ref TAG_REGEX: Regex =
+ Regex::new(TAG_REGEX_PATTERN).expect("Failed to create TAG_REGEX");
+}
diff --git a/cairo-verify/src/error_sets.rs b/cairo-verify/src/error_sets.rs
new file mode 100644
index 000000000..3a688d197
--- /dev/null
+++ b/cairo-verify/src/error_sets.rs
@@ -0,0 +1,31 @@
+use crate::cmd::Cmd;
+use std::collections::HashSet;
+
+pub struct ErrorSets {
+ pub compile_errors: HashSet,
+ pub run_errors: HashSet,
+ pub test_errors: HashSet,
+ pub format_errors: HashSet,
+ pub starknet_errors: HashSet,
+}
+
+impl ErrorSets {
+ pub fn new() -> Self {
+ Self {
+ compile_errors: HashSet::new(),
+ run_errors: HashSet::new(),
+ test_errors: HashSet::new(),
+ format_errors: HashSet::new(),
+ starknet_errors: HashSet::new(),
+ }
+ }
+
+ pub fn get_mut_error_set(&mut self, cmd: &Cmd) -> &mut HashSet {
+ match cmd {
+ Cmd::ScarbFormat() => &mut self.format_errors,
+ Cmd::ScarbBuild() => &mut self.compile_errors,
+ Cmd::ScarbCairoRun() => &mut self.run_errors,
+ Cmd::ScarbTest() => &mut self.test_errors,
+ }
+ }
+}
diff --git a/cairo-verify/src/logger.rs b/cairo-verify/src/logger.rs
new file mode 100644
index 000000000..1bf9d798a
--- /dev/null
+++ b/cairo-verify/src/logger.rs
@@ -0,0 +1,43 @@
+use env_logger::Env;
+use indicatif::ProgressBar;
+use log::{Log, Metadata, Record};
+
+use crate::Config;
+
+struct ProgressBarLogger {
+ pb: ProgressBar,
+}
+
+impl Log for ProgressBarLogger {
+ fn enabled(&self, metadata: &Metadata) -> bool {
+ metadata.level() <= log::Level::Info
+ }
+
+ fn log(&self, record: &Record) {
+ if self.enabled(record.metadata()) {
+ self.pb.suspend(|| println!("{}", record.args()))
+ }
+ }
+
+ fn flush(&self) {}
+}
+
+pub fn setup(cfg: &Config, pb: ProgressBar) {
+ let env = Env::default()
+ .filter_or("APP_LOG", "info") // Default log level is "info"
+ .write_style_or("APP_LOG_STYLE", "always");
+
+ if cfg.verbose {
+ let logger = ProgressBarLogger { pb };
+ log::set_boxed_logger(Box::new(logger)).unwrap();
+ log::set_max_level(log::LevelFilter::max());
+ } else if cfg.quiet {
+ env_logger::Builder::from_env(env)
+ .filter(None, log::LevelFilter::Off)
+ .init();
+ } else {
+ let logger = ProgressBarLogger { pb };
+ log::set_boxed_logger(Box::new(logger)).unwrap();
+ log::set_max_level(log::LevelFilter::Error);
+ }
+}
diff --git a/cairo-verify/src/main.rs b/cairo-verify/src/main.rs
new file mode 100644
index 000000000..80470ea40
--- /dev/null
+++ b/cairo-verify/src/main.rs
@@ -0,0 +1,188 @@
+use clap::Parser;
+use colored::Colorize;
+use indicatif::ProgressBar;
+use log::error;
+use std::collections::HashSet;
+use std::fs::File;
+use std::io::{BufRead, BufReader};
+use std::sync::Mutex;
+
+#[macro_use]
+extern crate lazy_static;
+
+mod cmd;
+mod config;
+mod error_sets;
+mod logger;
+mod tags;
+mod utils;
+
+use crate::cmd::Cmd;
+use crate::config::Config;
+use crate::error_sets::ErrorSets;
+use crate::tags::Tags;
+use crate::utils::{clickable, find_scarb_manifests, print_error_table};
+
+lazy_static! {
+ static ref CFG: Config = Config::parse();
+}
+
+lazy_static! {
+ static ref ERRORS: Mutex = Mutex::new(ErrorSets::new());
+}
+
+fn main() {
+ let cfg = &*CFG;
+ let scarb_packages = find_scarb_manifests(cfg);
+
+ let pb = ProgressBar::new(scarb_packages.len() as u64);
+ logger::setup(cfg, pb.clone());
+
+ for file in scarb_packages {
+ process_file(&file);
+ if !cfg.quiet {
+ pb.inc(1);
+ }
+ }
+
+ pb.finish_and_clear();
+
+ let errors = ERRORS.lock().unwrap();
+ let total_errors = errors.compile_errors.len()
+ + errors.run_errors.len()
+ + errors.test_errors.len()
+ + errors.format_errors.len();
+
+ if total_errors > 0 {
+ println!("{}\n", " ==== RESULT === ".red().bold());
+
+ print_error_table(&errors.compile_errors, "Compile Errors");
+ print_error_table(&errors.run_errors, "Run Errors");
+ print_error_table(&errors.test_errors, "Test Errors");
+ print_error_table(&errors.format_errors, "Format Errors");
+
+ println!(
+ "{}",
+ format!("Total errors: {}", total_errors.to_string().red()).bold()
+ );
+
+ println!("\n{}", "Please review the errors above. Do not hesitate to ask for help by commenting on the issue on Github.".red().italic());
+ std::process::exit(1);
+ } else {
+ println!("\n{}\n", "ALL TESTS PASSED!".green().bold());
+ }
+}
+
+fn process_file(manifest_path: &str) {
+ let cfg = &*CFG;
+ let manifest_path_as_path = std::path::Path::new(manifest_path);
+ let file_path = manifest_path_as_path
+ .parent()
+ .unwrap()
+ .join("src/lib.cairo");
+ let file_path = file_path.to_str().unwrap();
+
+ let file =
+ File::open(file_path).unwrap_or_else(|_| panic!("Failed to open file {}", file_path));
+ let reader = BufReader::new(file);
+
+ // Parsed tags (if any)
+ let mut tags: HashSet = HashSet::new();
+ let mut in_tag_block = true;
+
+ // Program info
+ let mut should_be_runnable = false;
+ let mut should_be_testable = false;
+ let mut is_contract = false;
+
+ reader.lines().for_each(|line| {
+ if let Ok(line_contents) = line {
+ // Parse tags
+ if in_tag_block && config::TAG_REGEX.is_match(&line_contents) {
+ let line_contents = config::TAG_REGEX.replace(&line_contents, "");
+ let tags_in_line: Vec<&str> = line_contents
+ .trim()
+ .split(',')
+ .map(|tag| tag.trim())
+ .collect();
+
+ tags_in_line.iter().for_each(|tag| {
+ if let Some(tag_enum) = tags::Tags::from_str(tag) {
+ tags.insert(tag_enum);
+ }
+ });
+ } else {
+ // Stop parsing tags when we reach the first non-comment line
+ in_tag_block = false;
+ }
+
+ // Check for statements
+ is_contract |= line_contents.contains(config::STATEMENT_IS_CONTRACT);
+ should_be_runnable |= line_contents.contains(config::STATEMENT_IS_RUNNABLE);
+ should_be_testable |= line_contents.contains(config::STATEMENT_IS_TESTABLE);
+ }
+ });
+
+ // COMPILE / RUN CHECKS
+ if is_contract {
+ // This is a contract, it must pass starknet-compile
+ if !tags.contains(&Tags::DoesNotCompile) && !cfg.starknet_skip {
+ match Cmd::ScarbBuild().test(manifest_path) {
+ Ok(_) => {}
+ Err(e) => handle_error(e, file_path, Cmd::ScarbBuild()),
+ }
+ }
+ } else if should_be_runnable {
+ // This is a cairo program, it must pass cairo-run
+ if !tags.contains(&Tags::DoesNotRun)
+ && !tags.contains(&Tags::DoesNotCompile)
+ && !cfg.run_skip
+ {
+ match Cmd::ScarbCairoRun().test(manifest_path) {
+ Ok(_) => {}
+ Err(e) => handle_error(e, file_path, Cmd::ScarbCairoRun()),
+ }
+ }
+ } else {
+ // This is a cairo program, it must pass cairo-compile
+ if !tags.contains(&Tags::DoesNotCompile) && !cfg.compile_skip {
+ match Cmd::ScarbBuild().test(manifest_path) {
+ Ok(_) => {}
+ Err(e) => handle_error(e, file_path, Cmd::ScarbBuild()),
+ }
+ }
+ }
+
+ // TEST CHECKS
+ if should_be_testable && !cfg.test_skip && !tags.contains(&Tags::FailingTests) {
+ // This program has tests, it must pass cairo-test
+ match Cmd::ScarbTest().test(manifest_path) {
+ Ok(_) => {}
+ Err(e) => handle_error(e, file_path, Cmd::ScarbTest()),
+ }
+ }
+
+ // FORMAT CHECKS
+ if !tags.contains(&Tags::IgnoreFormat) && !cfg.formats_skip {
+ // This program must pass cairo-format
+ match Cmd::ScarbFormat().test(manifest_path) {
+ Ok(_) => {}
+ Err(e) => handle_error(e, file_path, Cmd::ScarbFormat()),
+ }
+ }
+}
+
+fn handle_error(e: String, file_path: &str, cmd: Cmd) {
+ let clickable_file = clickable(file_path);
+ let msg = match cmd {
+ Cmd::ScarbTest() | Cmd::ScarbCairoRun() => {
+ format!("{} -> {}: {}", clickable_file, cmd.as_str(), e.as_str())
+ }
+ _ => format!("{} -> {}", cmd.as_str(), clickable_file),
+ };
+
+ error!("{}", msg);
+
+ let mut errors = ERRORS.lock().unwrap();
+ errors.get_mut_error_set(&cmd).insert(clickable_file);
+}
diff --git a/cairo-verify/src/tags.rs b/cairo-verify/src/tags.rs
new file mode 100644
index 000000000..d6face6fd
--- /dev/null
+++ b/cairo-verify/src/tags.rs
@@ -0,0 +1,19 @@
+#[derive(Debug, PartialEq, Eq, Hash)]
+pub enum Tags {
+ DoesNotCompile,
+ DoesNotRun,
+ IgnoreFormat,
+ FailingTests,
+}
+
+impl Tags {
+ pub fn from_str(tag: &str) -> Option {
+ match tag {
+ "does_not_compile" => Some(Tags::DoesNotCompile),
+ "does_not_run" => Some(Tags::DoesNotRun),
+ "ignore_fmt" => Some(Tags::IgnoreFormat),
+ "tests_fail" => Some(Tags::FailingTests),
+ _ => None,
+ }
+ }
+}
diff --git a/cairo-verify/src/utils.rs b/cairo-verify/src/utils.rs
new file mode 100644
index 000000000..5b802964e
--- /dev/null
+++ b/cairo-verify/src/utils.rs
@@ -0,0 +1,74 @@
+use colored::Colorize;
+use regex::Regex;
+use std::collections::HashSet;
+use walkdir::WalkDir;
+
+use crate::config::Config;
+
+pub fn find_scarb_manifests(cfg: &Config) -> Vec {
+ let path = cfg.path.as_str();
+
+ let mut scarb_manifests: Vec = Vec::new();
+
+ for entry in WalkDir::new(path).into_iter().filter_map(|e| e.ok()) {
+ if let Some(file_name) = entry.file_name().to_str() {
+ if file_name.eq("Scarb.toml") {
+ if cfg.file.is_some() && !file_name.ends_with(cfg.file.as_ref().unwrap()) {
+ continue;
+ }
+
+ scarb_manifests.push(entry.path().display().to_string());
+ }
+ }
+ }
+
+ scarb_manifests
+}
+
+/// Will replace the file path contained in the input string with a clickable format for better output
+pub fn clickable(relative_path: &str) -> String {
+ let full_path = std::env::current_dir()
+ .unwrap()
+ .join(relative_path)
+ .display()
+ .to_string();
+ let mut path_parts: Vec<&str> = full_path.split(|c: char| c == '\\' || c == '/').collect();
+
+ let file_listing_path: Vec<&str> = full_path.split("listings").collect();
+ let mut filename: String = file_listing_path.last().unwrap_or(&"")[1..].to_string();
+ let re = Regex::new(r"([^:]+(:\d+:\d+)?)(:\s|$)").unwrap();
+ if let Some(captures) = re.captures(filename.as_str()) {
+ filename = captures.get(1).map_or("", |m| m.as_str()).to_string();
+ }
+
+ if let Some(parts) = path_parts.last_mut() {
+ *parts = &filename;
+ }
+
+ let clickable_format = format!(
+ "\u{1b}]8;;file://{}\u{1b}\\{}\u{1b}]8;;\u{1b}\\",
+ full_path, filename
+ )
+ .bold()
+ .red()
+ .to_string();
+
+ full_path.replacen(&full_path, &clickable_format, 1)
+}
+
+pub fn print_error_table(errors: &HashSet, section_name: &str) {
+ if errors.is_empty() {
+ return;
+ }
+
+ println!(
+ "{}",
+ format!("{}: {}", section_name, errors.len())
+ .bold()
+ .on_red()
+ );
+
+ for error in errors {
+ println!(" - {}", error);
+ }
+}
diff --git a/listings/ch02-99-common-collections/no_listing_00_array_new_append/.gitignore b/listings/ch02-99-common-collections/no_listing_00_array_new_append/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_00_array_new_append/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-99-common-collections/no_listing_00_array_new_append/Scarb.toml b/listings/ch02-99-common-collections/no_listing_00_array_new_append/Scarb.toml
new file mode 100644
index 000000000..6eb1290f8
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_00_array_new_append/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_00_array_new_append"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_30_array_new_append.cairo b/listings/ch02-99-common-collections/no_listing_00_array_new_append/src/lib.cairo
similarity index 80%
rename from listings/ch02-common-programming-concepts/no_listing_30_array_new_append.cairo
rename to listings/ch02-99-common-collections/no_listing_00_array_new_append/src/lib.cairo
index 146cceb61..5fe852c85 100644
--- a/listings/ch02-common-programming-concepts/no_listing_30_array_new_append.cairo
+++ b/listings/ch02-99-common-collections/no_listing_00_array_new_append/src/lib.cairo
@@ -1,5 +1,3 @@
-use array::ArrayTrait;
-
fn main() {
let mut a = ArrayTrait::new();
a.append(0);
diff --git a/listings/ch02-99-common-collections/no_listing_01_array_pop_front/.gitignore b/listings/ch02-99-common-collections/no_listing_01_array_pop_front/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_01_array_pop_front/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-99-common-collections/no_listing_01_array_pop_front/Scarb.toml b/listings/ch02-99-common-collections/no_listing_01_array_pop_front/Scarb.toml
new file mode 100644
index 000000000..a62bffb27
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_01_array_pop_front/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_01_array_pop_front"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_31_array_pop_front.cairo b/listings/ch02-99-common-collections/no_listing_01_array_pop_front/src/lib.cairo
similarity index 81%
rename from listings/ch02-common-programming-concepts/no_listing_31_array_pop_front.cairo
rename to listings/ch02-99-common-collections/no_listing_01_array_pop_front/src/lib.cairo
index 13f8edfce..1e6886af1 100644
--- a/listings/ch02-common-programming-concepts/no_listing_31_array_pop_front.cairo
+++ b/listings/ch02-99-common-collections/no_listing_01_array_pop_front/src/lib.cairo
@@ -1,5 +1,3 @@
-use option::OptionTrait;
-use array::ArrayTrait;
use debug::PrintTrait;
fn main() {
diff --git a/listings/ch02-99-common-collections/no_listing_02_array_at/.gitignore b/listings/ch02-99-common-collections/no_listing_02_array_at/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_02_array_at/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-99-common-collections/no_listing_02_array_at/Scarb.toml b/listings/ch02-99-common-collections/no_listing_02_array_at/Scarb.toml
new file mode 100644
index 000000000..3a4692b91
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_02_array_at/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_02_array_at"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_32_array_at.cairo b/listings/ch02-99-common-collections/no_listing_02_array_at/src/lib.cairo
similarity index 85%
rename from listings/ch02-common-programming-concepts/no_listing_32_array_at.cairo
rename to listings/ch02-99-common-collections/no_listing_02_array_at/src/lib.cairo
index a9c782fa7..ecfac6c03 100644
--- a/listings/ch02-common-programming-concepts/no_listing_32_array_at.cairo
+++ b/listings/ch02-99-common-collections/no_listing_02_array_at/src/lib.cairo
@@ -1,4 +1,3 @@
-use array::ArrayTrait;
fn main() {
let mut a = ArrayTrait::new();
a.append(0);
diff --git a/listings/ch02-99-common-collections/no_listing_03_array_get/.gitignore b/listings/ch02-99-common-collections/no_listing_03_array_get/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_03_array_get/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-99-common-collections/no_listing_03_array_get/Scarb.toml b/listings/ch02-99-common-collections/no_listing_03_array_get/Scarb.toml
new file mode 100644
index 000000000..780952999
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_03_array_get/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_03_array_get"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_33_array_get.cairo b/listings/ch02-99-common-collections/no_listing_03_array_get/src/lib.cairo
similarity index 89%
rename from listings/ch02-common-programming-concepts/no_listing_33_array_get.cairo
rename to listings/ch02-99-common-collections/no_listing_03_array_get/src/lib.cairo
index 8cff80e03..445877e69 100644
--- a/listings/ch02-common-programming-concepts/no_listing_33_array_get.cairo
+++ b/listings/ch02-99-common-collections/no_listing_03_array_get/src/lib.cairo
@@ -1,5 +1,3 @@
-use array::ArrayTrait;
-use box::BoxTrait;
fn main() -> u128 {
let mut arr = ArrayTrait::::new();
arr.append(100);
@@ -8,7 +6,7 @@ fn main() -> u128 {
match arr.get(index_to_access) {
Option::Some(x) => {
*x.unbox()
- // Don't worry about * for now, if you are curious see Chapter 3.2 #desnap operator
+ // Don't worry about * for now, if you are curious see Chapter 4.2 #desnap operator
// It basically means "transform what get(idx) returned into a real value"
},
Option::None(_) => {
diff --git a/listings/ch02-99-common-collections/no_listing_04_array_with_enums/.gitignore b/listings/ch02-99-common-collections/no_listing_04_array_with_enums/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_04_array_with_enums/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-99-common-collections/no_listing_04_array_with_enums/Scarb.toml b/listings/ch02-99-common-collections/no_listing_04_array_with_enums/Scarb.toml
new file mode 100644
index 000000000..e9dcf1664
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_04_array_with_enums/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_04_array_with_enums"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_34_array_with_enums.cairo b/listings/ch02-99-common-collections/no_listing_04_array_with_enums/src/lib.cairo
similarity index 87%
rename from listings/ch02-common-programming-concepts/no_listing_34_array_with_enums.cairo
rename to listings/ch02-99-common-collections/no_listing_04_array_with_enums/src/lib.cairo
index 7353af425..1d2997c71 100644
--- a/listings/ch02-common-programming-concepts/no_listing_34_array_with_enums.cairo
+++ b/listings/ch02-99-common-collections/no_listing_04_array_with_enums/src/lib.cairo
@@ -1,6 +1,3 @@
-use array::ArrayTrait;
-use traits::Into;
-
#[derive(Copy, Drop)]
enum Data {
Integer: u128,
diff --git a/listings/ch02-99-common-collections/no_listing_05_array_span/.gitignore b/listings/ch02-99-common-collections/no_listing_05_array_span/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_05_array_span/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-99-common-collections/no_listing_05_array_span/Scarb.toml b/listings/ch02-99-common-collections/no_listing_05_array_span/Scarb.toml
new file mode 100644
index 000000000..9c5aa5e14
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_05_array_span/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_05_array_span"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-99-common-collections/no_listing_05_array_span/src/lib.cairo b/listings/ch02-99-common-collections/no_listing_05_array_span/src/lib.cairo
new file mode 100644
index 000000000..73aa069a2
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_05_array_span/src/lib.cairo
@@ -0,0 +1,4 @@
+fn main() {
+ let mut array: Array = ArrayTrait::new();
+ array.span();
+}
diff --git a/listings/ch02-99-common-collections/no_listing_07_intro/.gitignore b/listings/ch02-99-common-collections/no_listing_07_intro/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_07_intro/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-99-common-collections/no_listing_07_intro/Scarb.toml b/listings/ch02-99-common-collections/no_listing_07_intro/Scarb.toml
new file mode 100644
index 000000000..45feec3eb
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_07_intro/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_07_intro"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-99-common-collections/no_listing_07_intro/src/lib.cairo b/listings/ch02-99-common-collections/no_listing_07_intro/src/lib.cairo
new file mode 100644
index 000000000..05a53be87
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_07_intro/src/lib.cairo
@@ -0,0 +1,12 @@
+fn main() {
+ let mut balances: Felt252Dict = Default::default();
+
+ balances.insert('Alex', 100);
+ balances.insert('Maria', 200);
+
+ let alex_balance = balances.get('Alex');
+ assert(alex_balance == 100, 'Balance is not 100');
+
+ let maria_balance = balances.get('Maria');
+ assert(maria_balance == 200, 'Balance is not 200');
+}
diff --git a/listings/ch02-99-common-collections/no_listing_08_intro_rewrite/.gitignore b/listings/ch02-99-common-collections/no_listing_08_intro_rewrite/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_08_intro_rewrite/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-99-common-collections/no_listing_08_intro_rewrite/Scarb.toml b/listings/ch02-99-common-collections/no_listing_08_intro_rewrite/Scarb.toml
new file mode 100644
index 000000000..bf4bc43ed
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_08_intro_rewrite/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_08_intro_rewrite"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-99-common-collections/no_listing_08_intro_rewrite/src/lib.cairo b/listings/ch02-99-common-collections/no_listing_08_intro_rewrite/src/lib.cairo
new file mode 100644
index 000000000..ac56f269b
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_08_intro_rewrite/src/lib.cairo
@@ -0,0 +1,15 @@
+fn main() {
+ let mut balances: Felt252Dict = Default::default();
+
+ // Insert Alex with 100 balance
+ balances.insert('Alex', 100);
+ // Check that Alex has indeed 100 asociated with him
+ let alex_balance = balances.get('Alex');
+ assert(alex_balance == 100, 'Alex balance is not 100');
+
+ // Insert Alex again, this time with 200 balance
+ balances.insert('Alex', 200);
+ // Check the new balance is correct
+ let alex_balance_2 = balances.get('Alex');
+ assert(alex_balance_2 == 200, 'Alex balance is not 200');
+}
diff --git a/listings/ch02-99-common-collections/no_listing_09_entries/.gitignore b/listings/ch02-99-common-collections/no_listing_09_entries/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_09_entries/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-99-common-collections/no_listing_09_entries/Scarb.toml b/listings/ch02-99-common-collections/no_listing_09_entries/Scarb.toml
new file mode 100644
index 000000000..9da08421e
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_09_entries/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_09_entries"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-99-common-collections/no_listing_09_entries/src/lib.cairo b/listings/ch02-99-common-collections/no_listing_09_entries/src/lib.cairo
new file mode 100644
index 000000000..9a6d83056
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_09_entries/src/lib.cairo
@@ -0,0 +1,17 @@
+// ANCHOR: struct
+struct Entry {
+ key: felt252,
+ previous_value: T,
+ new_value: T,
+}
+// ANCHOR_END: struct
+
+fn main() {
+ let mut balances: Felt252Dict = Default::default();
+ // ANCHOR: inserts
+ balances.insert('Alex', 100_u64);
+ balances.insert('Maria', 50_u64);
+ balances.insert('Alex', 200_u64);
+ balances.get('Maria');
+// ANCHOR_END: inserts
+}
diff --git a/listings/ch02-99-common-collections/no_listing_10_custom_methods/.gitignore b/listings/ch02-99-common-collections/no_listing_10_custom_methods/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_10_custom_methods/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-99-common-collections/no_listing_10_custom_methods/Scarb.toml b/listings/ch02-99-common-collections/no_listing_10_custom_methods/Scarb.toml
new file mode 100644
index 000000000..22f49ce69
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_10_custom_methods/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_10_custom_methods"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-99-common-collections/no_listing_10_custom_methods/src/lib.cairo b/listings/ch02-99-common-collections/no_listing_10_custom_methods/src/lib.cairo
new file mode 100644
index 000000000..5ec47b819
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_10_custom_methods/src/lib.cairo
@@ -0,0 +1,58 @@
+// ANCHOR: imports
+use dict::Felt252DictEntryTrait;
+// ANCHOR_END: imports
+
+use debug::PrintTrait;
+
+// ANCHOR: custom_get
+fn custom_get, impl TDrop: Drop, impl TCopy: Copy>(
+ ref dict: Felt252Dict, key: felt252
+) -> T {
+ // Get the new entry and the previous value held at `key`
+ let (entry, prev_value) = dict.entry(key);
+
+ // Store the value to return
+ let return_value = prev_value;
+
+ // Update the entry with `prev_value` and get back ownership of the dictionary
+ dict = entry.finalize(prev_value);
+
+ // Return the read value
+ return_value
+}
+// ANCHOR_END: custom_get
+
+// ANCHOR: custom_insert
+fn custom_insert<
+ T,
+ impl TDefault: Felt252DictValue,
+ impl TDestruct: Destruct,
+ impl TPrint: PrintTrait,
+ impl TDrop: Drop
+>(
+ ref dict: Felt252Dict, key: felt252, value: T
+) {
+ // Get the last entry associated with `key`
+ // Notice that if `key` does not exists, _prev_value will
+ // be the default value of T.
+ let (entry, _prev_value) = dict.entry(key);
+
+ // Insert `entry` back in the dictionary with the updated value,
+ // and recieve ownership of the dictionary
+ dict = entry.finalize(value);
+}
+// ANCHOR_END: custom_insert
+
+// ANCHOR: main
+fn main() {
+ let mut dict: Felt252Dict = Default::default();
+
+ custom_insert(ref dict, '0', 100);
+
+ let val = custom_get(ref dict, '0');
+
+ assert(val == 100, 'Expecting 100');
+}
+// ANCHOR_END: main
+
+
diff --git a/listings/ch02-99-common-collections/no_listing_11_dict_of_complex/.gitignore b/listings/ch02-99-common-collections/no_listing_11_dict_of_complex/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_11_dict_of_complex/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-99-common-collections/no_listing_11_dict_of_complex/Scarb.toml b/listings/ch02-99-common-collections/no_listing_11_dict_of_complex/Scarb.toml
new file mode 100644
index 000000000..3aba306d8
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_11_dict_of_complex/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_11_dict_of_complex"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-99-common-collections/no_listing_11_dict_of_complex/src/lib.cairo b/listings/ch02-99-common-collections/no_listing_11_dict_of_complex/src/lib.cairo
new file mode 100644
index 000000000..4b9495049
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_11_dict_of_complex/src/lib.cairo
@@ -0,0 +1,42 @@
+// ANCHOR: all
+
+// ANCHOR: imports
+use dict::Felt252DictTrait;
+use nullable::{nullable_from_box, match_nullable, FromNullableResult};
+// ANCHOR_END: imports
+
+// ANCHOR: header
+fn main() {
+ // Create the dictionary
+ let mut d: Felt252Dict>> = Default::default();
+
+ // Crate the array to insert
+ let mut a = ArrayTrait::new();
+ a.append(8);
+ a.append(9);
+ a.append(10);
+
+ // Insert it as a `Span`
+ d.insert(0, nullable_from_box(BoxTrait::new(a.span())));
+ // ANCHOR_END: header
+
+ // ANCHOR: footer
+ // Get value back
+ let val = d.get(0);
+
+ // Search the value and assert it is not null
+ let span = match match_nullable(val) {
+ FromNullableResult::Null(()) => panic_with_felt252('No value found'),
+ FromNullableResult::NotNull(val) => val.unbox(),
+ };
+
+ // Verify we are having the right values
+ assert(*span.at(0) == 8, 'Expecting 8');
+ assert(*span.at(1) == 9, 'Expecting 9');
+ assert(*span.at(2) == 10, 'Expecting 10');
+}
+// ANCHOR_END: footer
+
+// ANCHOR_END: all
+
+
diff --git a/listings/ch02-99-common-collections/no_listing_12_dict_struct_member/.gitignore b/listings/ch02-99-common-collections/no_listing_12_dict_struct_member/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_12_dict_struct_member/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-99-common-collections/no_listing_12_dict_struct_member/Scarb.toml b/listings/ch02-99-common-collections/no_listing_12_dict_struct_member/Scarb.toml
new file mode 100644
index 000000000..22aafaa64
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_12_dict_struct_member/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_12_dict_struct_member"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-99-common-collections/no_listing_12_dict_struct_member/src/lib.cairo b/listings/ch02-99-common-collections/no_listing_12_dict_struct_member/src/lib.cairo
new file mode 100644
index 000000000..71394111c
--- /dev/null
+++ b/listings/ch02-99-common-collections/no_listing_12_dict_struct_member/src/lib.cairo
@@ -0,0 +1,64 @@
+// ANCHOR: struct
+struct UserDatabase {
+ users_amount: u64,
+ balances: Felt252Dict,
+}
+// ANCHOR_END: struct
+
+// ANCHOR: trait
+trait UserDatabaseTrait {
+ fn new() -> UserDatabase;
+ fn add_user>(ref self: UserDatabase, name: felt252, balance: T);
+ fn get_user>(ref self: UserDatabase, name: felt252) -> T;
+}
+// ANCHOR_END: trait
+
+// ANCHOR: impl
+impl UserDatabaseImpl> of UserDatabaseTrait {
+ // Creates a database
+ fn new() -> UserDatabase {
+ UserDatabase { users_amount: 0, balances: Default::default() }
+ }
+
+ // Get the user
+ fn get_user>(ref self: UserDatabase, name: felt252) -> T {
+ self.balances.get(name)
+ }
+
+ // Add a user
+ fn add_user>(ref self: UserDatabase, name: felt252, balance: T) {
+ self.balances.insert(name, balance);
+ self.users_amount += 1;
+ }
+}
+// ANCHOR_END: impl
+
+// ANCHOR: destruct
+impl UserDatabaseDestruct<
+ T, impl TDrop: Drop, impl TDefault: Felt252DictValue
+> of Destruct> {
+ fn destruct(self: UserDatabase) nopanic {
+ self.balances.squash();
+ }
+}
+// ANCHOR_END: destruct
+
+// ANCHOR: main
+fn main() {
+ let mut db = UserDatabaseTrait::new();
+
+ db.add_user('Alex', 100);
+ db.add_user('Maria', 80);
+
+ db.add_user('Alex', 40);
+ db.add_user('Maria', 0);
+
+ let alex_latest_balance = db.get_user('Alex');
+ let maria_latest_balance = db.get_user('Maria');
+
+ assert(alex_latest_balance == 40, 'Expected 40');
+ assert(maria_latest_balance == 0, 'Expected 0');
+}
+// ANCHOR_END: main
+
+
diff --git a/listings/ch02-common-programming-concepts/listing_01_statement/.gitignore b/listings/ch02-common-programming-concepts/listing_01_statement/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/listing_01_statement/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/listing_01_statement/Scarb.toml b/listings/ch02-common-programming-concepts/listing_01_statement/Scarb.toml
new file mode 100644
index 000000000..08fa7d33d
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/listing_01_statement/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_01_statement"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/listing_01_statement.cairo b/listings/ch02-common-programming-concepts/listing_01_statement/src/lib.cairo
similarity index 100%
rename from listings/ch02-common-programming-concepts/listing_01_statement.cairo
rename to listings/ch02-common-programming-concepts/listing_01_statement/src/lib.cairo
diff --git a/listings/ch02-common-programming-concepts/no_listing_01_variables_are_immutable/.gitignore b/listings/ch02-common-programming-concepts/no_listing_01_variables_are_immutable/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_01_variables_are_immutable/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_01_variables_are_immutable/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_01_variables_are_immutable/Scarb.toml
new file mode 100644
index 000000000..2a39b2100
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_01_variables_are_immutable/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_01_variables_are_immutable"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_01_variables_are_immutable.cairo b/listings/ch02-common-programming-concepts/no_listing_01_variables_are_immutable/src/lib.cairo
similarity index 79%
rename from listings/ch02-common-programming-concepts/no_listing_01_variables_are_immutable.cairo
rename to listings/ch02-common-programming-concepts/no_listing_01_variables_are_immutable/src/lib.cairo
index 3ad722319..d9dc53bbe 100644
--- a/listings/ch02-common-programming-concepts/no_listing_01_variables_are_immutable.cairo
+++ b/listings/ch02-common-programming-concepts/no_listing_01_variables_are_immutable/src/lib.cairo
@@ -1,3 +1,4 @@
+//TAG: does_not_compile
use debug::PrintTrait;
fn main() {
let x = 5;
diff --git a/listings/ch02-common-programming-concepts/no_listing_02_adding_mut/.gitignore b/listings/ch02-common-programming-concepts/no_listing_02_adding_mut/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_02_adding_mut/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_02_adding_mut/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_02_adding_mut/Scarb.toml
new file mode 100644
index 000000000..076f17cdd
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_02_adding_mut/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_02_adding_mut"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_02_adding_mut.cairo b/listings/ch02-common-programming-concepts/no_listing_02_adding_mut/src/lib.cairo
similarity index 100%
rename from listings/ch02-common-programming-concepts/no_listing_02_adding_mut.cairo
rename to listings/ch02-common-programming-concepts/no_listing_02_adding_mut/src/lib.cairo
diff --git a/listings/ch02-common-programming-concepts/no_listing_03_shadowing/.gitignore b/listings/ch02-common-programming-concepts/no_listing_03_shadowing/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_03_shadowing/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_03_shadowing/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_03_shadowing/Scarb.toml
new file mode 100644
index 000000000..7e468182b
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_03_shadowing/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_03_shadowing"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_03_shadowing.cairo b/listings/ch02-common-programming-concepts/no_listing_03_shadowing/src/lib.cairo
similarity index 100%
rename from listings/ch02-common-programming-concepts/no_listing_03_shadowing.cairo
rename to listings/ch02-common-programming-concepts/no_listing_03_shadowing/src/lib.cairo
diff --git a/listings/ch02-common-programming-concepts/no_listing_04_shadowing_different_type/.gitignore b/listings/ch02-common-programming-concepts/no_listing_04_shadowing_different_type/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_04_shadowing_different_type/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_04_shadowing_different_type/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_04_shadowing_different_type/Scarb.toml
new file mode 100644
index 000000000..ac40c52fd
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_04_shadowing_different_type/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_04_shadowing_different_type"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_04_shadowing_different_type.cairo b/listings/ch02-common-programming-concepts/no_listing_04_shadowing_different_type/src/lib.cairo
similarity index 82%
rename from listings/ch02-common-programming-concepts/no_listing_04_shadowing_different_type.cairo
rename to listings/ch02-common-programming-concepts/no_listing_04_shadowing_different_type/src/lib.cairo
index 57e466646..eff26cfc6 100644
--- a/listings/ch02-common-programming-concepts/no_listing_04_shadowing_different_type.cairo
+++ b/listings/ch02-common-programming-concepts/no_listing_04_shadowing_different_type/src/lib.cairo
@@ -1,7 +1,7 @@
use debug::PrintTrait;
-use traits::Into;
+
fn main() {
- let x = 2;
+ let x: u64 = 2;
x.print();
let x: felt252 = x.into(); // converts x to a felt, type annotation is required.
x.print()
diff --git a/listings/ch02-common-programming-concepts/no_listing_05_mut_cant_change_type.cairo b/listings/ch02-common-programming-concepts/no_listing_05_mut_cant_change_type.cairo
deleted file mode 100644
index e79c4a84c..000000000
--- a/listings/ch02-common-programming-concepts/no_listing_05_mut_cant_change_type.cairo
+++ /dev/null
@@ -1,8 +0,0 @@
-use debug::PrintTrait;
-use traits::Into;
-fn main() {
- let mut x = 2;
- x.print();
- x = x.into();
- x.print()
-}
diff --git a/listings/ch02-common-programming-concepts/no_listing_05_mut_cant_change_type/.gitignore b/listings/ch02-common-programming-concepts/no_listing_05_mut_cant_change_type/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_05_mut_cant_change_type/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_05_mut_cant_change_type/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_05_mut_cant_change_type/Scarb.toml
new file mode 100644
index 000000000..b82f404e4
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_05_mut_cant_change_type/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_05_mut_cant_change_type"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_05_mut_cant_change_type/src/lib.cairo b/listings/ch02-common-programming-concepts/no_listing_05_mut_cant_change_type/src/lib.cairo
new file mode 100644
index 000000000..b9a0d9643
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_05_mut_cant_change_type/src/lib.cairo
@@ -0,0 +1,9 @@
+//TAG: does_not_compile
+use debug::PrintTrait;
+
+fn main() {
+ let mut x: u64 = 2;
+ x.print();
+ x = 100_felt252;
+ x.print()
+}
diff --git a/listings/ch02-common-programming-concepts/no_listing_06_data_types/.gitignore b/listings/ch02-common-programming-concepts/no_listing_06_data_types/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_06_data_types/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_06_data_types/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_06_data_types/Scarb.toml
new file mode 100644
index 000000000..c1cad1a62
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_06_data_types/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_06_data_types"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_06_data_types.cairo b/listings/ch02-common-programming-concepts/no_listing_06_data_types/src/lib.cairo
similarity index 62%
rename from listings/ch02-common-programming-concepts/no_listing_06_data_types.cairo
rename to listings/ch02-common-programming-concepts/no_listing_06_data_types/src/lib.cairo
index 3fc8b5f7d..236d87335 100644
--- a/listings/ch02-common-programming-concepts/no_listing_06_data_types.cairo
+++ b/listings/ch02-common-programming-concepts/no_listing_06_data_types/src/lib.cairo
@@ -1,5 +1,3 @@
-use traits::TryInto;
-use option::OptionTrait;
fn main() {
let x: felt252 = 3;
let y: u32 = x.try_into().unwrap();
diff --git a/listings/ch02-common-programming-concepts/no_listing_07_integer_types/.gitignore b/listings/ch02-common-programming-concepts/no_listing_07_integer_types/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_07_integer_types/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_07_integer_types/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_07_integer_types/Scarb.toml
new file mode 100644
index 000000000..72cc8f8e6
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_07_integer_types/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_07_integer_types"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_07_integer_types.cairo b/listings/ch02-common-programming-concepts/no_listing_07_integer_types/src/lib.cairo
similarity index 100%
rename from listings/ch02-common-programming-concepts/no_listing_07_integer_types.cairo
rename to listings/ch02-common-programming-concepts/no_listing_07_integer_types/src/lib.cairo
diff --git a/listings/ch02-common-programming-concepts/no_listing_08_numeric_operations/.gitignore b/listings/ch02-common-programming-concepts/no_listing_08_numeric_operations/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_08_numeric_operations/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_08_numeric_operations/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_08_numeric_operations/Scarb.toml
new file mode 100644
index 000000000..52285eeb0
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_08_numeric_operations/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_08_numeric_operations"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_08_numeric_operations.cairo b/listings/ch02-common-programming-concepts/no_listing_08_numeric_operations/src/lib.cairo
similarity index 100%
rename from listings/ch02-common-programming-concepts/no_listing_08_numeric_operations.cairo
rename to listings/ch02-common-programming-concepts/no_listing_08_numeric_operations/src/lib.cairo
diff --git a/listings/ch02-common-programming-concepts/no_listing_09_boolean_type/.gitignore b/listings/ch02-common-programming-concepts/no_listing_09_boolean_type/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_09_boolean_type/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_09_boolean_type/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_09_boolean_type/Scarb.toml
new file mode 100644
index 000000000..97c5b87f6
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_09_boolean_type/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_09_boolean_type"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_09_boolean_type.cairo b/listings/ch02-common-programming-concepts/no_listing_09_boolean_type/src/lib.cairo
similarity index 100%
rename from listings/ch02-common-programming-concepts/no_listing_09_boolean_type.cairo
rename to listings/ch02-common-programming-concepts/no_listing_09_boolean_type/src/lib.cairo
diff --git a/listings/ch02-common-programming-concepts/no_listing_10_short_string_type/.gitignore b/listings/ch02-common-programming-concepts/no_listing_10_short_string_type/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_10_short_string_type/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_10_short_string_type/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_10_short_string_type/Scarb.toml
new file mode 100644
index 000000000..395768c5c
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_10_short_string_type/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_10_short_string_type"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_10_short_string_type.cairo b/listings/ch02-common-programming-concepts/no_listing_10_short_string_type/src/lib.cairo
similarity index 97%
rename from listings/ch02-common-programming-concepts/no_listing_10_short_string_type.cairo
rename to listings/ch02-common-programming-concepts/no_listing_10_short_string_type/src/lib.cairo
index a1a9073e7..a31b2a5fb 100644
--- a/listings/ch02-common-programming-concepts/no_listing_10_short_string_type.cairo
+++ b/listings/ch02-common-programming-concepts/no_listing_10_short_string_type/src/lib.cairo
@@ -1,4 +1,4 @@
fn main() {
let my_first_char = 'C';
let my_first_string = 'Hello world';
-}
\ No newline at end of file
+}
diff --git a/listings/ch02-common-programming-concepts/no_listing_11_type_casting/.gitignore b/listings/ch02-common-programming-concepts/no_listing_11_type_casting/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_11_type_casting/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_11_type_casting/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_11_type_casting/Scarb.toml
new file mode 100644
index 000000000..ae67ed157
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_11_type_casting/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_11_type_casting"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_11_type_casting.cairo b/listings/ch02-common-programming-concepts/no_listing_11_type_casting/src/lib.cairo
similarity index 90%
rename from listings/ch02-common-programming-concepts/no_listing_11_type_casting.cairo
rename to listings/ch02-common-programming-concepts/no_listing_11_type_casting/src/lib.cairo
index 34e4a041f..39b9bb41e 100644
--- a/listings/ch02-common-programming-concepts/no_listing_11_type_casting.cairo
+++ b/listings/ch02-common-programming-concepts/no_listing_11_type_casting/src/lib.cairo
@@ -1,7 +1,3 @@
-use traits::TryInto;
-use traits::Into;
-use option::OptionTrait;
-
fn main() {
let my_felt252 = 10;
// Since a felt252 might not fit in a u8, we need to unwrap the Option type
diff --git a/listings/ch02-common-programming-concepts/no_listing_12_tuple_type/.gitignore b/listings/ch02-common-programming-concepts/no_listing_12_tuple_type/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_12_tuple_type/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_12_tuple_type/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_12_tuple_type/Scarb.toml
new file mode 100644
index 000000000..4180edff3
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_12_tuple_type/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_12_tuple_type"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_12_tuple_type.cairo b/listings/ch02-common-programming-concepts/no_listing_12_tuple_type/src/lib.cairo
similarity index 100%
rename from listings/ch02-common-programming-concepts/no_listing_12_tuple_type.cairo
rename to listings/ch02-common-programming-concepts/no_listing_12_tuple_type/src/lib.cairo
diff --git a/listings/ch02-common-programming-concepts/no_listing_13_tuple_destructuration/.gitignore b/listings/ch02-common-programming-concepts/no_listing_13_tuple_destructuration/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_13_tuple_destructuration/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_13_tuple_destructuration/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_13_tuple_destructuration/Scarb.toml
new file mode 100644
index 000000000..11ddb9e53
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_13_tuple_destructuration/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_13_tuple_destructuration"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_13_tuple_destructuration.cairo b/listings/ch02-common-programming-concepts/no_listing_13_tuple_destructuration/src/lib.cairo
similarity index 98%
rename from listings/ch02-common-programming-concepts/no_listing_13_tuple_destructuration.cairo
rename to listings/ch02-common-programming-concepts/no_listing_13_tuple_destructuration/src/lib.cairo
index e94460f84..2deab26e9 100644
--- a/listings/ch02-common-programming-concepts/no_listing_13_tuple_destructuration.cairo
+++ b/listings/ch02-common-programming-concepts/no_listing_13_tuple_destructuration/src/lib.cairo
@@ -7,4 +7,4 @@ fn main() {
if y == 6 {
'y is six!'.print();
}
-}
\ No newline at end of file
+}
diff --git a/listings/ch02-common-programming-concepts/no_listing_14_tuple_types/.gitignore b/listings/ch02-common-programming-concepts/no_listing_14_tuple_types/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_14_tuple_types/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_14_tuple_types/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_14_tuple_types/Scarb.toml
new file mode 100644
index 000000000..206e53efa
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_14_tuple_types/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_14_tuple_types"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_14_tuple_types.cairo b/listings/ch02-common-programming-concepts/no_listing_14_tuple_types/src/lib.cairo
similarity index 96%
rename from listings/ch02-common-programming-concepts/no_listing_14_tuple_types.cairo
rename to listings/ch02-common-programming-concepts/no_listing_14_tuple_types/src/lib.cairo
index ba894ef01..569232773 100644
--- a/listings/ch02-common-programming-concepts/no_listing_14_tuple_types.cairo
+++ b/listings/ch02-common-programming-concepts/no_listing_14_tuple_types/src/lib.cairo
@@ -1,3 +1,3 @@
fn main() {
let (x, y): (felt252, felt252) = (2, 3);
-}
\ No newline at end of file
+}
diff --git a/listings/ch02-common-programming-concepts/no_listing_15_functions/.gitignore b/listings/ch02-common-programming-concepts/no_listing_15_functions/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_15_functions/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_15_functions/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_15_functions/Scarb.toml
new file mode 100644
index 000000000..c5992cd89
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_15_functions/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_15_functions"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_15_functions.cairo b/listings/ch02-common-programming-concepts/no_listing_15_functions/src/lib.cairo
similarity index 100%
rename from listings/ch02-common-programming-concepts/no_listing_15_functions.cairo
rename to listings/ch02-common-programming-concepts/no_listing_15_functions/src/lib.cairo
diff --git a/listings/ch02-common-programming-concepts/no_listing_16_single_param/.gitignore b/listings/ch02-common-programming-concepts/no_listing_16_single_param/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_16_single_param/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_16_single_param/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_16_single_param/Scarb.toml
new file mode 100644
index 000000000..d42a00350
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_16_single_param/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_16_single_param"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_16_single_param.cairo b/listings/ch02-common-programming-concepts/no_listing_16_single_param/src/lib.cairo
similarity index 100%
rename from listings/ch02-common-programming-concepts/no_listing_16_single_param.cairo
rename to listings/ch02-common-programming-concepts/no_listing_16_single_param/src/lib.cairo
diff --git a/listings/ch02-common-programming-concepts/no_listing_17_multiple_params/.gitignore b/listings/ch02-common-programming-concepts/no_listing_17_multiple_params/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_17_multiple_params/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_17_multiple_params/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_17_multiple_params/Scarb.toml
new file mode 100644
index 000000000..b40e1ea31
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_17_multiple_params/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_17_multiple_params"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_17_multiple_params.cairo b/listings/ch02-common-programming-concepts/no_listing_17_multiple_params/src/lib.cairo
similarity index 100%
rename from listings/ch02-common-programming-concepts/no_listing_17_multiple_params.cairo
rename to listings/ch02-common-programming-concepts/no_listing_17_multiple_params/src/lib.cairo
diff --git a/listings/ch02-common-programming-concepts/no_listing_18_statements_dont_return_values/.gitignore b/listings/ch02-common-programming-concepts/no_listing_18_statements_dont_return_values/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_18_statements_dont_return_values/.gitignore
@@ -0,0 +1 @@
+target
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_18_statements_dont_return_values/Scarb.toml
new file mode 100644
index 000000000..7056e4c4e
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_18_statements_dont_return_values/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_18_statements_dont_return_values"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_18_statements_dont_return_values.cairo b/listings/ch02-common-programming-concepts/no_listing_18_statements_dont_return_values/src/lib.cairo
similarity index 51%
rename from listings/ch02-common-programming-concepts/no_listing_18_statements_dont_return_values.cairo
rename to listings/ch02-common-programming-concepts/no_listing_18_statements_dont_return_values/src/lib.cairo
index 213ab59a9..3b306fe8b 100644
--- a/listings/ch02-common-programming-concepts/no_listing_18_statements_dont_return_values.cairo
+++ b/listings/ch02-common-programming-concepts/no_listing_18_statements_dont_return_values/src/lib.cairo
@@ -1,3 +1,4 @@
+//TAG: does_not_compile, ignore_fmt
fn main() {
let x = (let y = 6);
}
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_19_blocks_are_expressions/.gitignore b/listings/ch02-common-programming-concepts/no_listing_19_blocks_are_expressions/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_19_blocks_are_expressions/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_19_blocks_are_expressions/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_19_blocks_are_expressions/Scarb.toml
new file mode 100644
index 000000000..9b299348e
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_19_blocks_are_expressions/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_19_blocks_are_expressions"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_19_blocks_are_expressions.cairo b/listings/ch02-common-programming-concepts/no_listing_19_blocks_are_expressions/src/lib.cairo
similarity index 100%
rename from listings/ch02-common-programming-concepts/no_listing_19_blocks_are_expressions.cairo
rename to listings/ch02-common-programming-concepts/no_listing_19_blocks_are_expressions/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_20_function_return_values/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_20_function_return_values/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_20_function_return_values/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_20_function_return_values/Scarb.toml
new file mode 100644
index 000000000..d0b02e96f
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_20_function_return_values/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_20_function_return_values"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_20_function_return_values.cairo b/listings/ch02-common-programming-concepts/no_listing_20_function_return_values/src/lib.cairo
similarity index 100%
rename from listings/ch02-common-programming-concepts/no_listing_20_function_return_values.cairo
rename to listings/ch02-common-programming-concepts/no_listing_20_function_return_values/src/lib.cairo
diff --git a/listings/ch02-common-programming-concepts/no_listing_21_function_return_values_2/.gitignore b/listings/ch02-common-programming-concepts/no_listing_21_function_return_values_2/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_21_function_return_values_2/.gitignore
@@ -0,0 +1 @@
+target
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_21_function_return_values_2/Scarb.toml
new file mode 100644
index 000000000..d0613adb1
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_21_function_return_values_2/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_21_function_return_values_2"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_21_function_return_values_2.cairo b/listings/ch02-common-programming-concepts/no_listing_21_function_return_values_2/src/lib.cairo
similarity index 100%
rename from listings/ch02-common-programming-concepts/no_listing_21_function_return_values_2.cairo
rename to listings/ch02-common-programming-concepts/no_listing_21_function_return_values_2/src/lib.cairo
diff --git a/listings/ch02-common-programming-concepts/no_listing_22_function_return_invalid/.gitignore b/listings/ch02-common-programming-concepts/no_listing_22_function_return_invalid/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_22_function_return_invalid/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_22_function_return_invalid/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_22_function_return_invalid/Scarb.toml
new file mode 100644
index 000000000..ac72696d9
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_22_function_return_invalid/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_22_function_return_invalid"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_22_function_return_invalid.cairo b/listings/ch02-common-programming-concepts/no_listing_22_function_return_invalid/src/lib.cairo
similarity index 83%
rename from listings/ch02-common-programming-concepts/no_listing_22_function_return_invalid.cairo
rename to listings/ch02-common-programming-concepts/no_listing_22_function_return_invalid/src/lib.cairo
index bf9ededae..e406df9ed 100644
--- a/listings/ch02-common-programming-concepts/no_listing_22_function_return_invalid.cairo
+++ b/listings/ch02-common-programming-concepts/no_listing_22_function_return_invalid/src/lib.cairo
@@ -1,3 +1,4 @@
+//TAG: does_not_compile
use debug::PrintTrait;
fn main() {
diff --git a/listings/ch02-common-programming-concepts/no_listing_23_comments/.gitignore b/listings/ch02-common-programming-concepts/no_listing_23_comments/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_23_comments/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_23_comments/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_23_comments/Scarb.toml
new file mode 100644
index 000000000..0b73db64c
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_23_comments/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_23_comments"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_23_comments.cairo b/listings/ch02-common-programming-concepts/no_listing_23_comments/src/lib.cairo
similarity index 100%
rename from listings/ch02-common-programming-concepts/no_listing_23_comments.cairo
rename to listings/ch02-common-programming-concepts/no_listing_23_comments/src/lib.cairo
diff --git a/listings/ch02-common-programming-concepts/no_listing_24_if/.gitignore b/listings/ch02-common-programming-concepts/no_listing_24_if/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_24_if/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_24_if/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_24_if/Scarb.toml
new file mode 100644
index 000000000..4b600c4c4
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_24_if/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_24_if"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_24_if.cairo b/listings/ch02-common-programming-concepts/no_listing_24_if/src/lib.cairo
similarity index 98%
rename from listings/ch02-common-programming-concepts/no_listing_24_if.cairo
rename to listings/ch02-common-programming-concepts/no_listing_24_if/src/lib.cairo
index c72071969..4e21f894c 100644
--- a/listings/ch02-common-programming-concepts/no_listing_24_if.cairo
+++ b/listings/ch02-common-programming-concepts/no_listing_24_if/src/lib.cairo
@@ -8,4 +8,4 @@ fn main() {
} else {
'condition was false'.print();
}
-}
\ No newline at end of file
+}
diff --git a/listings/ch02-common-programming-concepts/no_listing_25_else_if/.gitignore b/listings/ch02-common-programming-concepts/no_listing_25_else_if/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_25_else_if/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_25_else_if/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_25_else_if/Scarb.toml
new file mode 100644
index 000000000..e4023b0ed
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_25_else_if/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_25_else_if"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_25_else_if.cairo b/listings/ch02-common-programming-concepts/no_listing_25_else_if/src/lib.cairo
similarity index 100%
rename from listings/ch02-common-programming-concepts/no_listing_25_else_if.cairo
rename to listings/ch02-common-programming-concepts/no_listing_25_else_if/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_26_if_let/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_26_if_let/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_26_if_let/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_26_if_let/Scarb.toml
new file mode 100644
index 000000000..9a02e9000
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_26_if_let/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_26_if_let"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_26_if_let.cairo b/listings/ch02-common-programming-concepts/no_listing_26_if_let/src/lib.cairo
similarity index 100%
rename from listings/ch02-common-programming-concepts/no_listing_26_if_let.cairo
rename to listings/ch02-common-programming-concepts/no_listing_26_if_let/src/lib.cairo
diff --git a/listings/ch02-common-programming-concepts/no_listing_27_loop/.gitignore b/listings/ch02-common-programming-concepts/no_listing_27_loop/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_27_loop/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_27_loop/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_27_loop/Scarb.toml
new file mode 100644
index 000000000..38a5d514c
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_27_loop/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_27_loop"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_27_loop.cairo b/listings/ch02-common-programming-concepts/no_listing_27_loop/src/lib.cairo
similarity index 86%
rename from listings/ch02-common-programming-concepts/no_listing_27_loop.cairo
rename to listings/ch02-common-programming-concepts/no_listing_27_loop/src/lib.cairo
index d92f63c42..b110300e3 100644
--- a/listings/ch02-common-programming-concepts/no_listing_27_loop.cairo
+++ b/listings/ch02-common-programming-concepts/no_listing_27_loop/src/lib.cairo
@@ -3,7 +3,7 @@ fn main() {
let mut i: usize = 0;
loop {
if i > 10 {
- break ();
+ break;
}
'again!'.print();
}
diff --git a/listings/ch02-common-programming-concepts/no_listing_28_loop_break/.gitignore b/listings/ch02-common-programming-concepts/no_listing_28_loop_break/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_28_loop_break/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_28_loop_break/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_28_loop_break/Scarb.toml
new file mode 100644
index 000000000..3665382fc
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_28_loop_break/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_28_loop_break"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_28_loop_break.cairo b/listings/ch02-common-programming-concepts/no_listing_28_loop_break/src/lib.cairo
similarity index 87%
rename from listings/ch02-common-programming-concepts/no_listing_28_loop_break.cairo
rename to listings/ch02-common-programming-concepts/no_listing_28_loop_break/src/lib.cairo
index 02f30ad22..c3a9478a3 100644
--- a/listings/ch02-common-programming-concepts/no_listing_28_loop_break.cairo
+++ b/listings/ch02-common-programming-concepts/no_listing_28_loop_break/src/lib.cairo
@@ -3,7 +3,7 @@ fn main() {
let mut i: usize = 0;
loop {
if i > 10 {
- break ();
+ break;
}
'again'.print();
i += 1;
diff --git a/listings/ch02-common-programming-concepts/no_listing_29_loop_return_values/.gitignore b/listings/ch02-common-programming-concepts/no_listing_29_loop_return_values/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_29_loop_return_values/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_29_loop_return_values/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_29_loop_return_values/Scarb.toml
new file mode 100644
index 000000000..1c99b1497
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_29_loop_return_values/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_29_loop_return_values"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_29_loop_return_values.cairo b/listings/ch02-common-programming-concepts/no_listing_29_loop_return_values/src/lib.cairo
similarity index 100%
rename from listings/ch02-common-programming-concepts/no_listing_29_loop_return_values.cairo
rename to listings/ch02-common-programming-concepts/no_listing_29_loop_return_values/src/lib.cairo
diff --git a/listings/ch02-common-programming-concepts/no_listing_30_named_parameters/.gitignore b/listings/ch02-common-programming-concepts/no_listing_30_named_parameters/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_30_named_parameters/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch02-common-programming-concepts/no_listing_30_named_parameters/Scarb.toml b/listings/ch02-common-programming-concepts/no_listing_30_named_parameters/Scarb.toml
new file mode 100644
index 000000000..fa6d94038
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_30_named_parameters/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_30_named_parameters"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch02-common-programming-concepts/no_listing_30_named_parameters/src/lib.cairo b/listings/ch02-common-programming-concepts/no_listing_30_named_parameters/src/lib.cairo
new file mode 100644
index 000000000..0bfec9cc5
--- /dev/null
+++ b/listings/ch02-common-programming-concepts/no_listing_30_named_parameters/src/lib.cairo
@@ -0,0 +1,10 @@
+fn foo(x: u8, y: u8) {}
+
+fn main() {
+ let first_arg = 3;
+ let second_arg = 4;
+ foo(x: first_arg, y: second_arg);
+ let x = 1;
+ let y = 2;
+ foo(:x, :y)
+}
diff --git a/listings/ch02-common-programming-concepts/no_listing_35_array_span.cairo b/listings/ch02-common-programming-concepts/no_listing_35_array_span.cairo
deleted file mode 100644
index f84dc5fac..000000000
--- a/listings/ch02-common-programming-concepts/no_listing_35_array_span.cairo
+++ /dev/null
@@ -1,6 +0,0 @@
-use array::ArrayTrait;
-
-fn main() {
- let mut array = ArrayTrait::new();
- array.span()
-}
diff --git a/listings/ch03-understanding-ownership/listing_03_01/.gitignore b/listings/ch03-understanding-ownership/listing_03_01/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch03-understanding-ownership/listing_03_01/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch03-understanding-ownership/listing_03_01/Scarb.toml b/listings/ch03-understanding-ownership/listing_03_01/Scarb.toml
new file mode 100644
index 000000000..670d74ed4
--- /dev/null
+++ b/listings/ch03-understanding-ownership/listing_03_01/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_03_01"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch03-understanding-ownership/listing_03_01.cairo b/listings/ch03-understanding-ownership/listing_03_01/src/lib.cairo
similarity index 94%
rename from listings/ch03-understanding-ownership/listing_03_01.cairo
rename to listings/ch03-understanding-ownership/listing_03_01/src/lib.cairo
index b4e93b7af..99d7dfbf2 100644
--- a/listings/ch03-understanding-ownership/listing_03_01.cairo
+++ b/listings/ch03-understanding-ownership/listing_03_01/src/lib.cairo
@@ -1,3 +1,4 @@
+//TAG: ignore_fmt
fn main() {
// ANCHOR: here
{ // s is not valid here, it’s not yet declared
diff --git a/listings/ch03-understanding-ownership/listing_03_03/.gitignore b/listings/ch03-understanding-ownership/listing_03_03/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch03-understanding-ownership/listing_03_03/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch03-understanding-ownership/listing_03_03/Scarb.toml b/listings/ch03-understanding-ownership/listing_03_03/Scarb.toml
new file mode 100644
index 000000000..3a62cfc6b
--- /dev/null
+++ b/listings/ch03-understanding-ownership/listing_03_03/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_03_03"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch03-understanding-ownership/listing_03_03.cairo b/listings/ch03-understanding-ownership/listing_03_03/src/lib.cairo
similarity index 98%
rename from listings/ch03-understanding-ownership/listing_03_03.cairo
rename to listings/ch03-understanding-ownership/listing_03_03/src/lib.cairo
index e2d343f60..91f46a8e0 100644
--- a/listings/ch03-understanding-ownership/listing_03_03.cairo
+++ b/listings/ch03-understanding-ownership/listing_03_03/src/lib.cairo
@@ -1,3 +1,4 @@
+//TAG: ignore_fmt
#[derive(Drop)]
struct MyStruct{}
diff --git a/listings/ch03-understanding-ownership/listing_03_04/.gitignore b/listings/ch03-understanding-ownership/listing_03_04/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch03-understanding-ownership/listing_03_04/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch03-understanding-ownership/listing_03_04/Scarb.toml b/listings/ch03-understanding-ownership/listing_03_04/Scarb.toml
new file mode 100644
index 000000000..eccab7776
--- /dev/null
+++ b/listings/ch03-understanding-ownership/listing_03_04/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_03_04"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch03-understanding-ownership/listing_03_04.cairo b/listings/ch03-understanding-ownership/listing_03_04/src/lib.cairo
similarity index 98%
rename from listings/ch03-understanding-ownership/listing_03_04.cairo
rename to listings/ch03-understanding-ownership/listing_03_04/src/lib.cairo
index 2c63d6067..3c40c90d6 100644
--- a/listings/ch03-understanding-ownership/listing_03_04.cairo
+++ b/listings/ch03-understanding-ownership/listing_03_04/src/lib.cairo
@@ -1,3 +1,4 @@
+//TAG: ignore_fmt
#[derive(Drop)]
struct A {}
diff --git a/listings/ch03-understanding-ownership/listing_03_05/.gitignore b/listings/ch03-understanding-ownership/listing_03_05/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch03-understanding-ownership/listing_03_05/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch03-understanding-ownership/listing_03_05/Scarb.toml b/listings/ch03-understanding-ownership/listing_03_05/Scarb.toml
new file mode 100644
index 000000000..7ff49e77b
--- /dev/null
+++ b/listings/ch03-understanding-ownership/listing_03_05/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_03_05"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch03-understanding-ownership/listing_03_05.cairo b/listings/ch03-understanding-ownership/listing_03_05/src/lib.cairo
similarity index 91%
rename from listings/ch03-understanding-ownership/listing_03_05.cairo
rename to listings/ch03-understanding-ownership/listing_03_05/src/lib.cairo
index be94a9a4a..f89511aba 100644
--- a/listings/ch03-understanding-ownership/listing_03_05.cairo
+++ b/listings/ch03-understanding-ownership/listing_03_05/src/lib.cairo
@@ -1,4 +1,3 @@
-use array::ArrayTrait;
fn main() {
let arr1 = ArrayTrait::::new();
diff --git a/listings/ch03-understanding-ownership/listing_03_06/.gitignore b/listings/ch03-understanding-ownership/listing_03_06/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch03-understanding-ownership/listing_03_06/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch03-understanding-ownership/listing_03_06/Scarb.toml b/listings/ch03-understanding-ownership/listing_03_06/Scarb.toml
new file mode 100644
index 000000000..e660b2686
--- /dev/null
+++ b/listings/ch03-understanding-ownership/listing_03_06/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_03_06"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch03-understanding-ownership/listing_03_06.cairo b/listings/ch03-understanding-ownership/listing_03_06/src/lib.cairo
similarity index 91%
rename from listings/ch03-understanding-ownership/listing_03_06.cairo
rename to listings/ch03-understanding-ownership/listing_03_06/src/lib.cairo
index 7533c9562..06e51604d 100644
--- a/listings/ch03-understanding-ownership/listing_03_06.cairo
+++ b/listings/ch03-understanding-ownership/listing_03_06/src/lib.cairo
@@ -1,4 +1,4 @@
-// does_not_compile
+//TAG: does_not_compile
#[derive(Copy, Drop)]
struct Rectangle {
height: u64,
diff --git a/listings/ch03-understanding-ownership/listing_03_07/.gitignore b/listings/ch03-understanding-ownership/listing_03_07/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch03-understanding-ownership/listing_03_07/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch03-understanding-ownership/listing_03_07/Scarb.toml b/listings/ch03-understanding-ownership/listing_03_07/Scarb.toml
new file mode 100644
index 000000000..807947a4e
--- /dev/null
+++ b/listings/ch03-understanding-ownership/listing_03_07/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_03_07"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch03-understanding-ownership/listing_03_07.cairo b/listings/ch03-understanding-ownership/listing_03_07/src/lib.cairo
similarity index 100%
rename from listings/ch03-understanding-ownership/listing_03_07.cairo
rename to listings/ch03-understanding-ownership/listing_03_07/src/lib.cairo
diff --git a/listings/ch03-understanding-ownership/no_listing_01_array/.gitignore b/listings/ch03-understanding-ownership/no_listing_01_array/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch03-understanding-ownership/no_listing_01_array/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch03-understanding-ownership/no_listing_01_array/Scarb.toml b/listings/ch03-understanding-ownership/no_listing_01_array/Scarb.toml
new file mode 100644
index 000000000..a26b3b9c0
--- /dev/null
+++ b/listings/ch03-understanding-ownership/no_listing_01_array/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_01_array"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch03-understanding-ownership/no_listing_01_array.cairo b/listings/ch03-understanding-ownership/no_listing_01_array/src/lib.cairo
similarity index 80%
rename from listings/ch03-understanding-ownership/no_listing_01_array.cairo
rename to listings/ch03-understanding-ownership/no_listing_01_array/src/lib.cairo
index 37f250cda..9e8244360 100644
--- a/listings/ch03-understanding-ownership/no_listing_01_array.cairo
+++ b/listings/ch03-understanding-ownership/no_listing_01_array/src/lib.cairo
@@ -1,4 +1,3 @@
-use array::ArrayTrait;
fn main() {
let mut arr = ArrayTrait::::new();
arr.append(1);
diff --git a/listings/ch03-understanding-ownership/no_listing_02_pass_array_by_value/.gitignore b/listings/ch03-understanding-ownership/no_listing_02_pass_array_by_value/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch03-understanding-ownership/no_listing_02_pass_array_by_value/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch03-understanding-ownership/no_listing_02_pass_array_by_value/Scarb.toml b/listings/ch03-understanding-ownership/no_listing_02_pass_array_by_value/Scarb.toml
new file mode 100644
index 000000000..982685dd2
--- /dev/null
+++ b/listings/ch03-understanding-ownership/no_listing_02_pass_array_by_value/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_02_pass_array_by_value"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch03-understanding-ownership/no_listing_02_pass_array_by_value.cairo b/listings/ch03-understanding-ownership/no_listing_02_pass_array_by_value/src/lib.cairo
similarity index 86%
rename from listings/ch03-understanding-ownership/no_listing_02_pass_array_by_value.cairo
rename to listings/ch03-understanding-ownership/no_listing_02_pass_array_by_value/src/lib.cairo
index 7e9b892ce..6d61ded8c 100644
--- a/listings/ch03-understanding-ownership/no_listing_02_pass_array_by_value.cairo
+++ b/listings/ch03-understanding-ownership/no_listing_02_pass_array_by_value/src/lib.cairo
@@ -1,4 +1,5 @@
-use array::ArrayTrait;
+//TAG: does_not_run
+
fn foo(arr: Array) {}
fn bar(arr: Array) {}
diff --git a/listings/ch03-understanding-ownership/no_listing_03_copy_trait/.gitignore b/listings/ch03-understanding-ownership/no_listing_03_copy_trait/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch03-understanding-ownership/no_listing_03_copy_trait/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch03-understanding-ownership/no_listing_03_copy_trait/Scarb.toml b/listings/ch03-understanding-ownership/no_listing_03_copy_trait/Scarb.toml
new file mode 100644
index 000000000..b6b3f4081
--- /dev/null
+++ b/listings/ch03-understanding-ownership/no_listing_03_copy_trait/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_03_copy_trait"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch03-understanding-ownership/no_listing_03_copy_trait.cairo b/listings/ch03-understanding-ownership/no_listing_03_copy_trait/src/lib.cairo
similarity index 75%
rename from listings/ch03-understanding-ownership/no_listing_03_copy_trait.cairo
rename to listings/ch03-understanding-ownership/no_listing_03_copy_trait/src/lib.cairo
index f78ca8193..d51f15bcb 100644
--- a/listings/ch03-understanding-ownership/no_listing_03_copy_trait.cairo
+++ b/listings/ch03-understanding-ownership/no_listing_03_copy_trait/src/lib.cairo
@@ -10,6 +10,5 @@ fn main() {
foo(p1);
}
-fn foo(p: Point) {
- // do something with p
-}
\ No newline at end of file
+fn foo(p: Point) { // do something with p
+}
diff --git a/listings/ch03-understanding-ownership/no_listing_04_no_drop_derive_fails/.gitignore b/listings/ch03-understanding-ownership/no_listing_04_no_drop_derive_fails/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch03-understanding-ownership/no_listing_04_no_drop_derive_fails/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch03-understanding-ownership/no_listing_04_no_drop_derive_fails/Scarb.toml b/listings/ch03-understanding-ownership/no_listing_04_no_drop_derive_fails/Scarb.toml
new file mode 100644
index 000000000..7e178d5f7
--- /dev/null
+++ b/listings/ch03-understanding-ownership/no_listing_04_no_drop_derive_fails/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_04_no_drop_derive_fails"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch03-understanding-ownership/no_listing_04_no_drop_derive_fails.cairo b/listings/ch03-understanding-ownership/no_listing_04_no_drop_derive_fails/src/lib.cairo
similarity index 71%
rename from listings/ch03-understanding-ownership/no_listing_04_no_drop_derive_fails.cairo
rename to listings/ch03-understanding-ownership/no_listing_04_no_drop_derive_fails/src/lib.cairo
index 474131619..0cb538029 100644
--- a/listings/ch03-understanding-ownership/no_listing_04_no_drop_derive_fails.cairo
+++ b/listings/ch03-understanding-ownership/no_listing_04_no_drop_derive_fails/src/lib.cairo
@@ -1,5 +1,6 @@
+//TAG: does_not_compile
struct A {}
fn main() {
A {}; // error: Value not dropped.
-}
\ No newline at end of file
+}
diff --git a/listings/ch03-understanding-ownership/no_listing_05_drop_derive_compiles/.gitignore b/listings/ch03-understanding-ownership/no_listing_05_drop_derive_compiles/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch03-understanding-ownership/no_listing_05_drop_derive_compiles/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch03-understanding-ownership/no_listing_05_drop_derive_compiles/Scarb.toml b/listings/ch03-understanding-ownership/no_listing_05_drop_derive_compiles/Scarb.toml
new file mode 100644
index 000000000..623e85a05
--- /dev/null
+++ b/listings/ch03-understanding-ownership/no_listing_05_drop_derive_compiles/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_05_drop_derive_compiles"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch03-understanding-ownership/no_listing_05_drop_derive_compiles.cairo b/listings/ch03-understanding-ownership/no_listing_05_drop_derive_compiles/src/lib.cairo
similarity index 100%
rename from listings/ch03-understanding-ownership/no_listing_05_drop_derive_compiles.cairo
rename to listings/ch03-understanding-ownership/no_listing_05_drop_derive_compiles/src/lib.cairo
diff --git a/listings/ch03-understanding-ownership/no_listing_06_no_destruct_compile_fails.cairo b/listings/ch03-understanding-ownership/no_listing_06_no_destruct_compile_fails.cairo
deleted file mode 100644
index 64664994d..000000000
--- a/listings/ch03-understanding-ownership/no_listing_06_no_destruct_compile_fails.cairo
+++ /dev/null
@@ -1,9 +0,0 @@
-use dict::Felt252DictTrait;
-
-struct A {
- dict: Felt252Dict
-}
-
-fn main() {
- A { dict: Felt252DictTrait::new() };
-}
diff --git a/listings/ch03-understanding-ownership/no_listing_06_no_destruct_compile_fails/.gitignore b/listings/ch03-understanding-ownership/no_listing_06_no_destruct_compile_fails/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch03-understanding-ownership/no_listing_06_no_destruct_compile_fails/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch03-understanding-ownership/no_listing_06_no_destruct_compile_fails/Scarb.toml b/listings/ch03-understanding-ownership/no_listing_06_no_destruct_compile_fails/Scarb.toml
new file mode 100644
index 000000000..326ab5944
--- /dev/null
+++ b/listings/ch03-understanding-ownership/no_listing_06_no_destruct_compile_fails/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_06_no_destruct_compile_fails"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch03-understanding-ownership/no_listing_06_no_destruct_compile_fails/src/lib.cairo b/listings/ch03-understanding-ownership/no_listing_06_no_destruct_compile_fails/src/lib.cairo
new file mode 100644
index 000000000..1939b7215
--- /dev/null
+++ b/listings/ch03-understanding-ownership/no_listing_06_no_destruct_compile_fails/src/lib.cairo
@@ -0,0 +1,9 @@
+//TAG: does_not_compile
+
+struct A {
+ dict: Felt252Dict
+}
+
+fn main() {
+ A { dict: Default::default() };
+}
diff --git a/listings/ch03-understanding-ownership/no_listing_07_destruct_compiles.cairo b/listings/ch03-understanding-ownership/no_listing_07_destruct_compiles.cairo
deleted file mode 100644
index ac1c5e91d..000000000
--- a/listings/ch03-understanding-ownership/no_listing_07_destruct_compiles.cairo
+++ /dev/null
@@ -1,10 +0,0 @@
-use dict::Felt252DictTrait;
-
-#[derive(Destruct)]
-struct A {
- dict: Felt252Dict
-}
-
-fn main() {
- A { dict: Felt252DictTrait::new() }; // No error here
-}
diff --git a/listings/ch03-understanding-ownership/no_listing_07_destruct_compiles/.gitignore b/listings/ch03-understanding-ownership/no_listing_07_destruct_compiles/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch03-understanding-ownership/no_listing_07_destruct_compiles/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch03-understanding-ownership/no_listing_07_destruct_compiles/Scarb.toml b/listings/ch03-understanding-ownership/no_listing_07_destruct_compiles/Scarb.toml
new file mode 100644
index 000000000..ef1cb40a1
--- /dev/null
+++ b/listings/ch03-understanding-ownership/no_listing_07_destruct_compiles/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_07_destruct_compiles"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch03-understanding-ownership/no_listing_07_destruct_compiles/src/lib.cairo b/listings/ch03-understanding-ownership/no_listing_07_destruct_compiles/src/lib.cairo
new file mode 100644
index 000000000..3e6c530e9
--- /dev/null
+++ b/listings/ch03-understanding-ownership/no_listing_07_destruct_compiles/src/lib.cairo
@@ -0,0 +1,8 @@
+#[derive(Destruct)]
+struct A {
+ dict: Felt252Dict
+}
+
+fn main() {
+ A { dict: Default::default() }; // No error here
+}
diff --git a/listings/ch03-understanding-ownership/no_listing_08_array_clone/.gitignore b/listings/ch03-understanding-ownership/no_listing_08_array_clone/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch03-understanding-ownership/no_listing_08_array_clone/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch03-understanding-ownership/no_listing_08_array_clone/Scarb.toml b/listings/ch03-understanding-ownership/no_listing_08_array_clone/Scarb.toml
new file mode 100644
index 000000000..3d7582afa
--- /dev/null
+++ b/listings/ch03-understanding-ownership/no_listing_08_array_clone/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_08_array_clone"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch03-understanding-ownership/no_listing_08_array_clone.cairo b/listings/ch03-understanding-ownership/no_listing_08_array_clone/src/lib.cairo
similarity index 85%
rename from listings/ch03-understanding-ownership/no_listing_08_array_clone.cairo
rename to listings/ch03-understanding-ownership/no_listing_08_array_clone/src/lib.cairo
index 053bc95cb..c2bccc07f 100644
--- a/listings/ch03-understanding-ownership/no_listing_08_array_clone.cairo
+++ b/listings/ch03-understanding-ownership/no_listing_08_array_clone/src/lib.cairo
@@ -1,4 +1,3 @@
-use array::ArrayTrait;
use clone::Clone;
use array::ArrayTCloneImpl;
fn main() {
diff --git a/listings/ch03-understanding-ownership/no_listing_09_snapshots/.gitignore b/listings/ch03-understanding-ownership/no_listing_09_snapshots/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch03-understanding-ownership/no_listing_09_snapshots/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch03-understanding-ownership/no_listing_09_snapshots/Scarb.toml b/listings/ch03-understanding-ownership/no_listing_09_snapshots/Scarb.toml
new file mode 100644
index 000000000..c4a83c3aa
--- /dev/null
+++ b/listings/ch03-understanding-ownership/no_listing_09_snapshots/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_09_snapshots"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch03-understanding-ownership/no_listing_09_snapshots.cairo b/listings/ch03-understanding-ownership/no_listing_09_snapshots/src/lib.cairo
similarity index 96%
rename from listings/ch03-understanding-ownership/no_listing_09_snapshots.cairo
rename to listings/ch03-understanding-ownership/no_listing_09_snapshots/src/lib.cairo
index 0433cc19c..1fb3e452d 100644
--- a/listings/ch03-understanding-ownership/no_listing_09_snapshots.cairo
+++ b/listings/ch03-understanding-ownership/no_listing_09_snapshots/src/lib.cairo
@@ -1,4 +1,3 @@
-use array::ArrayTrait;
use debug::PrintTrait;
fn main() {
diff --git a/listings/ch03-understanding-ownership/no_listing_10_desnap/.gitignore b/listings/ch03-understanding-ownership/no_listing_10_desnap/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch03-understanding-ownership/no_listing_10_desnap/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch03-understanding-ownership/no_listing_10_desnap/Scarb.toml b/listings/ch03-understanding-ownership/no_listing_10_desnap/Scarb.toml
new file mode 100644
index 000000000..e408dccee
--- /dev/null
+++ b/listings/ch03-understanding-ownership/no_listing_10_desnap/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_10_desnap"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch03-understanding-ownership/no_listing_10_desnap.cairo b/listings/ch03-understanding-ownership/no_listing_10_desnap/src/lib.cairo
similarity index 100%
rename from listings/ch03-understanding-ownership/no_listing_10_desnap.cairo
rename to listings/ch03-understanding-ownership/no_listing_10_desnap/src/lib.cairo
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_01_user_struct/.gitignore b/listings/ch04-using-structs-to-structure-related-data/listing_04_01_user_struct/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch04-using-structs-to-structure-related-data/listing_04_01_user_struct/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_01_user_struct/Scarb.toml b/listings/ch04-using-structs-to-structure-related-data/listing_04_01_user_struct/Scarb.toml
new file mode 100644
index 000000000..9bed1b252
--- /dev/null
+++ b/listings/ch04-using-structs-to-structure-related-data/listing_04_01_user_struct/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_04_01_user_struct"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_01_user_struct.cairo b/listings/ch04-using-structs-to-structure-related-data/listing_04_01_user_struct/src/lib.cairo
similarity index 100%
rename from listings/ch04-using-structs-to-structure-related-data/listing_04_01_user_struct.cairo
rename to listings/ch04-using-structs-to-structure-related-data/listing_04_01_user_struct/src/lib.cairo
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_03_mut_struct/.gitignore b/listings/ch04-using-structs-to-structure-related-data/listing_04_03_mut_struct/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch04-using-structs-to-structure-related-data/listing_04_03_mut_struct/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_03_mut_struct/Scarb.toml b/listings/ch04-using-structs-to-structure-related-data/listing_04_03_mut_struct/Scarb.toml
new file mode 100644
index 000000000..23951d82b
--- /dev/null
+++ b/listings/ch04-using-structs-to-structure-related-data/listing_04_03_mut_struct/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_04_03_mut_struct"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_03_mut_struct.cairo b/listings/ch04-using-structs-to-structure-related-data/listing_04_03_mut_struct/src/lib.cairo
similarity index 89%
rename from listings/ch04-using-structs-to-structure-related-data/listing_04_03_mut_struct.cairo
rename to listings/ch04-using-structs-to-structure-related-data/listing_04_03_mut_struct/src/lib.cairo
index 221ff91b3..7e9f30f64 100644
--- a/listings/ch04-using-structs-to-structure-related-data/listing_04_03_mut_struct.cairo
+++ b/listings/ch04-using-structs-to-structure-related-data/listing_04_03_mut_struct/src/lib.cairo
@@ -17,14 +17,15 @@ fn main() {
// ANCHOR: build_user
fn build_user(email: felt252, username: felt252) -> User {
- User { active: true, username: username, email: email, sign_in_count: 1, }
+ User { active: true, username: username, email: email, sign_in_count: 1, }
}
// ANCHOR_END: build_user
// ANCHOR: build_user2
fn build_user_short(email: felt252, username: felt252) -> User {
- User { active: true, username, email, sign_in_count: 1, }
+ User { active: true, username, email, sign_in_count: 1, }
}
// ANCHOR_END: build_user2
// ANCHOR_END: all
+
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_06_no_struct/.gitignore b/listings/ch04-using-structs-to-structure-related-data/listing_04_06_no_struct/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch04-using-structs-to-structure-related-data/listing_04_06_no_struct/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_06_no_struct/Scarb.toml b/listings/ch04-using-structs-to-structure-related-data/listing_04_06_no_struct/Scarb.toml
new file mode 100644
index 000000000..914681f3f
--- /dev/null
+++ b/listings/ch04-using-structs-to-structure-related-data/listing_04_06_no_struct/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_04_06_no_struct"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_06_no_struct.cairo b/listings/ch04-using-structs-to-structure-related-data/listing_04_06_no_struct/src/lib.cairo
similarity index 99%
rename from listings/ch04-using-structs-to-structure-related-data/listing_04_06_no_struct.cairo
rename to listings/ch04-using-structs-to-structure-related-data/listing_04_06_no_struct/src/lib.cairo
index 50d52ac29..fae125347 100644
--- a/listings/ch04-using-structs-to-structure-related-data/listing_04_06_no_struct.cairo
+++ b/listings/ch04-using-structs-to-structure-related-data/listing_04_06_no_struct/src/lib.cairo
@@ -8,4 +8,4 @@ fn main() {
fn area(width: u64, height: u64) -> u64 {
width * height
-}
\ No newline at end of file
+}
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_07_w_tuples/.gitignore b/listings/ch04-using-structs-to-structure-related-data/listing_04_07_w_tuples/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch04-using-structs-to-structure-related-data/listing_04_07_w_tuples/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_07_w_tuples/Scarb.toml b/listings/ch04-using-structs-to-structure-related-data/listing_04_07_w_tuples/Scarb.toml
new file mode 100644
index 000000000..16bdd6007
--- /dev/null
+++ b/listings/ch04-using-structs-to-structure-related-data/listing_04_07_w_tuples/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_04_07_w_tuples"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_07_w_tuples.cairo b/listings/ch04-using-structs-to-structure-related-data/listing_04_07_w_tuples/src/lib.cairo
similarity index 100%
rename from listings/ch04-using-structs-to-structure-related-data/listing_04_07_w_tuples.cairo
rename to listings/ch04-using-structs-to-structure-related-data/listing_04_07_w_tuples/src/lib.cairo
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_08_w_structs/.gitignore b/listings/ch04-using-structs-to-structure-related-data/listing_04_08_w_structs/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch04-using-structs-to-structure-related-data/listing_04_08_w_structs/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_08_w_structs/Scarb.toml b/listings/ch04-using-structs-to-structure-related-data/listing_04_08_w_structs/Scarb.toml
new file mode 100644
index 000000000..ad8c9fd6d
--- /dev/null
+++ b/listings/ch04-using-structs-to-structure-related-data/listing_04_08_w_structs/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_04_08_w_structs"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_08_w_structs.cairo b/listings/ch04-using-structs-to-structure-related-data/listing_04_08_w_structs/src/lib.cairo
similarity index 80%
rename from listings/ch04-using-structs-to-structure-related-data/listing_04_08_w_structs.cairo
rename to listings/ch04-using-structs-to-structure-related-data/listing_04_08_w_structs/src/lib.cairo
index 6202fd7a3..7db5eeac1 100644
--- a/listings/ch04-using-structs-to-structure-related-data/listing_04_08_w_structs.cairo
+++ b/listings/ch04-using-structs-to-structure-related-data/listing_04_08_w_structs/src/lib.cairo
@@ -6,7 +6,7 @@ struct Rectangle {
}
fn main() {
- let rectangle = Rectangle { width: 30, height: 10, };
+ let rectangle = Rectangle { width: 30, height: 10, };
let area = area(rectangle);
area.print(); // print out the area
}
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_10_print_rectangle/.gitignore b/listings/ch04-using-structs-to-structure-related-data/listing_04_10_print_rectangle/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch04-using-structs-to-structure-related-data/listing_04_10_print_rectangle/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_10_print_rectangle/Scarb.toml b/listings/ch04-using-structs-to-structure-related-data/listing_04_10_print_rectangle/Scarb.toml
new file mode 100644
index 000000000..243072d65
--- /dev/null
+++ b/listings/ch04-using-structs-to-structure-related-data/listing_04_10_print_rectangle/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_04_10_print_rectangle"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_10_print_rectangle.cairo b/listings/ch04-using-structs-to-structure-related-data/listing_04_10_print_rectangle/src/lib.cairo
similarity index 81%
rename from listings/ch04-using-structs-to-structure-related-data/listing_04_10_print_rectangle.cairo
rename to listings/ch04-using-structs-to-structure-related-data/listing_04_10_print_rectangle/src/lib.cairo
index 4f54ffec8..412db5030 100644
--- a/listings/ch04-using-structs-to-structure-related-data/listing_04_10_print_rectangle.cairo
+++ b/listings/ch04-using-structs-to-structure-related-data/listing_04_10_print_rectangle/src/lib.cairo
@@ -6,7 +6,7 @@ struct Rectangle {
}
fn main() {
- let rectangle = Rectangle { width: 30, height: 10, };
+ let rectangle = Rectangle { width: 30, height: 10, };
rectangle.print();
}
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_13_area_method/.gitignore b/listings/ch04-using-structs-to-structure-related-data/listing_04_13_area_method/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch04-using-structs-to-structure-related-data/listing_04_13_area_method/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_13_area_method/Scarb.toml b/listings/ch04-using-structs-to-structure-related-data/listing_04_13_area_method/Scarb.toml
new file mode 100644
index 000000000..0299a3d72
--- /dev/null
+++ b/listings/ch04-using-structs-to-structure-related-data/listing_04_13_area_method/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_04_13_area_method"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_13_area_method.cairo b/listings/ch04-using-structs-to-structure-related-data/listing_04_13_area_method/src/lib.cairo
similarity index 85%
rename from listings/ch04-using-structs-to-structure-related-data/listing_04_13_area_method.cairo
rename to listings/ch04-using-structs-to-structure-related-data/listing_04_13_area_method/src/lib.cairo
index eb158b7d5..02d7964ac 100644
--- a/listings/ch04-using-structs-to-structure-related-data/listing_04_13_area_method.cairo
+++ b/listings/ch04-using-structs-to-structure-related-data/listing_04_13_area_method/src/lib.cairo
@@ -16,7 +16,7 @@ impl RectangleImpl of RectangleTrait {
}
fn main() {
- let rect1 = Rectangle { width: 30, height: 50, };
+ let rect1 = Rectangle { width: 30, height: 50, };
rect1.area().print();
}
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_14_width_method/.gitignore b/listings/ch04-using-structs-to-structure-related-data/listing_04_14_width_method/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch04-using-structs-to-structure-related-data/listing_04_14_width_method/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_14_width_method/Scarb.toml b/listings/ch04-using-structs-to-structure-related-data/listing_04_14_width_method/Scarb.toml
new file mode 100644
index 000000000..4013efeab
--- /dev/null
+++ b/listings/ch04-using-structs-to-structure-related-data/listing_04_14_width_method/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_04_14_width_method"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_14_width_method.cairo b/listings/ch04-using-structs-to-structure-related-data/listing_04_14_width_method/src/lib.cairo
similarity index 85%
rename from listings/ch04-using-structs-to-structure-related-data/listing_04_14_width_method.cairo
rename to listings/ch04-using-structs-to-structure-related-data/listing_04_14_width_method/src/lib.cairo
index 080fab4ca..0d846fc4f 100644
--- a/listings/ch04-using-structs-to-structure-related-data/listing_04_14_width_method.cairo
+++ b/listings/ch04-using-structs-to-structure-related-data/listing_04_14_width_method/src/lib.cairo
@@ -16,6 +16,6 @@ impl RectangleImpl of RectangleTrait {
}
fn main() {
- let rect1 = Rectangle { width: 30, height: 50, };
+ let rect1 = Rectangle { width: 30, height: 50, };
rect1.width().print();
}
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_15_can_hold/.gitignore b/listings/ch04-using-structs-to-structure-related-data/listing_04_15_can_hold/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch04-using-structs-to-structure-related-data/listing_04_15_can_hold/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_15_can_hold/Scarb.toml b/listings/ch04-using-structs-to-structure-related-data/listing_04_15_can_hold/Scarb.toml
new file mode 100644
index 000000000..18910b023
--- /dev/null
+++ b/listings/ch04-using-structs-to-structure-related-data/listing_04_15_can_hold/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_04_15_can_hold"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch04-using-structs-to-structure-related-data/listing_04_15_can_hold.cairo b/listings/ch04-using-structs-to-structure-related-data/listing_04_15_can_hold/src/lib.cairo
similarity index 80%
rename from listings/ch04-using-structs-to-structure-related-data/listing_04_15_can_hold.cairo
rename to listings/ch04-using-structs-to-structure-related-data/listing_04_15_can_hold/src/lib.cairo
index 815a75689..66dedf44d 100644
--- a/listings/ch04-using-structs-to-structure-related-data/listing_04_15_can_hold.cairo
+++ b/listings/ch04-using-structs-to-structure-related-data/listing_04_15_can_hold/src/lib.cairo
@@ -1,4 +1,4 @@
-// does_not_compile
+//TAG: does_not_compile
// ANCHOR: all
// ANCHOR: no_method
use debug::PrintTrait;
@@ -9,9 +9,9 @@ struct Rectangle {
}
fn main() {
- let rect1 = Rectangle { width: 30, height: 50, };
- let rect2 = Rectangle { width: 10, height: 40, };
- let rect3 = Rectangle { width: 60, height: 45, };
+ let rect1 = Rectangle { width: 30, height: 50, };
+ let rect2 = Rectangle { width: 10, height: 40, };
+ let rect3 = Rectangle { width: 60, height: 45, };
'Can rect1 hold rect2?'.print();
rect1.can_hold(@rect2).print();
diff --git a/listings/ch04-using-structs-to-structure-related-data/no_listing_01_implementation_functions/.gitignore b/listings/ch04-using-structs-to-structure-related-data/no_listing_01_implementation_functions/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch04-using-structs-to-structure-related-data/no_listing_01_implementation_functions/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch04-using-structs-to-structure-related-data/no_listing_01_implementation_functions/Scarb.toml b/listings/ch04-using-structs-to-structure-related-data/no_listing_01_implementation_functions/Scarb.toml
new file mode 100644
index 000000000..4ed15de20
--- /dev/null
+++ b/listings/ch04-using-structs-to-structure-related-data/no_listing_01_implementation_functions/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_01_implementation_functions"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch04-using-structs-to-structure-related-data/no_listing_01_implementation_functions.cairo b/listings/ch04-using-structs-to-structure-related-data/no_listing_01_implementation_functions/src/lib.cairo
similarity index 99%
rename from listings/ch04-using-structs-to-structure-related-data/no_listing_01_implementation_functions.cairo
rename to listings/ch04-using-structs-to-structure-related-data/no_listing_01_implementation_functions/src/lib.cairo
index a8ccc0101..ae36b7418 100644
--- a/listings/ch04-using-structs-to-structure-related-data/no_listing_01_implementation_functions.cairo
+++ b/listings/ch04-using-structs-to-structure-related-data/no_listing_01_implementation_functions/src/lib.cairo
@@ -16,3 +16,4 @@ impl RectangleImpl of RectangleTrait {
}
// ANCHOR_END: here
+
diff --git a/listings/ch04-using-structs-to-structure-related-data/no_listing_02_multiple_impls/.gitignore b/listings/ch04-using-structs-to-structure-related-data/no_listing_02_multiple_impls/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch04-using-structs-to-structure-related-data/no_listing_02_multiple_impls/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch04-using-structs-to-structure-related-data/no_listing_02_multiple_impls/Scarb.toml b/listings/ch04-using-structs-to-structure-related-data/no_listing_02_multiple_impls/Scarb.toml
new file mode 100644
index 000000000..8431301bb
--- /dev/null
+++ b/listings/ch04-using-structs-to-structure-related-data/no_listing_02_multiple_impls/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_02_multiple_impls"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch04-using-structs-to-structure-related-data/no_listing_02_multiple_impls.cairo b/listings/ch04-using-structs-to-structure-related-data/no_listing_02_multiple_impls/src/lib.cairo
similarity index 88%
rename from listings/ch04-using-structs-to-structure-related-data/no_listing_02_multiple_impls.cairo
rename to listings/ch04-using-structs-to-structure-related-data/no_listing_02_multiple_impls/src/lib.cairo
index 41dbfc025..d6daf6ce9 100644
--- a/listings/ch04-using-structs-to-structure-related-data/no_listing_02_multiple_impls.cairo
+++ b/listings/ch04-using-structs-to-structure-related-data/no_listing_02_multiple_impls/src/lib.cairo
@@ -20,7 +20,7 @@ trait RectangleCmp {
impl RectangleCmpImpl of RectangleCmp {
fn can_hold(self: @Rectangle, other: @Rectangle) -> bool {
- *self.width > *other.width & *self.height > *other.height
+ *self.width > *other.width && *self.height > *other.height
}
}
// ANCHOR_END: here
diff --git a/listings/ch05-enums-and-pattern-matching/listing_05_03/.gitignore b/listings/ch05-enums-and-pattern-matching/listing_05_03/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch05-enums-and-pattern-matching/listing_05_03/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch05-enums-and-pattern-matching/listing_05_03/Scarb.toml b/listings/ch05-enums-and-pattern-matching/listing_05_03/Scarb.toml
new file mode 100644
index 000000000..13b80bb40
--- /dev/null
+++ b/listings/ch05-enums-and-pattern-matching/listing_05_03/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_05_03"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch05-enums-and-pattern-matching/listing_05_03.cairo b/listings/ch05-enums-and-pattern-matching/listing_05_03/src/lib.cairo
similarity index 99%
rename from listings/ch05-enums-and-pattern-matching/listing_05_03.cairo
rename to listings/ch05-enums-and-pattern-matching/listing_05_03/src/lib.cairo
index 4eebf80d4..919705178 100644
--- a/listings/ch05-enums-and-pattern-matching/listing_05_03.cairo
+++ b/listings/ch05-enums-and-pattern-matching/listing_05_03/src/lib.cairo
@@ -18,3 +18,4 @@ fn value_in_cents(coin: Coin) -> felt252 {
// ANCHOR_END: function
// ANCHOR_END: all
+
diff --git a/listings/ch05-enums-and-pattern-matching/listing_05_04/.gitignore b/listings/ch05-enums-and-pattern-matching/listing_05_04/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch05-enums-and-pattern-matching/listing_05_04/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch05-enums-and-pattern-matching/listing_05_04/Scarb.toml b/listings/ch05-enums-and-pattern-matching/listing_05_04/Scarb.toml
new file mode 100644
index 000000000..2c7182df3
--- /dev/null
+++ b/listings/ch05-enums-and-pattern-matching/listing_05_04/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_05_04"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch05-enums-and-pattern-matching/listing_05_04.cairo b/listings/ch05-enums-and-pattern-matching/listing_05_04/src/lib.cairo
similarity index 84%
rename from listings/ch05-enums-and-pattern-matching/listing_05_04.cairo
rename to listings/ch05-enums-and-pattern-matching/listing_05_04/src/lib.cairo
index 9b4dbed82..c842e785a 100644
--- a/listings/ch05-enums-and-pattern-matching/listing_05_04.cairo
+++ b/listings/ch05-enums-and-pattern-matching/listing_05_04/src/lib.cairo
@@ -9,5 +9,5 @@ enum Coin {
Penny: (),
Nickel: (),
Dime: (),
- Quarter: (UsState, ),
+ Quarter: (UsState,),
}
diff --git a/listings/ch05-enums-and-pattern-matching/listing_05_05/.gitignore b/listings/ch05-enums-and-pattern-matching/listing_05_05/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch05-enums-and-pattern-matching/listing_05_05/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch05-enums-and-pattern-matching/listing_05_05/Scarb.toml b/listings/ch05-enums-and-pattern-matching/listing_05_05/Scarb.toml
new file mode 100644
index 000000000..2a26cd413
--- /dev/null
+++ b/listings/ch05-enums-and-pattern-matching/listing_05_05/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_05_05"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch05-enums-and-pattern-matching/listing_05_05.cairo b/listings/ch05-enums-and-pattern-matching/listing_05_05/src/lib.cairo
similarity index 72%
rename from listings/ch05-enums-and-pattern-matching/listing_05_05.cairo
rename to listings/ch05-enums-and-pattern-matching/listing_05_05/src/lib.cairo
index cbb7e19d3..f24658ee0 100644
--- a/listings/ch05-enums-and-pattern-matching/listing_05_05.cairo
+++ b/listings/ch05-enums-and-pattern-matching/listing_05_05/src/lib.cairo
@@ -1,10 +1,9 @@
-use option::OptionTrait;
use debug::PrintTrait;
fn plus_one(x: Option) -> Option {
match x {
Option::Some(val) => Option::Some(val + 1),
- Option::None(_) => Option::None(()),
+ Option::None(_) => Option::None,
}
}
@@ -12,6 +11,6 @@ fn main() {
let five: Option = Option::Some(5);
let six: Option = plus_one(five);
six.unwrap().print();
- let none = plus_one(Option::None(()));
+ let none = plus_one(Option::None);
none.unwrap().print();
}
diff --git a/listings/ch05-enums-and-pattern-matching/no_listing_01_enum_example/.gitignore b/listings/ch05-enums-and-pattern-matching/no_listing_01_enum_example/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch05-enums-and-pattern-matching/no_listing_01_enum_example/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch05-enums-and-pattern-matching/no_listing_01_enum_example/Scarb.toml b/listings/ch05-enums-and-pattern-matching/no_listing_01_enum_example/Scarb.toml
new file mode 100644
index 000000000..407c6ecef
--- /dev/null
+++ b/listings/ch05-enums-and-pattern-matching/no_listing_01_enum_example/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_01_enum_example"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch05-enums-and-pattern-matching/no_listing_01_enum_example.cairo b/listings/ch05-enums-and-pattern-matching/no_listing_01_enum_example/src/lib.cairo
similarity index 56%
rename from listings/ch05-enums-and-pattern-matching/no_listing_01_enum_example.cairo
rename to listings/ch05-enums-and-pattern-matching/no_listing_01_enum_example/src/lib.cairo
index 9db1d7da4..2d9ae761f 100644
--- a/listings/ch05-enums-and-pattern-matching/no_listing_01_enum_example.cairo
+++ b/listings/ch05-enums-and-pattern-matching/no_listing_01_enum_example/src/lib.cairo
@@ -2,17 +2,17 @@
// ANCHOR: enum_example
#[derive(Drop)]
enum Direction {
- North: (),
- East: (),
- South: (),
- West: (),
+ North,
+ East,
+ South,
+ West,
}
// ANCHOR_END: enum_example
fn main() {
// ANCHOR: here
- let direction = Direction::North(());
- // ANCHOR_END: here
+ let direction = Direction::North;
+// ANCHOR_END: here
}
// ANCHOR_END: all
diff --git a/listings/ch05-enums-and-pattern-matching/no_listing_02_enum_message/.gitignore b/listings/ch05-enums-and-pattern-matching/no_listing_02_enum_message/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch05-enums-and-pattern-matching/no_listing_02_enum_message/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch05-enums-and-pattern-matching/no_listing_02_enum_message/Scarb.toml b/listings/ch05-enums-and-pattern-matching/no_listing_02_enum_message/Scarb.toml
new file mode 100644
index 000000000..cd1fd236c
--- /dev/null
+++ b/listings/ch05-enums-and-pattern-matching/no_listing_02_enum_message/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_02_enum_message"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch05-enums-and-pattern-matching/no_listing_02_enum_message.cairo b/listings/ch05-enums-and-pattern-matching/no_listing_02_enum_message/src/lib.cairo
similarity index 88%
rename from listings/ch05-enums-and-pattern-matching/no_listing_02_enum_message.cairo
rename to listings/ch05-enums-and-pattern-matching/no_listing_02_enum_message/src/lib.cairo
index b140de116..0e7bdb663 100644
--- a/listings/ch05-enums-and-pattern-matching/no_listing_02_enum_message.cairo
+++ b/listings/ch05-enums-and-pattern-matching/no_listing_02_enum_message/src/lib.cairo
@@ -3,7 +3,7 @@ use debug::PrintTrait;
// ANCHOR: message
#[derive(Drop)]
enum Message {
- Quit: (),
+ Quit,
Echo: felt252,
Move: (u128, u128),
}
@@ -17,7 +17,7 @@ trait Processing {
impl ProcessingImpl of Processing {
fn process(self: Message) {
match self {
- Message::Quit(()) => {
+ Message::Quit => {
'quitting'.print();
},
Message::Echo(value) => {
@@ -32,7 +32,7 @@ impl ProcessingImpl of Processing {
// ANCHOR_END: trait_impl
fn main() {
// ANCHOR: main
- let msg: Message = Message::Quit(());
+ let msg: Message = Message::Quit;
msg.process();
// ANCHOR_END: main
}
diff --git a/listings/ch05-enums-and-pattern-matching/no_listing_03_enum_option/.gitignore b/listings/ch05-enums-and-pattern-matching/no_listing_03_enum_option/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch05-enums-and-pattern-matching/no_listing_03_enum_option/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch05-enums-and-pattern-matching/no_listing_03_enum_option/Scarb.toml b/listings/ch05-enums-and-pattern-matching/no_listing_03_enum_option/Scarb.toml
new file mode 100644
index 000000000..45bf5b470
--- /dev/null
+++ b/listings/ch05-enums-and-pattern-matching/no_listing_03_enum_option/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_03_enum_option"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch05-enums-and-pattern-matching/no_listing_03_enum_option.cairo b/listings/ch05-enums-and-pattern-matching/no_listing_03_enum_option/src/lib.cairo
similarity index 85%
rename from listings/ch05-enums-and-pattern-matching/no_listing_03_enum_option.cairo
rename to listings/ch05-enums-and-pattern-matching/no_listing_03_enum_option/src/lib.cairo
index ef95ce74d..1d3d9d39d 100644
--- a/listings/ch05-enums-and-pattern-matching/no_listing_03_enum_option.cairo
+++ b/listings/ch05-enums-and-pattern-matching/no_listing_03_enum_option/src/lib.cairo
@@ -1,9 +1,8 @@
-use array::ArrayTrait;
use debug::PrintTrait;
-use option::OptionTrait;
+
fn find_value_recursive(arr: @Array, value: felt252, index: usize) -> Option {
if index >= arr.len() {
- return Option::None(());
+ return Option::None;
}
if *arr.at(index) == value {
@@ -16,15 +15,15 @@ fn find_value_recursive(arr: @Array, value: felt252, index: usize) -> O
fn find_value_iterative(arr: @Array, value: felt252) -> Option {
let length = arr.len();
let mut index = 0;
- let mut found: Option = Option::None(());
+ let mut found: Option = Option::None;
loop {
if index < length {
if *arr.at(index) == value {
found = Option::Some(index);
- break ();
+ break;
}
} else {
- break ();
+ break;
}
index += 1;
};
@@ -50,7 +49,7 @@ fn test_increase_amount() {
'it worked'.print();
}
},
- Option::None(()) => {
+ Option::None => {
'not found'.print();
},
}
@@ -60,7 +59,7 @@ fn test_increase_amount() {
'it worked'.print();
}
},
- Option::None(()) => {
+ Option::None => {
'not found'.print();
},
}
diff --git a/listings/ch05-enums-and-pattern-matching/no_listing_04_match_arms/.gitignore b/listings/ch05-enums-and-pattern-matching/no_listing_04_match_arms/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch05-enums-and-pattern-matching/no_listing_04_match_arms/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch05-enums-and-pattern-matching/no_listing_04_match_arms/Scarb.toml b/listings/ch05-enums-and-pattern-matching/no_listing_04_match_arms/Scarb.toml
new file mode 100644
index 000000000..a9f754ed7
--- /dev/null
+++ b/listings/ch05-enums-and-pattern-matching/no_listing_04_match_arms/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_04_match_arms"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch05-enums-and-pattern-matching/no_listing_04_match_arms.cairo b/listings/ch05-enums-and-pattern-matching/no_listing_04_match_arms/src/lib.cairo
similarity index 90%
rename from listings/ch05-enums-and-pattern-matching/no_listing_04_match_arms.cairo
rename to listings/ch05-enums-and-pattern-matching/no_listing_04_match_arms/src/lib.cairo
index cb0c06473..682bb7f95 100644
--- a/listings/ch05-enums-and-pattern-matching/no_listing_04_match_arms.cairo
+++ b/listings/ch05-enums-and-pattern-matching/no_listing_04_match_arms/src/lib.cairo
@@ -6,7 +6,7 @@ enum Coin {
Quarter: (),
}
-// ANCHOR: main
+// ANCHOR: here
fn value_in_cents(coin: Coin) -> felt252 {
match coin {
Coin::Penny(_) => {
@@ -18,3 +18,6 @@ fn value_in_cents(coin: Coin) -> felt252 {
Coin::Quarter(_) => 25,
}
}
+// ANCHOR_END: here
+
+
diff --git a/listings/ch05-enums-and-pattern-matching/no_listing_05_print_enum/.gitignore b/listings/ch05-enums-and-pattern-matching/no_listing_05_print_enum/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch05-enums-and-pattern-matching/no_listing_05_print_enum/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch05-enums-and-pattern-matching/no_listing_05_print_enum/Scarb.toml b/listings/ch05-enums-and-pattern-matching/no_listing_05_print_enum/Scarb.toml
new file mode 100644
index 000000000..ad28eebe4
--- /dev/null
+++ b/listings/ch05-enums-and-pattern-matching/no_listing_05_print_enum/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_05_print_enum"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch05-enums-and-pattern-matching/no_listing_05_print_enum.cairo b/listings/ch05-enums-and-pattern-matching/no_listing_05_print_enum/src/lib.cairo
similarity index 96%
rename from listings/ch05-enums-and-pattern-matching/no_listing_05_print_enum.cairo
rename to listings/ch05-enums-and-pattern-matching/no_listing_05_print_enum/src/lib.cairo
index cac6b628e..4165e2835 100644
--- a/listings/ch05-enums-and-pattern-matching/no_listing_05_print_enum.cairo
+++ b/listings/ch05-enums-and-pattern-matching/no_listing_05_print_enum/src/lib.cairo
@@ -12,7 +12,7 @@ enum Coin {
Penny: (),
Nickel: (),
Dime: (),
- Quarter: (UsState, ),
+ Quarter: UsState,
}
// ANCHOR_END: enum_def
@@ -41,3 +41,4 @@ impl UsStatePrintImpl of PrintTrait {
}
// ANCHOR_END: print_impl
+
diff --git a/listings/ch05-enums-and-pattern-matching/no_listing_06_match_zero/.gitignore b/listings/ch05-enums-and-pattern-matching/no_listing_06_match_zero/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch05-enums-and-pattern-matching/no_listing_06_match_zero/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch05-enums-and-pattern-matching/no_listing_06_match_zero/Scarb.toml b/listings/ch05-enums-and-pattern-matching/no_listing_06_match_zero/Scarb.toml
new file mode 100644
index 000000000..8d96b6fdd
--- /dev/null
+++ b/listings/ch05-enums-and-pattern-matching/no_listing_06_match_zero/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_06_match_zero"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch05-enums-and-pattern-matching/no_listing_06_match_zero.cairo b/listings/ch05-enums-and-pattern-matching/no_listing_06_match_zero/src/lib.cairo
similarity index 99%
rename from listings/ch05-enums-and-pattern-matching/no_listing_06_match_zero.cairo
rename to listings/ch05-enums-and-pattern-matching/no_listing_06_match_zero/src/lib.cairo
index 35b6acd25..96f817bb0 100644
--- a/listings/ch05-enums-and-pattern-matching/no_listing_06_match_zero.cairo
+++ b/listings/ch05-enums-and-pattern-matching/no_listing_06_match_zero/src/lib.cairo
@@ -9,3 +9,4 @@ fn did_i_win(nb: felt252) {
}
// ANCHOR_END: here
+
diff --git a/listings/ch05-enums-and-pattern-matching/no_listing_07_missing_match_arm/.gitignore b/listings/ch05-enums-and-pattern-matching/no_listing_07_missing_match_arm/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch05-enums-and-pattern-matching/no_listing_07_missing_match_arm/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch05-enums-and-pattern-matching/no_listing_07_missing_match_arm/Scarb.toml b/listings/ch05-enums-and-pattern-matching/no_listing_07_missing_match_arm/Scarb.toml
new file mode 100644
index 000000000..2d464a91a
--- /dev/null
+++ b/listings/ch05-enums-and-pattern-matching/no_listing_07_missing_match_arm/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_07_missing_match_arm"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch05-enums-and-pattern-matching/no_listing_07_missing_match_arm/src/lib.cairo b/listings/ch05-enums-and-pattern-matching/no_listing_07_missing_match_arm/src/lib.cairo
new file mode 100644
index 000000000..0411e8b8f
--- /dev/null
+++ b/listings/ch05-enums-and-pattern-matching/no_listing_07_missing_match_arm/src/lib.cairo
@@ -0,0 +1,19 @@
+//TAG: does_not_compile
+
+use debug::PrintTrait;
+
+//ANCHOR: here
+fn plus_one(x: Option) -> Option {
+ match x {
+ Option::Some(val) => Option::Some(val + 1),
+ }
+}
+//ANCHOR_END: here
+
+fn main() {
+ let five: Option = Option::Some(5);
+ let six: Option = plus_one(five);
+ six.unwrap().print();
+ let none = plus_one(Option::None);
+ none.unwrap().print();
+}
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_01/.gitignore b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_01/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_01/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_01/Scarb.toml b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_01/Scarb.toml
new file mode 100644
index 000000000..7b5dc5092
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_01/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_06_01"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_01.cairo b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_01/src/lib.cairo
similarity index 100%
rename from listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_01.cairo
rename to listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_01/src/lib.cairo
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_03/.gitignore b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_03/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_03/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_03/Scarb.toml b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_03/Scarb.toml
new file mode 100644
index 000000000..b31c51bd9
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_03/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_06_03"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_03.cairo b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_03/src/lib.cairo
similarity index 94%
rename from listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_03.cairo
rename to listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_03/src/lib.cairo
index b308ef956..daabd4c5f 100644
--- a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_03.cairo
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_03/src/lib.cairo
@@ -1,3 +1,4 @@
+//TAG: does_not_compile
mod front_of_house {
mod hosting {
fn add_to_waitlist() {}
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_04/.gitignore b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_04/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_04/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_04/Scarb.toml b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_04/Scarb.toml
new file mode 100644
index 000000000..4e66bae77
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_04/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_06_04"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_04.cairo b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_04/src/lib.cairo
similarity index 100%
rename from listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_04.cairo
rename to listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_04/src/lib.cairo
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_05/.gitignore b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_05/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_05/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_05/Scarb.toml b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_05/Scarb.toml
new file mode 100644
index 000000000..89da1587a
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_05/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_06_05"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_05.cairo b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_05/src/lib.cairo
similarity index 89%
rename from listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_05.cairo
rename to listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_05/src/lib.cairo
index 10ac3229f..a1f5d88ce 100644
--- a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_05.cairo
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_05/src/lib.cairo
@@ -1,4 +1,4 @@
-// does_not_compile
+//TAG: does_not_compile
mod front_of_house {
mod hosting {
fn add_to_waitlist() {}
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_06/.gitignore b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_06/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_06/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_06/Scarb.toml b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_06/Scarb.toml
new file mode 100644
index 000000000..5600f9b9c
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_06/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_06_06"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_06.cairo b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_06/src/lib.cairo
similarity index 89%
rename from listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_06.cairo
rename to listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_06/src/lib.cairo
index 928726676..91adbd444 100644
--- a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_06.cairo
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_06/src/lib.cairo
@@ -1,4 +1,4 @@
-// does_not_compile
+//TAG: does_not_compile
mod front_of_house {
mod hosting {
fn add_to_waitlist() {}
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_07/.gitignore b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_07/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_07/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_07/Scarb.toml b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_07/Scarb.toml
new file mode 100644
index 000000000..46ba47977
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_07/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_06_07"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_07.cairo b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_07/src/lib.cairo
similarity index 88%
rename from listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_07.cairo
rename to listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_07/src/lib.cairo
index 84f0a4337..3db58df7c 100644
--- a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_07.cairo
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_07/src/lib.cairo
@@ -1,3 +1,4 @@
+//TAG: does_not_compile
mod front_of_house {
mod hosting {
fn add_to_waitlist() {}
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_08/.gitignore b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_08/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_08/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_08/Scarb.toml b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_08/Scarb.toml
new file mode 100644
index 000000000..0d468918d
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_08/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_06_08"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_08.cairo b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_08/src/lib.cairo
similarity index 74%
rename from listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_08.cairo
rename to listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_08/src/lib.cairo
index 68276118c..9890f8749 100644
--- a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_08.cairo
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_08/src/lib.cairo
@@ -1,5 +1,3 @@
-use array::ArrayTrait;
-
fn main() {
let mut arr = ArrayTrait::new();
arr.append(1);
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_09/.gitignore b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_09/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_09/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_09/Scarb.toml b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_09/Scarb.toml
new file mode 100644
index 000000000..88557e02a
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_09/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_06_09"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_09.cairo b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_09/src/lib.cairo
similarity index 100%
rename from listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_09.cairo
rename to listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_09/src/lib.cairo
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_10/.gitignore b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_10/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_10/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_10/Scarb.toml b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_10/Scarb.toml
new file mode 100644
index 000000000..10d4d6558
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_10/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_06_10"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_10.cairo b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_10/src/lib.cairo
similarity index 100%
rename from listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_10.cairo
rename to listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_10/src/lib.cairo
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_11/.gitignore b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_11/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_11/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_11/Scarb.toml b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_11/Scarb.toml
new file mode 100644
index 000000000..4276a23d1
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_11/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_06_11"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_11.cairo b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_11/src/lib.cairo
similarity index 88%
rename from listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_11.cairo
rename to listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_11/src/lib.cairo
index fde2ffa9e..783f73a58 100644
--- a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_11.cairo
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_11/src/lib.cairo
@@ -1,4 +1,4 @@
-// does_not_compile
+//TAG: does_not_compile
mod front_of_house {
mod hosting {
fn add_to_waitlist() {}
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_12/.gitignore b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_12/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_12/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_12/Scarb.toml b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_12/Scarb.toml
new file mode 100644
index 000000000..e721af9d7
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_12/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_06_12"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_12.cairo b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_12/src/lib.cairo
similarity index 83%
rename from listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_12.cairo
rename to listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_12/src/lib.cairo
index b04f162d6..19921e561 100644
--- a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_12.cairo
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_12/src/lib.cairo
@@ -1,4 +1,4 @@
-// does_not_compile
+//TAG: does_not_compile
mod front_of_house;
use restaurant::front_of_house::hosting;
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_13/.gitignore b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_13/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_13/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_13/Scarb.toml b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_13/Scarb.toml
new file mode 100644
index 000000000..75c00ee65
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_13/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_06_13"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_13.cairo b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_13/src/lib.cairo
similarity index 100%
rename from listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_13.cairo
rename to listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/listing_06_13/src/lib.cairo
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/no_listing_01_lib/.gitignore b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/no_listing_01_lib/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/no_listing_01_lib/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/no_listing_01_lib/Scarb.toml b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/no_listing_01_lib/Scarb.toml
new file mode 100644
index 000000000..90a4ede79
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/no_listing_01_lib/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_01_lib"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/no_listing_01_lib.cairo b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/no_listing_01_lib/src/lib.cairo
similarity index 80%
rename from listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/no_listing_01_lib.cairo
rename to listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/no_listing_01_lib/src/lib.cairo
index 621827d07..87041362a 100644
--- a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/no_listing_01_lib.cairo
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/no_listing_01_lib/src/lib.cairo
@@ -1,4 +1,4 @@
-// does_not_compile
+//TAG: does_not_compile
use garden::vegetables::Asparagus;
mod garden;
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/no_listing_02_garden/.gitignore b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/no_listing_02_garden/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/no_listing_02_garden/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/no_listing_02_garden/Scarb.toml b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/no_listing_02_garden/Scarb.toml
new file mode 100644
index 000000000..c5e9e67ea
--- /dev/null
+++ b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/no_listing_02_garden/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_02_garden"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/no_listing_02_garden.cairo b/listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/no_listing_02_garden/src/lib.cairo
similarity index 100%
rename from listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/no_listing_02_garden.cairo
rename to listings/ch06-managing-cairo-projects-with-packages-crates-and-modules/no_listing_02_garden/src/lib.cairo
diff --git a/listings/ch07-generic-types-and-traits/no_listing_01_missing_tdrop/.gitignore b/listings/ch07-generic-types-and-traits/no_listing_01_missing_tdrop/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_01_missing_tdrop/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch07-generic-types-and-traits/no_listing_01_missing_tdrop/Scarb.toml b/listings/ch07-generic-types-and-traits/no_listing_01_missing_tdrop/Scarb.toml
new file mode 100644
index 000000000..930478f31
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_01_missing_tdrop/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_01_missing_tdrop"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch07-generic-types-and-traits/no_listing_01_missing_tdrop.cairo b/listings/ch07-generic-types-and-traits/no_listing_01_missing_tdrop/src/lib.cairo
similarity index 91%
rename from listings/ch07-generic-types-and-traits/no_listing_01_missing_tdrop.cairo
rename to listings/ch07-generic-types-and-traits/no_listing_01_missing_tdrop/src/lib.cairo
index 9bc3e1d0a..7fef27cc2 100644
--- a/listings/ch07-generic-types-and-traits/no_listing_01_missing_tdrop.cairo
+++ b/listings/ch07-generic-types-and-traits/no_listing_01_missing_tdrop/src/lib.cairo
@@ -1,6 +1,4 @@
-// does_not_compile
-
-use array::ArrayTrait;
+//TAG: does_not_compile
// Specify generic type T between the angulars
fn largest_list(l1: Array, l2: Array) -> Array {
diff --git a/listings/ch07-generic-types-and-traits/no_listing_02_with_tdrop/.gitignore b/listings/ch07-generic-types-and-traits/no_listing_02_with_tdrop/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_02_with_tdrop/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch07-generic-types-and-traits/no_listing_02_with_tdrop/Scarb.toml b/listings/ch07-generic-types-and-traits/no_listing_02_with_tdrop/Scarb.toml
new file mode 100644
index 000000000..578ca26a8
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_02_with_tdrop/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_02_with_tdrop"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch07-generic-types-and-traits/no_listing_02_with_tdrop.cairo b/listings/ch07-generic-types-and-traits/no_listing_02_with_tdrop/src/lib.cairo
similarity index 87%
rename from listings/ch07-generic-types-and-traits/no_listing_02_with_tdrop.cairo
rename to listings/ch07-generic-types-and-traits/no_listing_02_with_tdrop/src/lib.cairo
index 348274c32..54e7d595a 100644
--- a/listings/ch07-generic-types-and-traits/no_listing_02_with_tdrop.cairo
+++ b/listings/ch07-generic-types-and-traits/no_listing_02_with_tdrop/src/lib.cairo
@@ -1,4 +1,3 @@
-use array::ArrayTrait;
fn largest_list>(l1: Array, l2: Array) -> Array {
if l1.len() > l2.len() {
l1
diff --git a/listings/ch07-generic-types-and-traits/no_listing_03_missing_tcopy/.gitignore b/listings/ch07-generic-types-and-traits/no_listing_03_missing_tcopy/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_03_missing_tcopy/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch07-generic-types-and-traits/no_listing_03_missing_tcopy/Scarb.toml b/listings/ch07-generic-types-and-traits/no_listing_03_missing_tcopy/Scarb.toml
new file mode 100644
index 000000000..9762cd009
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_03_missing_tcopy/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_03_missing_tcopy"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch07-generic-types-and-traits/no_listing_03_missing_tcopy.cairo b/listings/ch07-generic-types-and-traits/no_listing_03_missing_tcopy/src/lib.cairo
similarity index 95%
rename from listings/ch07-generic-types-and-traits/no_listing_03_missing_tcopy.cairo
rename to listings/ch07-generic-types-and-traits/no_listing_03_missing_tcopy/src/lib.cairo
index 3fb19b0d0..224246c52 100644
--- a/listings/ch07-generic-types-and-traits/no_listing_03_missing_tcopy.cairo
+++ b/listings/ch07-generic-types-and-traits/no_listing_03_missing_tcopy/src/lib.cairo
@@ -1,5 +1,4 @@
-// does_not_compile
-use array::ArrayTrait;
+//TAG: does_not_compile
// Given a list of T get the smallest one.
// The PartialOrd trait implements comparison operations for T
diff --git a/listings/ch07-generic-types-and-traits/no_listing_04_with_tcopy/.gitignore b/listings/ch07-generic-types-and-traits/no_listing_04_with_tcopy/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_04_with_tcopy/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch07-generic-types-and-traits/no_listing_04_with_tcopy/Scarb.toml b/listings/ch07-generic-types-and-traits/no_listing_04_with_tcopy/Scarb.toml
new file mode 100644
index 000000000..735b68760
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_04_with_tcopy/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_04_with_tcopy"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch07-generic-types-and-traits/no_listing_04_with_tcopy.cairo b/listings/ch07-generic-types-and-traits/no_listing_04_with_tcopy/src/lib.cairo
similarity index 94%
rename from listings/ch07-generic-types-and-traits/no_listing_04_with_tcopy.cairo
rename to listings/ch07-generic-types-and-traits/no_listing_04_with_tcopy/src/lib.cairo
index c8b740f51..7f3e9485d 100644
--- a/listings/ch07-generic-types-and-traits/no_listing_04_with_tcopy.cairo
+++ b/listings/ch07-generic-types-and-traits/no_listing_04_with_tcopy/src/lib.cairo
@@ -1,4 +1,3 @@
-use array::ArrayTrait;
fn smallest_element, impl TCopy: Copy, impl TDrop: Drop>(
list: @Array
) -> T {
diff --git a/listings/ch07-generic-types-and-traits/no_listing_05_derive_generics/.gitignore b/listings/ch07-generic-types-and-traits/no_listing_05_derive_generics/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_05_derive_generics/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch07-generic-types-and-traits/no_listing_05_derive_generics/Scarb.toml b/listings/ch07-generic-types-and-traits/no_listing_05_derive_generics/Scarb.toml
new file mode 100644
index 000000000..8fa7ee52c
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_05_derive_generics/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_05_derive_generics"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch07-generic-types-and-traits/no_listing_05_derive_generics.cairo b/listings/ch07-generic-types-and-traits/no_listing_05_derive_generics/src/lib.cairo
similarity index 100%
rename from listings/ch07-generic-types-and-traits/no_listing_05_derive_generics.cairo
rename to listings/ch07-generic-types-and-traits/no_listing_05_derive_generics/src/lib.cairo
diff --git a/listings/ch07-generic-types-and-traits/no_listing_06_drop_explicit/.gitignore b/listings/ch07-generic-types-and-traits/no_listing_06_drop_explicit/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_06_drop_explicit/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch07-generic-types-and-traits/no_listing_06_drop_explicit/Scarb.toml b/listings/ch07-generic-types-and-traits/no_listing_06_drop_explicit/Scarb.toml
new file mode 100644
index 000000000..51eebf163
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_06_drop_explicit/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_06_drop_explicit"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch07-generic-types-and-traits/no_listing_06_drop_explicit.cairo b/listings/ch07-generic-types-and-traits/no_listing_06_drop_explicit/src/lib.cairo
similarity index 100%
rename from listings/ch07-generic-types-and-traits/no_listing_06_drop_explicit.cairo
rename to listings/ch07-generic-types-and-traits/no_listing_06_drop_explicit/src/lib.cairo
diff --git a/listings/ch07-generic-types-and-traits/no_listing_07_two_generics/.gitignore b/listings/ch07-generic-types-and-traits/no_listing_07_two_generics/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_07_two_generics/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch07-generic-types-and-traits/no_listing_07_two_generics/Scarb.toml b/listings/ch07-generic-types-and-traits/no_listing_07_two_generics/Scarb.toml
new file mode 100644
index 000000000..35c81abfb
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_07_two_generics/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_07_two_generics"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch07-generic-types-and-traits/no_listing_07_two_generics.cairo b/listings/ch07-generic-types-and-traits/no_listing_07_two_generics/src/lib.cairo
similarity index 100%
rename from listings/ch07-generic-types-and-traits/no_listing_07_two_generics.cairo
rename to listings/ch07-generic-types-and-traits/no_listing_07_two_generics/src/lib.cairo
diff --git a/listings/ch07-generic-types-and-traits/no_listing_08_option/.gitignore b/listings/ch07-generic-types-and-traits/no_listing_08_option/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_08_option/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch07-generic-types-and-traits/no_listing_08_option/Scarb.toml b/listings/ch07-generic-types-and-traits/no_listing_08_option/Scarb.toml
new file mode 100644
index 000000000..78a1db578
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_08_option/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_08_option"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch07-generic-types-and-traits/no_listing_08_option.cairo b/listings/ch07-generic-types-and-traits/no_listing_08_option/src/lib.cairo
similarity index 69%
rename from listings/ch07-generic-types-and-traits/no_listing_08_option.cairo
rename to listings/ch07-generic-types-and-traits/no_listing_08_option/src/lib.cairo
index efb36460a..3c933b8e0 100644
--- a/listings/ch07-generic-types-and-traits/no_listing_08_option.cairo
+++ b/listings/ch07-generic-types-and-traits/no_listing_08_option/src/lib.cairo
@@ -1,4 +1,4 @@
enum Option {
Some: T,
- None: (),
+ None,
}
diff --git a/listings/ch07-generic-types-and-traits/no_listing_09_result/.gitignore b/listings/ch07-generic-types-and-traits/no_listing_09_result/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_09_result/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch07-generic-types-and-traits/no_listing_09_result/Scarb.toml b/listings/ch07-generic-types-and-traits/no_listing_09_result/Scarb.toml
new file mode 100644
index 000000000..7a054cbbc
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_09_result/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_09_result"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch07-generic-types-and-traits/no_listing_09_result.cairo b/listings/ch07-generic-types-and-traits/no_listing_09_result/src/lib.cairo
similarity index 100%
rename from listings/ch07-generic-types-and-traits/no_listing_09_result.cairo
rename to listings/ch07-generic-types-and-traits/no_listing_09_result/src/lib.cairo
diff --git a/listings/ch07-generic-types-and-traits/no_listing_10_generic_methods/.gitignore b/listings/ch07-generic-types-and-traits/no_listing_10_generic_methods/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_10_generic_methods/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch07-generic-types-and-traits/no_listing_10_generic_methods/Scarb.toml b/listings/ch07-generic-types-and-traits/no_listing_10_generic_methods/Scarb.toml
new file mode 100644
index 000000000..451d4cb5b
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_10_generic_methods/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_10_generic_methods"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch07-generic-types-and-traits/no_listing_10_generic_methods.cairo b/listings/ch07-generic-types-and-traits/no_listing_10_generic_methods/src/lib.cairo
similarity index 100%
rename from listings/ch07-generic-types-and-traits/no_listing_10_generic_methods.cairo
rename to listings/ch07-generic-types-and-traits/no_listing_10_generic_methods/src/lib.cairo
diff --git a/listings/ch07-generic-types-and-traits/no_listing_11_constrained_generics/.gitignore b/listings/ch07-generic-types-and-traits/no_listing_11_constrained_generics/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_11_constrained_generics/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch07-generic-types-and-traits/no_listing_11_constrained_generics/Scarb.toml b/listings/ch07-generic-types-and-traits/no_listing_11_constrained_generics/Scarb.toml
new file mode 100644
index 000000000..36d0db1df
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_11_constrained_generics/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_11_constrained_generics"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch07-generic-types-and-traits/no_listing_11_constrained_generics.cairo b/listings/ch07-generic-types-and-traits/no_listing_11_constrained_generics/src/lib.cairo
similarity index 100%
rename from listings/ch07-generic-types-and-traits/no_listing_11_constrained_generics.cairo
rename to listings/ch07-generic-types-and-traits/no_listing_11_constrained_generics/src/lib.cairo
diff --git a/listings/ch07-generic-types-and-traits/no_listing_12_not_compiling/.gitignore b/listings/ch07-generic-types-and-traits/no_listing_12_not_compiling/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_12_not_compiling/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch07-generic-types-and-traits/no_listing_12_not_compiling/Scarb.toml b/listings/ch07-generic-types-and-traits/no_listing_12_not_compiling/Scarb.toml
new file mode 100644
index 000000000..71e548448
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_12_not_compiling/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_12_not_compiling"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch07-generic-types-and-traits/no_listing_12_not_compiling.cairo b/listings/ch07-generic-types-and-traits/no_listing_12_not_compiling/src/lib.cairo
similarity index 94%
rename from listings/ch07-generic-types-and-traits/no_listing_12_not_compiling.cairo
rename to listings/ch07-generic-types-and-traits/no_listing_12_not_compiling/src/lib.cairo
index 719ca23f6..a53e1a572 100644
--- a/listings/ch07-generic-types-and-traits/no_listing_12_not_compiling.cairo
+++ b/listings/ch07-generic-types-and-traits/no_listing_12_not_compiling/src/lib.cairo
@@ -1,4 +1,4 @@
-// does_not_compile
+//TAG: does_not_compile
struct Wallet {
balance: T,
address: U,
diff --git a/listings/ch07-generic-types-and-traits/no_listing_13_compiling/.gitignore b/listings/ch07-generic-types-and-traits/no_listing_13_compiling/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_13_compiling/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch07-generic-types-and-traits/no_listing_13_compiling/Scarb.toml b/listings/ch07-generic-types-and-traits/no_listing_13_compiling/Scarb.toml
new file mode 100644
index 000000000..5d9a57dc6
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_13_compiling/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_13_compiling"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch07-generic-types-and-traits/no_listing_13_compiling.cairo b/listings/ch07-generic-types-and-traits/no_listing_13_compiling/src/lib.cairo
similarity index 100%
rename from listings/ch07-generic-types-and-traits/no_listing_13_compiling.cairo
rename to listings/ch07-generic-types-and-traits/no_listing_13_compiling/src/lib.cairo
diff --git a/listings/ch07-generic-types-and-traits/no_listing_14_traits/.gitignore b/listings/ch07-generic-types-and-traits/no_listing_14_traits/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_14_traits/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch07-generic-types-and-traits/no_listing_14_traits/Scarb.toml b/listings/ch07-generic-types-and-traits/no_listing_14_traits/Scarb.toml
new file mode 100644
index 000000000..ab527f47b
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_14_traits/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_14_traits"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch07-generic-types-and-traits/no_listing_14_traits/src/lib.cairo b/listings/ch07-generic-types-and-traits/no_listing_14_traits/src/lib.cairo
new file mode 100644
index 000000000..93ea9d6d5
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_14_traits/src/lib.cairo
@@ -0,0 +1,45 @@
+use debug::PrintTrait;
+
+#[derive(Drop, Copy)]
+struct Rectangle {
+ height: u64,
+ width: u64,
+}
+
+//ANCHOR: trait
+trait ShapeGeometry {
+ fn boundary(self: Rectangle) -> u64;
+ fn area(self: Rectangle) -> u64;
+}
+//ANCHOR_END: trait
+
+//ANCHOR: impl
+impl RectangleGeometry of ShapeGeometry {
+ fn boundary(self: Rectangle) -> u64 {
+ 2 * (self.height + self.width)
+ }
+ fn area(self: Rectangle) -> u64 {
+ self.height * self.width
+ }
+}
+//ANCHOR_END: impl
+
+//ANCHOR: main
+fn main() {
+ let rect = Rectangle { height: 5, width: 10 }; // Rectangle instantiation
+
+ // First way, as a method on the struct instance
+ let area1 = rect.area();
+ // Second way, from the implementation
+ let area2 = RectangleGeometry::area(rect);
+ // Third way, from the trait
+ let area3 = ShapeGeometry::area(rect);
+
+ // `area1` has same value as `area2` and `area3`
+ area1.print();
+ area2.print();
+ area3.print();
+}
+//ANCHOR_END: main
+
+
diff --git a/listings/ch07-generic-types-and-traits/no_listing_15_generate_trait/.gitignore b/listings/ch07-generic-types-and-traits/no_listing_15_generate_trait/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_15_generate_trait/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch07-generic-types-and-traits/no_listing_15_generate_trait/Scarb.toml b/listings/ch07-generic-types-and-traits/no_listing_15_generate_trait/Scarb.toml
new file mode 100644
index 000000000..794830652
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_15_generate_trait/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_15_generate_trait"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch07-generic-types-and-traits/no_listing_15_generate_trait/src/lib.cairo b/listings/ch07-generic-types-and-traits/no_listing_15_generate_trait/src/lib.cairo
new file mode 100644
index 000000000..506ac110c
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_15_generate_trait/src/lib.cairo
@@ -0,0 +1,14 @@
+struct Rectangle {
+ height: u64,
+ width: u64,
+}
+
+#[generate_trait]
+impl RectangleGeometry of RectangleGeometryTrait {
+ fn boundary(self: Rectangle) -> u64 {
+ 2 * (self.height + self.width)
+ }
+ fn area(self: Rectangle) -> u64 {
+ self.height * self.width
+ }
+}
diff --git a/listings/ch07-generic-types-and-traits/no_listing_16_generic_traits/.gitignore b/listings/ch07-generic-types-and-traits/no_listing_16_generic_traits/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_16_generic_traits/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch07-generic-types-and-traits/no_listing_16_generic_traits/Scarb.toml b/listings/ch07-generic-types-and-traits/no_listing_16_generic_traits/Scarb.toml
new file mode 100644
index 000000000..3f77c8bbf
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_16_generic_traits/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_16_generic_traits"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch07-generic-types-and-traits/no_listing_16_generic_traits/src/lib.cairo b/listings/ch07-generic-types-and-traits/no_listing_16_generic_traits/src/lib.cairo
new file mode 100644
index 000000000..6b3a2f895
--- /dev/null
+++ b/listings/ch07-generic-types-and-traits/no_listing_16_generic_traits/src/lib.cairo
@@ -0,0 +1,50 @@
+use debug::PrintTrait;
+
+#[derive(Copy, Drop)]
+struct Rectangle {
+ height: u64,
+ width: u64,
+}
+
+#[derive(Copy, Drop)]
+struct Circle {
+ radius: u64
+}
+
+// Here T is an alias type which will be provided during implementation
+trait ShapeGeometry {
+ fn boundary(self: T) -> u64;
+ fn area(self: T) -> u64;
+}
+
+// Implementation RectangleGeometry passes in
+// to implement the trait for that type
+impl RectangleGeometry of ShapeGeometry {
+ fn boundary(self: Rectangle) -> u64 {
+ 2 * (self.height + self.width)
+ }
+ fn area(self: Rectangle) -> u64 {
+ self.height * self.width
+ }
+}
+
+// We might have another struct Circle
+// which can use the same trait spec
+impl CircleGeometry of ShapeGeometry {
+ fn boundary(self: Circle) -> u64 {
+ (2 * 314 * self.radius) / 100
+ }
+ fn area(self: Circle) -> u64 {
+ (314 * self.radius * self.radius) / 100
+ }
+}
+
+fn main() {
+ let rect = Rectangle { height: 5, width: 7 };
+ rect.area().print(); // 35
+ rect.boundary().print(); // 24
+
+ let circ = Circle { radius: 5 };
+ circ.area().print(); // 78
+ circ.boundary().print(); // 31
+}
diff --git a/listings/ch08-testing-cairo-programs/listing_08_01_02/.gitignore b/listings/ch08-testing-cairo-programs/listing_08_01_02/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/listing_08_01_02/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch08-testing-cairo-programs/listing_08_01_02/Scarb.toml b/listings/ch08-testing-cairo-programs/listing_08_01_02/Scarb.toml
new file mode 100644
index 000000000..c9ccda601
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/listing_08_01_02/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_08_01_02"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch08-testing-cairo-programs/listing_08_01_03.cairo b/listings/ch08-testing-cairo-programs/listing_08_01_02/src/lib.cairo
similarity index 63%
rename from listings/ch08-testing-cairo-programs/listing_08_01_03.cairo
rename to listings/ch08-testing-cairo-programs/listing_08_01_02/src/lib.cairo
index ce4bfb393..f49e01d3a 100644
--- a/listings/ch08-testing-cairo-programs/listing_08_01_03.cairo
+++ b/listings/ch08-testing-cairo-programs/listing_08_01_02/src/lib.cairo
@@ -14,13 +14,5 @@ mod tests {
let result = 2 + 2;
assert(result == 4, 'result is not 4');
}
- // ANCHOR_END: exploration
-
- // ANCHOR: another
- #[test]
- fn another() {
- let result = 2 + 2;
- assert(result == 6, 'Make this test fail');
- }
-// ANCHOR_END: another
+// ANCHOR_END: exploration
}
diff --git a/listings/ch08-testing-cairo-programs/listing_08_03/.gitignore b/listings/ch08-testing-cairo-programs/listing_08_03/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/listing_08_03/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch08-testing-cairo-programs/listing_08_03/Scarb.toml b/listings/ch08-testing-cairo-programs/listing_08_03/Scarb.toml
new file mode 100644
index 000000000..3383fae7e
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/listing_08_03/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_08_03"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch08-testing-cairo-programs/listing_08_03/src/lib.cairo b/listings/ch08-testing-cairo-programs/listing_08_03/src/lib.cairo
new file mode 100644
index 000000000..a908dc053
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/listing_08_03/src/lib.cairo
@@ -0,0 +1,11 @@
+//TAG: tests_fail
+#[cfg(test)]
+mod tests {
+ // ANCHOR: another
+ #[test]
+ fn another() {
+ let result = 2 + 2;
+ assert(result == 6, 'Make this test fail');
+ }
+// ANCHOR_END: another
+}
diff --git a/listings/ch08-testing-cairo-programs/listing_08_06/.gitignore b/listings/ch08-testing-cairo-programs/listing_08_06/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/listing_08_06/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch08-testing-cairo-programs/listing_08_06/Scarb.toml b/listings/ch08-testing-cairo-programs/listing_08_06/Scarb.toml
new file mode 100644
index 000000000..27f82c67f
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/listing_08_06/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_08_06"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch08-testing-cairo-programs/listing_08_06.cairo b/listings/ch08-testing-cairo-programs/listing_08_06/src/lib.cairo
similarity index 75%
rename from listings/ch08-testing-cairo-programs/listing_08_06.cairo
rename to listings/ch08-testing-cairo-programs/listing_08_06/src/lib.cairo
index 850025a12..5e41961e4 100644
--- a/listings/ch08-testing-cairo-programs/listing_08_06.cairo
+++ b/listings/ch08-testing-cairo-programs/listing_08_06/src/lib.cairo
@@ -17,7 +17,7 @@ impl RectangleImpl of RectangleTrait {
}
fn can_hold(self: @Rectangle, other: @Rectangle) -> bool {
- *self.width > *other.width & *self.height > *other.height
+ *self.width > *other.width && *self.height > *other.height
}
}
// ANCHOR_END: trait_impl
@@ -32,8 +32,8 @@ mod tests {
// ANCHOR: test1
#[test]
fn larger_can_hold_smaller() {
- let larger = Rectangle { height: 7, width: 8, };
- let smaller = Rectangle { height: 1, width: 5, };
+ let larger = Rectangle { height: 7, width: 8, };
+ let smaller = Rectangle { height: 1, width: 5, };
assert(larger.can_hold(@smaller), 'rectangle cannot hold');
}
@@ -42,8 +42,8 @@ mod tests {
// ANCHOR: test2
#[test]
fn smaller_cannot_hold_larger() {
- let larger = Rectangle { height: 7, width: 8, };
- let smaller = Rectangle { height: 1, width: 5, };
+ let larger = Rectangle { height: 7, width: 8, };
+ let smaller = Rectangle { height: 1, width: 5, };
assert(!smaller.can_hold(@larger), 'rectangle cannot hold');
}
diff --git a/listings/ch08-testing-cairo-programs/listing_08_08/.gitignore b/listings/ch08-testing-cairo-programs/listing_08_08/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/listing_08_08/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch08-testing-cairo-programs/listing_08_08/Scarb.toml b/listings/ch08-testing-cairo-programs/listing_08_08/Scarb.toml
new file mode 100644
index 000000000..75ece180d
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/listing_08_08/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_08_08"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch08-testing-cairo-programs/listing_08_08.cairo b/listings/ch08-testing-cairo-programs/listing_08_08/src/lib.cairo
similarity index 86%
rename from listings/ch08-testing-cairo-programs/listing_08_08.cairo
rename to listings/ch08-testing-cairo-programs/listing_08_08/src/lib.cairo
index f59ec8016..5c96fe9d8 100644
--- a/listings/ch08-testing-cairo-programs/listing_08_08.cairo
+++ b/listings/ch08-testing-cairo-programs/listing_08_08/src/lib.cairo
@@ -1,8 +1,6 @@
-use array::ArrayTrait;
-
#[derive(Copy, Drop)]
struct Guess {
- value: u64,
+ value: u64,
}
trait GuessTrait {
@@ -11,7 +9,7 @@ trait GuessTrait {
impl GuessImpl of GuessTrait {
fn new(value: u64) -> Guess {
- if value < 1 | value > 100 {
+ if value < 1 || value > 100 {
let mut data = ArrayTrait::new();
data.append('Guess must be >= 1 and <= 100');
panic(data);
diff --git a/listings/ch08-testing-cairo-programs/listing_08_09/.gitignore b/listings/ch08-testing-cairo-programs/listing_08_09/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/listing_08_09/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch08-testing-cairo-programs/listing_08_09/Scarb.toml b/listings/ch08-testing-cairo-programs/listing_08_09/Scarb.toml
new file mode 100644
index 000000000..e7d8a6da2
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/listing_08_09/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_08_09"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch08-testing-cairo-programs/listing_08_09.cairo b/listings/ch08-testing-cairo-programs/listing_08_09/src/lib.cairo
similarity index 53%
rename from listings/ch08-testing-cairo-programs/listing_08_09.cairo
rename to listings/ch08-testing-cairo-programs/listing_08_09/src/lib.cairo
index aecc2298a..f60dd8162 100644
--- a/listings/ch08-testing-cairo-programs/listing_08_09.cairo
+++ b/listings/ch08-testing-cairo-programs/listing_08_09/src/lib.cairo
@@ -1,8 +1,6 @@
-use array::ArrayTrait;
-
#[derive(Copy, Drop)]
struct Guess {
- value: u64,
+ value: u64,
}
trait GuessTrait {
@@ -13,16 +11,12 @@ trait GuessTrait {
impl GuessImpl of GuessTrait {
fn new(value: u64) -> Guess {
if value < 1 {
- let mut data = ArrayTrait::new();
- data.append('Guess must be <= 100');
- panic(data);
+ panic_with_felt252('Guess must be >= 1');
} else if value > 100 {
- let mut data = ArrayTrait::new();
- data.append('Guess must be >= 1');
- panic(data);
+ panic_with_felt252('Guess must be <= 100');
}
- Guess { value, }
+ Guess { value, }
}
}
@@ -33,11 +27,11 @@ mod tests {
//ANCHOR: test_panic
#[test]
- #[should_panic(expected: ('Guess must be <= 100', ))]
+ #[should_panic(expected: ('Guess must be <= 100',))]
fn greater_than_100() {
GuessTrait::new(200);
}
- //ANCHOR_END: test_panic
+//ANCHOR_END: test_panic
}
// ANCHOR_END:here
diff --git a/listings/ch08-testing-cairo-programs/listing_08_10/.gitignore b/listings/ch08-testing-cairo-programs/listing_08_10/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/listing_08_10/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch08-testing-cairo-programs/listing_08_10/Scarb.toml b/listings/ch08-testing-cairo-programs/listing_08_10/Scarb.toml
new file mode 100644
index 000000000..e3d394f1c
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/listing_08_10/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_08_10"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch08-testing-cairo-programs/listing_08_10.cairo b/listings/ch08-testing-cairo-programs/listing_08_10/src/lib.cairo
similarity index 100%
rename from listings/ch08-testing-cairo-programs/listing_08_10.cairo
rename to listings/ch08-testing-cairo-programs/listing_08_10/src/lib.cairo
diff --git a/listings/ch08-testing-cairo-programs/no_listing_01_meaningful_name/.gitignore b/listings/ch08-testing-cairo-programs/no_listing_01_meaningful_name/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/no_listing_01_meaningful_name/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch08-testing-cairo-programs/no_listing_01_meaningful_name/Scarb.toml b/listings/ch08-testing-cairo-programs/no_listing_01_meaningful_name/Scarb.toml
new file mode 100644
index 000000000..62a84a54c
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/no_listing_01_meaningful_name/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_01_meaningful_name"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch08-testing-cairo-programs/no_listing_01_meaningful_name.cairo b/listings/ch08-testing-cairo-programs/no_listing_01_meaningful_name/src/lib.cairo
similarity index 100%
rename from listings/ch08-testing-cairo-programs/no_listing_01_meaningful_name.cairo
rename to listings/ch08-testing-cairo-programs/no_listing_01_meaningful_name/src/lib.cairo
diff --git a/listings/ch08-testing-cairo-programs/no_listing_02_wrong_can_hold_impl/.gitignore b/listings/ch08-testing-cairo-programs/no_listing_02_wrong_can_hold_impl/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/no_listing_02_wrong_can_hold_impl/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch08-testing-cairo-programs/no_listing_02_wrong_can_hold_impl/Scarb.toml b/listings/ch08-testing-cairo-programs/no_listing_02_wrong_can_hold_impl/Scarb.toml
new file mode 100644
index 000000000..3f601dd4e
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/no_listing_02_wrong_can_hold_impl/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_02_wrong_can_hold_impl"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch08-testing-cairo-programs/no_listing_02_wrong_can_hold_impl.cairo b/listings/ch08-testing-cairo-programs/no_listing_02_wrong_can_hold_impl/src/lib.cairo
similarity index 75%
rename from listings/ch08-testing-cairo-programs/no_listing_02_wrong_can_hold_impl.cairo
rename to listings/ch08-testing-cairo-programs/no_listing_02_wrong_can_hold_impl/src/lib.cairo
index de9e7e031..a630039d9 100644
--- a/listings/ch08-testing-cairo-programs/no_listing_02_wrong_can_hold_impl.cairo
+++ b/listings/ch08-testing-cairo-programs/no_listing_02_wrong_can_hold_impl/src/lib.cairo
@@ -1,3 +1,4 @@
+//TAG: tests_fail
use debug::PrintTrait;
#[derive(Copy, Drop)]
struct Rectangle {
@@ -18,7 +19,7 @@ impl RectangleImpl of RectangleTrait {
}
fn can_hold(self: @Rectangle, other: @Rectangle) -> bool {
- *self.width < *other.width & *self.height > *other.height
+ *self.width < *other.width && *self.height > *other.height
}
}
//ANCHOR_END: wrong_impl
@@ -34,8 +35,8 @@ mod tests {
// ANCHOR: test1
#[test]
fn larger_can_hold_smaller() {
- let larger = Rectangle { height: 7, width: 8, };
- let smaller = Rectangle { height: 1, width: 5, };
+ let larger = Rectangle { height: 7, width: 8, };
+ let smaller = Rectangle { height: 1, width: 5, };
assert(larger.can_hold(@smaller), 'rectangle cannot hold');
}
@@ -44,8 +45,8 @@ mod tests {
// ANCHOR: test2
#[test]
fn smaller_cannot_hold_larger() {
- let larger = Rectangle { height: 7, width: 8, };
- let smaller = Rectangle { height: 1, width: 5, };
+ let larger = Rectangle { height: 7, width: 8, };
+ let smaller = Rectangle { height: 1, width: 5, };
assert(!smaller.can_hold(@larger), 'rectangle cannot hold');
}
diff --git a/listings/ch08-testing-cairo-programs/no_listing_03_wrong_new_impl/.gitignore b/listings/ch08-testing-cairo-programs/no_listing_03_wrong_new_impl/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/no_listing_03_wrong_new_impl/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch08-testing-cairo-programs/no_listing_03_wrong_new_impl/Scarb.toml b/listings/ch08-testing-cairo-programs/no_listing_03_wrong_new_impl/Scarb.toml
new file mode 100644
index 000000000..3f0ff7d02
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/no_listing_03_wrong_new_impl/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_03_wrong_new_impl"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch08-testing-cairo-programs/no_listing_03_wrong_new_impl.cairo b/listings/ch08-testing-cairo-programs/no_listing_03_wrong_new_impl/src/lib.cairo
similarity index 84%
rename from listings/ch08-testing-cairo-programs/no_listing_03_wrong_new_impl.cairo
rename to listings/ch08-testing-cairo-programs/no_listing_03_wrong_new_impl/src/lib.cairo
index 00b6f47b8..dc22aa36e 100644
--- a/listings/ch08-testing-cairo-programs/no_listing_03_wrong_new_impl.cairo
+++ b/listings/ch08-testing-cairo-programs/no_listing_03_wrong_new_impl/src/lib.cairo
@@ -1,8 +1,6 @@
-use array::ArrayTrait;
-
#[derive(Copy, Drop)]
struct Guess {
- value: u64,
+ value: u64,
}
trait GuessTrait {
@@ -18,8 +16,9 @@ impl GuessImpl of GuessTrait {
panic(data);
}
- Guess { value, }
+ Guess { value, }
}
}
// ANCHOR_END: here
+
diff --git a/listings/ch08-testing-cairo-programs/no_listing_04_new_bug/.gitignore b/listings/ch08-testing-cairo-programs/no_listing_04_new_bug/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/no_listing_04_new_bug/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch08-testing-cairo-programs/no_listing_04_new_bug/Scarb.toml b/listings/ch08-testing-cairo-programs/no_listing_04_new_bug/Scarb.toml
new file mode 100644
index 000000000..020a2dce8
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/no_listing_04_new_bug/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_04_new_bug"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch08-testing-cairo-programs/no_listing_04_new_bug.cairo b/listings/ch08-testing-cairo-programs/no_listing_04_new_bug/src/lib.cairo
similarity index 84%
rename from listings/ch08-testing-cairo-programs/no_listing_04_new_bug.cairo
rename to listings/ch08-testing-cairo-programs/no_listing_04_new_bug/src/lib.cairo
index 36924659e..d617ef42a 100644
--- a/listings/ch08-testing-cairo-programs/no_listing_04_new_bug.cairo
+++ b/listings/ch08-testing-cairo-programs/no_listing_04_new_bug/src/lib.cairo
@@ -1,8 +1,6 @@
-use array::ArrayTrait;
-
#[derive(Copy, Drop)]
struct Guess {
- value: u64,
+ value: u64,
}
trait GuessTrait {
@@ -22,7 +20,7 @@ impl GuessImpl of GuessTrait {
panic(data);
}
- Guess { value, }
+ Guess { value, }
}
}
@@ -32,7 +30,7 @@ mod tests {
use super::GuessTrait;
#[test]
- #[should_panic(expected: ('Guess must be <= 100', ))]
+ #[should_panic(expected: ('Guess must be <= 100',))]
fn greater_than_100() {
GuessTrait::new(200);
}
diff --git a/listings/ch08-testing-cairo-programs/no_listing_05_ignore_tests/.gitignore b/listings/ch08-testing-cairo-programs/no_listing_05_ignore_tests/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/no_listing_05_ignore_tests/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch08-testing-cairo-programs/no_listing_05_ignore_tests/Scarb.toml b/listings/ch08-testing-cairo-programs/no_listing_05_ignore_tests/Scarb.toml
new file mode 100644
index 000000000..2f5b8b69c
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/no_listing_05_ignore_tests/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_05_ignore_tests"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch08-testing-cairo-programs/no_listing_05_ignore_tests.cairo b/listings/ch08-testing-cairo-programs/no_listing_05_ignore_tests/src/lib.cairo
similarity index 74%
rename from listings/ch08-testing-cairo-programs/no_listing_05_ignore_tests.cairo
rename to listings/ch08-testing-cairo-programs/no_listing_05_ignore_tests/src/lib.cairo
index cee0d8489..f85e42a38 100644
--- a/listings/ch08-testing-cairo-programs/no_listing_05_ignore_tests.cairo
+++ b/listings/ch08-testing-cairo-programs/no_listing_05_ignore_tests/src/lib.cairo
@@ -8,6 +8,6 @@ mod tests {
#[test]
#[ignore]
- fn expensive_test() {// code that takes an hour to run
+ fn expensive_test() { // code that takes an hour to run
}
}
diff --git a/listings/ch08-testing-cairo-programs/no_listing_06_cfg_attr/.gitignore b/listings/ch08-testing-cairo-programs/no_listing_06_cfg_attr/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/no_listing_06_cfg_attr/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch08-testing-cairo-programs/no_listing_06_cfg_attr/Scarb.toml b/listings/ch08-testing-cairo-programs/no_listing_06_cfg_attr/Scarb.toml
new file mode 100644
index 000000000..f9fa90486
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/no_listing_06_cfg_attr/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_06_cfg_attr"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch08-testing-cairo-programs/no_listing_06_cfg_attr.cairo b/listings/ch08-testing-cairo-programs/no_listing_06_cfg_attr/src/lib.cairo
similarity index 100%
rename from listings/ch08-testing-cairo-programs/no_listing_06_cfg_attr.cairo
rename to listings/ch08-testing-cairo-programs/no_listing_06_cfg_attr/src/lib.cairo
diff --git a/listings/ch08-testing-cairo-programs/no_listing_07_integration_test/.gitignore b/listings/ch08-testing-cairo-programs/no_listing_07_integration_test/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/no_listing_07_integration_test/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch08-testing-cairo-programs/no_listing_07_integration_test/Scarb.toml b/listings/ch08-testing-cairo-programs/no_listing_07_integration_test/Scarb.toml
new file mode 100644
index 000000000..0456ded16
--- /dev/null
+++ b/listings/ch08-testing-cairo-programs/no_listing_07_integration_test/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_07_integration_test"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch08-testing-cairo-programs/no_listing_07_integration_test.cairo b/listings/ch08-testing-cairo-programs/no_listing_07_integration_test/src/lib.cairo
similarity index 99%
rename from listings/ch08-testing-cairo-programs/no_listing_07_integration_test.cairo
rename to listings/ch08-testing-cairo-programs/no_listing_07_integration_test/src/lib.cairo
index 3d5f9cb89..73e23f5d6 100644
--- a/listings/ch08-testing-cairo-programs/no_listing_07_integration_test.cairo
+++ b/listings/ch08-testing-cairo-programs/no_listing_07_integration_test/src/lib.cairo
@@ -14,3 +14,4 @@ fn internal() {
}
// ANCHOR_END: here
+
diff --git a/listings/ch09-error-handling/listing_01/.gitignore b/listings/ch09-error-handling/listing_01/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch09-error-handling/listing_01/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch09-error-handling/listing_01/Scarb.toml b/listings/ch09-error-handling/listing_01/Scarb.toml
new file mode 100644
index 000000000..845405747
--- /dev/null
+++ b/listings/ch09-error-handling/listing_01/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_01"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch09-error-handling/listing_01.cairo b/listings/ch09-error-handling/listing_01/src/lib.cairo
similarity index 92%
rename from listings/ch09-error-handling/listing_01.cairo
rename to listings/ch09-error-handling/listing_01/src/lib.cairo
index ebda4ad67..90e77f36d 100644
--- a/listings/ch09-error-handling/listing_01.cairo
+++ b/listings/ch09-error-handling/listing_01/src/lib.cairo
@@ -1,5 +1,3 @@
-use traits::TryInto;
-
//ANCHOR: function
fn parse_u8(s: felt252) -> Result {
match s.try_into() {
@@ -13,7 +11,6 @@ fn parse_u8(s: felt252) -> Result {
#[cfg(test)]
mod tests {
use super::parse_u8;
- use result::ResultTrait;
#[test]
fn test_felt252_to_u8() {
let number: felt252 = 5_felt252;
diff --git a/listings/ch09-error-handling/listing_02/.gitignore b/listings/ch09-error-handling/listing_02/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch09-error-handling/listing_02/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch09-error-handling/listing_02/Scarb.toml b/listings/ch09-error-handling/listing_02/Scarb.toml
new file mode 100644
index 000000000..77e6b806d
--- /dev/null
+++ b/listings/ch09-error-handling/listing_02/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "listing_02"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch09-error-handling/listing_02.cairo b/listings/ch09-error-handling/listing_02/src/lib.cairo
similarity index 97%
rename from listings/ch09-error-handling/listing_02.cairo
rename to listings/ch09-error-handling/listing_02/src/lib.cairo
index 2e2ac78aa..9385380be 100644
--- a/listings/ch09-error-handling/listing_02.cairo
+++ b/listings/ch09-error-handling/listing_02/src/lib.cairo
@@ -1,5 +1,3 @@
-use traits::TryInto;
-
fn parse_u8(s: felt252) -> Result {
match s.try_into() {
Option::Some(value) => Result::Ok(value),
diff --git a/listings/ch09-error-handling/no_listing_01_panic/.gitignore b/listings/ch09-error-handling/no_listing_01_panic/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch09-error-handling/no_listing_01_panic/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch09-error-handling/no_listing_01_panic/Scarb.toml b/listings/ch09-error-handling/no_listing_01_panic/Scarb.toml
new file mode 100644
index 000000000..58a65840b
--- /dev/null
+++ b/listings/ch09-error-handling/no_listing_01_panic/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_01_panic"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch09-error-handling/no_listing_01_panic.cairo b/listings/ch09-error-handling/no_listing_01_panic/src/lib.cairo
similarity index 88%
rename from listings/ch09-error-handling/no_listing_01_panic.cairo
rename to listings/ch09-error-handling/no_listing_01_panic/src/lib.cairo
index 6ece0826d..4ff8319ba 100644
--- a/listings/ch09-error-handling/no_listing_01_panic.cairo
+++ b/listings/ch09-error-handling/no_listing_01_panic/src/lib.cairo
@@ -1,4 +1,3 @@
-use array::ArrayTrait;
use debug::PrintTrait;
fn main() {
diff --git a/listings/ch09-error-handling/no_listing_02_with_felt252/.gitignore b/listings/ch09-error-handling/no_listing_02_with_felt252/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch09-error-handling/no_listing_02_with_felt252/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch09-error-handling/no_listing_02_with_felt252/Scarb.toml b/listings/ch09-error-handling/no_listing_02_with_felt252/Scarb.toml
new file mode 100644
index 000000000..2c76d86b2
--- /dev/null
+++ b/listings/ch09-error-handling/no_listing_02_with_felt252/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_02_with_felt252"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch09-error-handling/no_listing_02_with_felt252.cairo b/listings/ch09-error-handling/no_listing_02_with_felt252/src/lib.cairo
similarity index 95%
rename from listings/ch09-error-handling/no_listing_02_with_felt252.cairo
rename to listings/ch09-error-handling/no_listing_02_with_felt252/src/lib.cairo
index d5fdd9ce7..51c55b44f 100644
--- a/listings/ch09-error-handling/no_listing_02_with_felt252.cairo
+++ b/listings/ch09-error-handling/no_listing_02_with_felt252/src/lib.cairo
@@ -1,3 +1,3 @@
fn main() {
panic_with_felt252(2);
-}
\ No newline at end of file
+}
diff --git a/listings/ch09-error-handling/no_listing_03_nopanic/.gitignore b/listings/ch09-error-handling/no_listing_03_nopanic/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch09-error-handling/no_listing_03_nopanic/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch09-error-handling/no_listing_03_nopanic/Scarb.toml b/listings/ch09-error-handling/no_listing_03_nopanic/Scarb.toml
new file mode 100644
index 000000000..33d19f7ba
--- /dev/null
+++ b/listings/ch09-error-handling/no_listing_03_nopanic/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_03_nopanic"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch09-error-handling/no_listing_03_nopanic.cairo b/listings/ch09-error-handling/no_listing_03_nopanic/src/lib.cairo
similarity index 100%
rename from listings/ch09-error-handling/no_listing_03_nopanic.cairo
rename to listings/ch09-error-handling/no_listing_03_nopanic/src/lib.cairo
diff --git a/listings/ch09-error-handling/no_listing_04_nopanic_wrong/.gitignore b/listings/ch09-error-handling/no_listing_04_nopanic_wrong/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch09-error-handling/no_listing_04_nopanic_wrong/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch09-error-handling/no_listing_04_nopanic_wrong/Scarb.toml b/listings/ch09-error-handling/no_listing_04_nopanic_wrong/Scarb.toml
new file mode 100644
index 000000000..1f60b7433
--- /dev/null
+++ b/listings/ch09-error-handling/no_listing_04_nopanic_wrong/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_04_nopanic_wrong"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch09-error-handling/no_listing_04_nopanic_wrong.cairo b/listings/ch09-error-handling/no_listing_04_nopanic_wrong/src/lib.cairo
similarity index 73%
rename from listings/ch09-error-handling/no_listing_04_nopanic_wrong.cairo
rename to listings/ch09-error-handling/no_listing_04_nopanic_wrong/src/lib.cairo
index 9622d17ae..de0beb214 100644
--- a/listings/ch09-error-handling/no_listing_04_nopanic_wrong.cairo
+++ b/listings/ch09-error-handling/no_listing_04_nopanic_wrong/src/lib.cairo
@@ -1,4 +1,4 @@
-// does_not_compile
+//TAG: does_not_compile
fn function_never_panic() nopanic {
assert(1 == 1, 'what');
}
diff --git a/listings/ch09-error-handling/no_listing_05_panic_with/.gitignore b/listings/ch09-error-handling/no_listing_05_panic_with/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch09-error-handling/no_listing_05_panic_with/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch09-error-handling/no_listing_05_panic_with/Scarb.toml b/listings/ch09-error-handling/no_listing_05_panic_with/Scarb.toml
new file mode 100644
index 000000000..3b8347b6b
--- /dev/null
+++ b/listings/ch09-error-handling/no_listing_05_panic_with/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_05_panic_with"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch09-error-handling/no_listing_05_panic_with.cairo b/listings/ch09-error-handling/no_listing_05_panic_with/src/lib.cairo
similarity index 84%
rename from listings/ch09-error-handling/no_listing_05_panic_with.cairo
rename to listings/ch09-error-handling/no_listing_05_panic_with/src/lib.cairo
index 53db00b1a..d83225073 100644
--- a/listings/ch09-error-handling/no_listing_05_panic_with.cairo
+++ b/listings/ch09-error-handling/no_listing_05_panic_with/src/lib.cairo
@@ -1,9 +1,7 @@
-use option::OptionTrait;
-
#[panic_with('value is 0', wrap_not_zero)]
fn wrap_if_not_zero(value: u128) -> Option {
if value == 0 {
- Option::None(())
+ Option::None
} else {
Option::Some(value)
}
diff --git a/listings/ch09-error-handling/no_listing_06_assert/.gitignore b/listings/ch09-error-handling/no_listing_06_assert/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch09-error-handling/no_listing_06_assert/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch09-error-handling/no_listing_06_assert/Scarb.toml b/listings/ch09-error-handling/no_listing_06_assert/Scarb.toml
new file mode 100644
index 000000000..3cd373a59
--- /dev/null
+++ b/listings/ch09-error-handling/no_listing_06_assert/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_06_assert"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch09-error-handling/no_listing_06_assert.cairo b/listings/ch09-error-handling/no_listing_06_assert/src/lib.cairo
similarity index 100%
rename from listings/ch09-error-handling/no_listing_06_assert.cairo
rename to listings/ch09-error-handling/no_listing_06_assert/src/lib.cairo
diff --git a/listings/ch09-error-handling/no_listing_07_result_enum/.gitignore b/listings/ch09-error-handling/no_listing_07_result_enum/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch09-error-handling/no_listing_07_result_enum/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch09-error-handling/no_listing_07_result_enum/Scarb.toml b/listings/ch09-error-handling/no_listing_07_result_enum/Scarb.toml
new file mode 100644
index 000000000..70808e679
--- /dev/null
+++ b/listings/ch09-error-handling/no_listing_07_result_enum/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_07_result_enum"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch09-error-handling/no_listing_07_result_enum.cairo b/listings/ch09-error-handling/no_listing_07_result_enum/src/lib.cairo
similarity index 100%
rename from listings/ch09-error-handling/no_listing_07_result_enum.cairo
rename to listings/ch09-error-handling/no_listing_07_result_enum/src/lib.cairo
diff --git a/listings/ch09-error-handling/no_listing_08_result_trait/.gitignore b/listings/ch09-error-handling/no_listing_08_result_trait/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch09-error-handling/no_listing_08_result_trait/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch09-error-handling/no_listing_08_result_trait/Scarb.toml b/listings/ch09-error-handling/no_listing_08_result_trait/Scarb.toml
new file mode 100644
index 000000000..930164fb4
--- /dev/null
+++ b/listings/ch09-error-handling/no_listing_08_result_trait/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_08_result_trait"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch09-error-handling/no_listing_08_result_trait.cairo b/listings/ch09-error-handling/no_listing_08_result_trait/src/lib.cairo
similarity index 100%
rename from listings/ch09-error-handling/no_listing_08_result_trait.cairo
rename to listings/ch09-error-handling/no_listing_08_result_trait/src/lib.cairo
diff --git a/listings/ch10-advanced-features/no_listing_01_potions/.gitignore b/listings/ch10-advanced-features/no_listing_01_potions/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch10-advanced-features/no_listing_01_potions/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch10-advanced-features/no_listing_01_potions/Scarb.toml b/listings/ch10-advanced-features/no_listing_01_potions/Scarb.toml
new file mode 100644
index 000000000..86ad65031
--- /dev/null
+++ b/listings/ch10-advanced-features/no_listing_01_potions/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_01_potions"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
\ No newline at end of file
diff --git a/listings/ch10-advanced-features/no_listing_01_potions.cairo b/listings/ch10-advanced-features/no_listing_01_potions/src/lib.cairo
similarity index 97%
rename from listings/ch10-advanced-features/no_listing_01_potions.cairo
rename to listings/ch10-advanced-features/no_listing_01_potions/src/lib.cairo
index 255b04015..bf0de8bdd 100644
--- a/listings/ch10-advanced-features/no_listing_01_potions.cairo
+++ b/listings/ch10-advanced-features/no_listing_01_potions/src/lib.cairo
@@ -5,7 +5,7 @@ struct Potion {
impl PotionAdd of Add {
fn add(lhs: Potion, rhs: Potion) -> Potion {
- Potion { health: lhs.health + rhs.health, mana: lhs.mana + rhs.mana, }
+ Potion { health: lhs.health + rhs.health, mana: lhs.mana + rhs.mana, }
}
}
diff --git a/listings/ch10-advanced-features/no_listing_02_array_macro/.gitignore b/listings/ch10-advanced-features/no_listing_02_array_macro/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch10-advanced-features/no_listing_02_array_macro/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch10-advanced-features/no_listing_02_array_macro/Scarb.toml b/listings/ch10-advanced-features/no_listing_02_array_macro/Scarb.toml
new file mode 100644
index 000000000..15ef8bab6
--- /dev/null
+++ b/listings/ch10-advanced-features/no_listing_02_array_macro/Scarb.toml
@@ -0,0 +1,8 @@
+[package]
+name = "no_listing_02_array_macro"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
diff --git a/listings/ch10-advanced-features/no_listing_02_array_macro/src/lib.cairo b/listings/ch10-advanced-features/no_listing_02_array_macro/src/lib.cairo
new file mode 100644
index 000000000..9ed342558
--- /dev/null
+++ b/listings/ch10-advanced-features/no_listing_02_array_macro/src/lib.cairo
@@ -0,0 +1,10 @@
+fn main() {
+ let mut arr = ArrayTrait::new();
+ arr.append(1);
+ arr.append(2);
+ arr.append(3);
+ arr.append(4);
+ arr.append(5);
+
+ let arr = array![1, 2, 3, 4, 5];
+}
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_01/.gitignore b/listings/ch99-starknet-smart-contracts/listing_99_01/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_01/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_01/Scarb.toml b/listings/ch99-starknet-smart-contracts/listing_99_01/Scarb.toml
new file mode 100644
index 000000000..98e6405a2
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_01/Scarb.toml
@@ -0,0 +1,9 @@
+[package]
+name = "listing_99_01"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
+starknet = ">=2.2.0"
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_01/src/lib.cairo b/listings/ch99-starknet-smart-contracts/listing_99_01/src/lib.cairo
new file mode 100644
index 000000000..9f22016b4
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_01/src/lib.cairo
@@ -0,0 +1,36 @@
+// ANCHOR:all
+// ANCHOR: interface
+#[starknet::interface]
+trait ISimpleStorage {
+ fn set(ref self: TContractState, x: u128);
+ fn get(self: @TContractState) -> u128;
+}
+//ANCHOR_END: interface
+
+#[starknet::contract]
+mod SimpleStorage {
+ use starknet::get_caller_address;
+ use starknet::ContractAddress;
+
+ #[storage]
+ struct Storage {
+ stored_data: u128
+ }
+
+ //ANCHOR: impl
+ #[external(v0)]
+ impl SimpleStorage of super::ISimpleStorage {
+ //ANCHOR: write_state
+ fn set(ref self: ContractState, x: u128) {
+ self.stored_data.write(x);
+ }
+ //ANCHOR_END: write_state
+ fn get(self: @ContractState) -> u128 {
+ self.stored_data.read()
+ }
+ }
+//ANCHOR_END: impl
+}
+//ANCHOR_END: all
+
+
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_01_bis_wrong_impl/.gitignore b/listings/ch99-starknet-smart-contracts/listing_99_01_bis_wrong_impl/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_01_bis_wrong_impl/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_01_bis_wrong_impl/Scarb.toml b/listings/ch99-starknet-smart-contracts/listing_99_01_bis_wrong_impl/Scarb.toml
new file mode 100644
index 000000000..423ca857a
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_01_bis_wrong_impl/Scarb.toml
@@ -0,0 +1,9 @@
+[package]
+name = "listing_99_01_bis_wrong_impl"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
+starknet = ">=2.2.0"
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_01_bis_wrong_impl/src/lib.cairo b/listings/ch99-starknet-smart-contracts/listing_99_01_bis_wrong_impl/src/lib.cairo
new file mode 100644
index 000000000..96caf79cf
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_01_bis_wrong_impl/src/lib.cairo
@@ -0,0 +1,33 @@
+//TAG: does_not_compile
+// ANCHOR:all
+// ANCHOR: interface
+#[starknet::interface]
+trait ISimpleStorage {
+ fn set(ref self: TContractState, x: u128);
+ fn get(self: @TContractState) -> u128;
+}
+//ANCHOR_END: interface
+
+#[starknet::contract]
+mod SimpleStorage {
+ use starknet::get_caller_address;
+ use starknet::ContractAddress;
+
+ #[storage]
+ struct Storage {
+ stored_data: u128
+ }
+
+ //ANCHOR: impl
+ #[external(v0)]
+ impl SimpleStorage of super::ISimpleStorage {
+ fn set(ref self: ContractState) {}
+ fn get(self: @ContractState) -> u128 {
+ self.stored_data.read()
+ }
+ }
+//ANCHOR_END: impl
+}
+//ANCHOR_END: all
+
+
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_02/.gitignore b/listings/ch99-starknet-smart-contracts/listing_99_02/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_02/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_02/Scarb.toml b/listings/ch99-starknet-smart-contracts/listing_99_02/Scarb.toml
new file mode 100644
index 000000000..530447678
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_02/Scarb.toml
@@ -0,0 +1,9 @@
+[package]
+name = "listing_99_02"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
+starknet = ">=2.2.0"
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_02.cairo b/listings/ch99-starknet-smart-contracts/listing_99_02/src/lib.cairo
similarity index 52%
rename from listings/ch99-starknet-smart-contracts/listing_99_02.cairo
rename to listings/ch99-starknet-smart-contracts/listing_99_02/src/lib.cairo
index e5958935c..1f2c1d426 100644
--- a/listings/ch99-starknet-smart-contracts/listing_99_02.cairo
+++ b/listings/ch99-starknet-smart-contracts/listing_99_02/src/lib.cairo
@@ -1,9 +1,11 @@
-#[contract]
-mod Contract {
+#[starknet::contract]
+mod contract {
+ use starknet::ContractAddress;
//ANCHOR: here
+ #[storage]
struct Storage {
id: u8,
names: LegacyMap::,
}
- //ANCHOR_END: here
+//ANCHOR_END: here
}
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_03_example_contract.cairo b/listings/ch99-starknet-smart-contracts/listing_99_03_example_contract.cairo
deleted file mode 100644
index 9f4949b6d..000000000
--- a/listings/ch99-starknet-smart-contracts/listing_99_03_example_contract.cairo
+++ /dev/null
@@ -1,48 +0,0 @@
-//ANCHOR: all
-#[contract]
-mod Example {
- use starknet::get_caller_address;
- use starknet::ContractAddress;
-
- struct Storage {
- names: LegacyMap::,
- }
-
- //ANCHOR: event
- #[event]
- fn StoredName(caller: ContractAddress, name: felt252) {}
- //ANCHOR_END: event
-
- //ANCHOR: constructor
- #[constructor]
- fn constructor(_name: felt252, _address: ContractAddress) {
- names::write(_address, _name);
- }
- //ANCHOR_END: constructor
-
- //ANCHOR: external
- #[external]
- fn store_name(_name: felt252) {
- let caller = get_caller_address();
- //ANCHOR: write
- names::write(caller, _name);
- //ANCHOR_END: write
- //ANCHOR: emit_event
- StoredName(caller, _name);
- //ANCHOR_END: emit_event
- }
- //ANCHOR_END: external
-
- //ANCHOR: view
- #[view]
- fn get_name(_address: ContractAddress) -> felt252 {
- //ANCHOR: read
- let name = names::read(_address);
- //ANCHOR_END: read
- return name;
- }
-//ANCHOR_END: view
-}
-//ANCHOR_END: all
-
-
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_03_example_contract/.gitignore b/listings/ch99-starknet-smart-contracts/listing_99_03_example_contract/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_03_example_contract/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_03_example_contract/Scarb.toml b/listings/ch99-starknet-smart-contracts/listing_99_03_example_contract/Scarb.toml
new file mode 100644
index 000000000..c6a4d6a75
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_03_example_contract/Scarb.toml
@@ -0,0 +1,9 @@
+[package]
+name = "listing_99_03_example_contract"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
+starknet = ">=2.2.0"
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_03_example_contract/src/lib.cairo b/listings/ch99-starknet-smart-contracts/listing_99_03_example_contract/src/lib.cairo
new file mode 100644
index 000000000..179c51156
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_03_example_contract/src/lib.cairo
@@ -0,0 +1,101 @@
+//ANCHOR: all
+
+use starknet::ContractAddress;
+
+#[starknet::interface]
+trait INameRegistry {
+ fn store_name(ref self: TContractState, name: felt252);
+ fn get_name(self: @TContractState, address: ContractAddress) -> felt252;
+}
+
+
+#[starknet::contract]
+mod NameRegistry {
+ use starknet::{ContractAddress, get_caller_address};
+
+ #[storage]
+ struct Storage {
+ names: LegacyMap::,
+ total_names: u128,
+ owner: Person
+ }
+
+ //ANCHOR: event
+ #[event]
+ #[derive(Drop, starknet::Event)]
+ enum Event {
+ StoredName: StoredName,
+ }
+
+ #[derive(Drop, starknet::Event)]
+ struct StoredName {
+ #[key]
+ user: ContractAddress,
+ name: felt252
+ }
+ //ANCHOR_END: event
+
+ //ANCHOR: person
+ #[derive(Copy, Drop, Serde, starknet::Store)]
+ struct Person {
+ name: felt252,
+ address: ContractAddress
+ }
+ //ANCHOR_END: person
+
+ //ANCHOR: constructor
+ #[constructor]
+ fn constructor(ref self: ContractState, owner: Person) {
+ self.names.write(owner.address, owner.name);
+ self.total_names.write(1);
+ self.owner.write(owner);
+ }
+ //ANCHOR_END: constructor
+
+ //ANCHOR: impl_public
+ #[external(v0)]
+ impl NameRegistry of super::INameRegistry {
+ //ANCHOR: external
+ fn store_name(ref self: ContractState, name: felt252) {
+ let caller = get_caller_address();
+ self._store_name(caller, name);
+ }
+ //ANCHOR_END: external
+
+ //ANCHOR: view
+ fn get_name(self: @ContractState, address: ContractAddress) -> felt252 {
+ //ANCHOR: read
+ let name = self.names.read(address);
+ //ANCHOR_END: read
+ name
+ }
+ //ANCHOR_END: view
+ }
+ //ANCHOR_END: impl_public
+
+ // ANCHOR: state_internal
+ #[generate_trait]
+ impl InternalFunctions of InternalFunctionsTrait {
+ fn _store_name(ref self: ContractState, user: ContractAddress, name: felt252) {
+ let mut total_names = self.total_names.read();
+ //ANCHOR: write
+ self.names.write(user, name);
+ //ANCHOR_END: write
+ self.total_names.write(total_names + 1);
+ //ANCHOR: emit_event
+ self.emit(StoredName { user: user, name: name });
+ //ANCHOR_END: emit_event
+
+ }
+ }
+ // ANCHOR_END: state_internal
+
+ // ANCHOR: stateless_internal
+ fn _get_contract_name() -> felt252 {
+ 'Name Registry'
+ }
+// ANCHOR_END: stateless_internal
+}
+//ANCHOR_END: all
+
+
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_04_L1_L2_messaging/.gitignore b/listings/ch99-starknet-smart-contracts/listing_99_04_L1_L2_messaging/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_04_L1_L2_messaging/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_04_L1_L2_messaging/Scarb.toml b/listings/ch99-starknet-smart-contracts/listing_99_04_L1_L2_messaging/Scarb.toml
new file mode 100644
index 000000000..ff1df9623
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_04_L1_L2_messaging/Scarb.toml
@@ -0,0 +1,9 @@
+[package]
+name = "listing_99_04_L1_L2_messaging"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
+starknet = ">=2.2.0"
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_04_L1_L2_messaging/src/lib.cairo b/listings/ch99-starknet-smart-contracts/listing_99_04_L1_L2_messaging/src/lib.cairo
new file mode 100644
index 000000000..ba9bf746b
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_04_L1_L2_messaging/src/lib.cairo
@@ -0,0 +1,81 @@
+#[starknet::contract]
+mod Evaluator {
+ use starknet::get_caller_address;
+ use starknet::get_contract_address;
+ use starknet::ContractAddress;
+ use starknet::syscalls::send_message_to_l1_syscall;
+
+
+ use zeroable::Zeroable;
+
+
+ use integer::u256;
+ use integer::u256_from_felt252;
+
+ #[storage]
+ struct Storage {
+ l1_evaluator_address: felt252,
+ messages: LegacyMap,
+ messages_count: usize
+ }
+
+ #[constructor]
+ fn constructor(ref self: ContractState) {}
+
+ #[event]
+ #[derive(Drop, starknet::Event)]
+ enum Event {
+ ReceivedSomething: ReceivedSomething,
+ }
+
+ #[derive(Drop, starknet::Event)]
+ struct ReceivedSomething {
+ #[key]
+ from: usize,
+ name: usize
+ }
+
+
+ //ANCHOR:here
+ #[l1_handler]
+ fn ex_01_receive_message_from_l1(
+ ref self: ContractState, from_address: felt252, message: usize
+ ) {
+ // Selector: 0x274ab8abc4e270a94c36e1a54c794cd4dd537eeee371e7188c56ee768c4c0c4
+ // Check that the sender is the correct L1 evaluator
+ assert(from_address == self.l1_evaluator_address.read(), 'WRONG L1 EVALUATOR');
+ // Adding a check on the message, because why not?
+ assert(message > 168111, 'MESSAGE TOO SMALL');
+ assert(message < 5627895, 'MESSAGE TOO BIG');
+
+ // Store the message received from L1
+ let mut message_count = self.messages_count.read();
+ self.messages.write(message_count, message);
+ message_count += 1;
+ self.messages_count.write(message_count);
+ }
+ //ANCHOR_END: here
+ //ANCHOR: l2l1
+
+ #[external(v0)]
+ #[generate_trait]
+ impl Evaluator of IEvaluator {
+ fn ex_02_send_message_to_l1(ref self: ContractState, value: usize) {
+ // Create the message payload
+ // By default it's an array of felt252
+ let mut message_payload = ArrayTrait::new();
+ // Adding the address of the caller on L2
+ message_payload.append(get_caller_address().into());
+ // Adding the value
+ message_payload.append(value.into());
+ // Sending the message
+ send_message_to_l1_syscall(self.l1_evaluator_address.read(), message_payload.span());
+ }
+
+ fn get_l1_evaluator_address(self: @ContractState) -> felt252 {
+ self.l1_evaluator_address.read()
+ }
+ }
+//ANCHOR_END: l2l1
+
+}
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_04_interface.cairo b/listings/ch99-starknet-smart-contracts/listing_99_04_interface.cairo
deleted file mode 100644
index 25a0eb7e9..000000000
--- a/listings/ch99-starknet-smart-contracts/listing_99_04_interface.cairo
+++ /dev/null
@@ -1,31 +0,0 @@
-use starknet::ContractAddress;
-
-#[abi]
-trait IERC20 {
- #[view]
- fn name() -> felt252;
-
- #[view]
- fn symbol() -> felt252;
-
- #[view]
- fn decimals() -> u8;
-
- #[view]
- fn total_supply() -> u256;
-
- #[view]
- fn balance_of(account: ContractAddress) -> u256;
-
- #[view]
- fn allowance(owner: ContractAddress, spender: ContractAddress) -> u256;
-
- #[external]
- fn transfer(recipient: ContractAddress, amount: u256) -> bool;
-
- #[external]
- fn transfer_from(sender: ContractAddress, recipient: ContractAddress, amount: u256) -> bool;
-
- #[external]
- fn approve(spender: ContractAddress, amount: u256) -> bool;
-}
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_04_interface/.gitignore b/listings/ch99-starknet-smart-contracts/listing_99_04_interface/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_04_interface/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_04_interface/Scarb.toml b/listings/ch99-starknet-smart-contracts/listing_99_04_interface/Scarb.toml
new file mode 100644
index 000000000..255afe574
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_04_interface/Scarb.toml
@@ -0,0 +1,9 @@
+[package]
+name = "listing_99_04_interface"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
+starknet = ">=2.2.0"
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_04_interface/src/lib.cairo b/listings/ch99-starknet-smart-contracts/listing_99_04_interface/src/lib.cairo
new file mode 100644
index 000000000..bcae4c36e
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_04_interface/src/lib.cairo
@@ -0,0 +1,24 @@
+use starknet::ContractAddress;
+
+#[starknet::interface]
+trait IERC20 {
+ fn name(self: @TContractState) -> felt252;
+
+ fn symbol(self: @TContractState) -> felt252;
+
+ fn decimals(self: @TContractState) -> u8;
+
+ fn total_supply(self: @TContractState) -> u256;
+
+ fn balance_of(self: @TContractState, account: ContractAddress) -> u256;
+
+ fn allowance(self: @TContractState, owner: ContractAddress, spender: ContractAddress) -> u256;
+
+ fn transfer(ref self: TContractState, recipient: ContractAddress, amount: u256) -> bool;
+
+ fn transfer_from(
+ ref self: TContractState, sender: ContractAddress, recipient: ContractAddress, amount: u256
+ ) -> bool;
+
+ fn approve(ref self: TContractState, spender: ContractAddress, amount: u256) -> bool;
+}
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_05_dispatcher_trait/.gitignore b/listings/ch99-starknet-smart-contracts/listing_99_05_dispatcher_trait/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_05_dispatcher_trait/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_05_dispatcher_trait/Scarb.toml b/listings/ch99-starknet-smart-contracts/listing_99_05_dispatcher_trait/Scarb.toml
new file mode 100644
index 000000000..727258076
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_05_dispatcher_trait/Scarb.toml
@@ -0,0 +1,9 @@
+[package]
+name = "listing_99_05_dispatcher_trait"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
+starknet = ">=2.2.0"
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_05_dispatcher_trait.cairo b/listings/ch99-starknet-smart-contracts/listing_99_05_dispatcher_trait/src/lib.cairo
similarity index 81%
rename from listings/ch99-starknet-smart-contracts/listing_99_05_dispatcher_trait.cairo
rename to listings/ch99-starknet-smart-contracts/listing_99_05_dispatcher_trait/src/lib.cairo
index 497aae08f..de31d0d26 100644
--- a/listings/ch99-starknet-smart-contracts/listing_99_05_dispatcher_trait.cairo
+++ b/listings/ch99-starknet-smart-contracts/listing_99_05_dispatcher_trait/src/lib.cairo
@@ -1,4 +1,4 @@
-//does_not_compile
+//TAG: does_not_compile
use starknet::{ContractAddress};
trait IERC20DispatcherTrait {
@@ -6,9 +6,9 @@ trait IERC20DispatcherTrait {
fn transfer(self: T, recipient: ContractAddress, amount: u256);
}
-#[derive(Copy, Drop, storage_access::StorageAccess, Serde)]
+#[derive(Copy, Drop, starknet::Store, Serde)]
struct IERC20Dispatcher {
- contract_address: starknet::ContractAddress,
+ contract_address: starknet::ContractAddress,
}
impl IERC20DispatcherImpl of IERC20DispatcherTrait {
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_06_sample_contract.cairo b/listings/ch99-starknet-smart-contracts/listing_99_06_sample_contract.cairo
deleted file mode 100644
index 29758dc7d..000000000
--- a/listings/ch99-starknet-smart-contracts/listing_99_06_sample_contract.cairo
+++ /dev/null
@@ -1,54 +0,0 @@
-use starknet::ContractAddress;
-
-#[abi]
-trait IERC20 {
- #[view]
- fn name() -> felt252;
-
- #[view]
- fn symbol() -> felt252;
-
- #[view]
- fn decimals() -> u8;
-
- #[view]
- fn total_supply() -> u256;
-
- #[view]
- fn balance_of(account: ContractAddress) -> u256;
-
- #[view]
- fn allowance(owner: ContractAddress, spender: ContractAddress) -> u256;
-
- #[external]
- fn transfer(recipient: ContractAddress, amount: u256) -> bool;
-
- #[external]
- fn transfer_from(sender: ContractAddress, recipient: ContractAddress, amount: u256) -> bool;
-
- #[external]
- fn approve(spender: ContractAddress, amount: u256) -> bool;
-}
-
-//ANCHOR: here
-//**** Specify interface here ****//
-#[contract]
-mod Dispatcher {
- use super::IERC20DispatcherTrait;
- use super::IERC20Dispatcher;
- use starknet::ContractAddress;
-
- #[view]
- fn token_name(_contract_address: ContractAddress) -> felt252 {
- IERC20Dispatcher { contract_address: _contract_address }.name()
- }
-
- #[external]
- fn transfer_token(
- _contract_address: ContractAddress, recipient: ContractAddress, amount: u256
- ) -> bool {
- IERC20Dispatcher { contract_address: _contract_address }.transfer(recipient, amount)
- }
-}
-// ANCHOR_END: here
-
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_06_sample_contract/.gitignore b/listings/ch99-starknet-smart-contracts/listing_99_06_sample_contract/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_06_sample_contract/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_06_sample_contract/Scarb.toml b/listings/ch99-starknet-smart-contracts/listing_99_06_sample_contract/Scarb.toml
new file mode 100644
index 000000000..35cb2a4da
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_06_sample_contract/Scarb.toml
@@ -0,0 +1,9 @@
+[package]
+name = "listing_99_06_sample_contract"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
+starknet = ">=2.2.0"
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_06_sample_contract/src/lib.cairo b/listings/ch99-starknet-smart-contracts/listing_99_06_sample_contract/src/lib.cairo
new file mode 100644
index 000000000..15cba2172
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_06_sample_contract/src/lib.cairo
@@ -0,0 +1,68 @@
+use starknet::ContractAddress;
+
+#[starknet::interface]
+trait IERC20 {
+ fn name(self: @TContractState) -> felt252;
+
+ fn symbol(self: @TContractState) -> felt252;
+
+ fn decimals(self: @TContractState) -> u8;
+
+ fn total_supply(self: @TContractState) -> u256;
+
+ fn balance_of(self: @TContractState, account: ContractAddress) -> u256;
+
+ fn allowance(self: @TContractState, owner: ContractAddress, spender: ContractAddress) -> u256;
+
+ fn transfer(ref self: TContractState, recipient: ContractAddress, amount: u256) -> bool;
+
+ fn transfer_from(
+ ref self: TContractState, sender: ContractAddress, recipient: ContractAddress, amount: u256
+ ) -> bool;
+
+ fn approve(ref self: TContractState, spender: ContractAddress, amount: u256) -> bool;
+}
+
+#[starknet::interface]
+trait ITokenWrapper {
+ fn token_name(self: @TContractState, contract_address: ContractAddress) -> felt252;
+
+ fn transfer_token(
+ ref self: TContractState,
+ contract_address: ContractAddress,
+ recipient: ContractAddress,
+ amount: u256
+ ) -> bool;
+}
+
+
+//ANCHOR: here
+//**** Specify interface here ****//
+#[starknet::contract]
+mod TokenWrapper {
+ use super::IERC20DispatcherTrait;
+ use super::IERC20Dispatcher;
+ use super::ITokenWrapper;
+ use starknet::ContractAddress;
+
+ #[storage]
+ struct Storage {}
+
+ impl TokenWrapper of ITokenWrapper {
+ fn token_name(self: @ContractState, contract_address: ContractAddress) -> felt252 {
+ IERC20Dispatcher { contract_address }.name()
+ }
+
+ fn transfer_token(
+ ref self: ContractState,
+ contract_address: ContractAddress,
+ recipient: ContractAddress,
+ amount: u256
+ ) -> bool {
+ IERC20Dispatcher { contract_address }.transfer(recipient, amount)
+ }
+ }
+}
+// ANCHOR_END: here
+
+
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_07_library_dispatcher/.gitignore b/listings/ch99-starknet-smart-contracts/listing_99_07_library_dispatcher/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_07_library_dispatcher/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_07_library_dispatcher/Scarb.toml b/listings/ch99-starknet-smart-contracts/listing_99_07_library_dispatcher/Scarb.toml
new file mode 100644
index 000000000..3fde9e82f
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_07_library_dispatcher/Scarb.toml
@@ -0,0 +1,9 @@
+[package]
+name = "listing_99_07_library_dispatcher"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
+starknet = ">=2.2.0"
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_07_library_dispatcher.cairo b/listings/ch99-starknet-smart-contracts/listing_99_07_library_dispatcher/src/lib.cairo
similarity index 83%
rename from listings/ch99-starknet-smart-contracts/listing_99_07_library_dispatcher.cairo
rename to listings/ch99-starknet-smart-contracts/listing_99_07_library_dispatcher/src/lib.cairo
index 14a8495c3..eddc867f5 100644
--- a/listings/ch99-starknet-smart-contracts/listing_99_07_library_dispatcher.cairo
+++ b/listings/ch99-starknet-smart-contracts/listing_99_07_library_dispatcher/src/lib.cairo
@@ -1,4 +1,4 @@
-//does_not_compile
+//TAG: does_not_compile
use starknet::ContractAddress;
trait IERC20DispatcherTrait {
@@ -6,9 +6,9 @@ trait IERC20DispatcherTrait {
fn transfer(self: T, recipient: ContractAddress, amount: u256);
}
-#[derive(Copy, Drop, storage_access::StorageAccess, Serde)]
+#[derive(Copy, Drop, starknet::Store, Serde)]
struct IERC20LibraryDispatcher {
- class_hash: starknet::ClassHash,
+ class_hash: starknet::ClassHash,
}
impl IERC20LibraryDispatcherImpl of IERC20DispatcherTrait {
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_08_using_library_dispatcher.cairo b/listings/ch99-starknet-smart-contracts/listing_99_08_using_library_dispatcher.cairo
deleted file mode 100644
index fedffeb86..000000000
--- a/listings/ch99-starknet-smart-contracts/listing_99_08_using_library_dispatcher.cairo
+++ /dev/null
@@ -1,54 +0,0 @@
-//**** Specify interface here ****//
-use starknet::ContractAddress;
-
-#[abi]
-trait IERC20 {
- #[view]
- fn name() -> felt252;
-
- #[view]
- fn symbol() -> felt252;
-
- #[view]
- fn decimals() -> u8;
-
- #[view]
- fn total_supply() -> u256;
-
- #[view]
- fn balance_of(account: ContractAddress) -> u256;
-
- #[view]
- fn allowance(owner: ContractAddress, spender: ContractAddress) -> u256;
-
- #[external]
- fn transfer(recipient: ContractAddress, amount: u256) -> bool;
-
- #[external]
- fn transfer_from(sender: ContractAddress, recipient: ContractAddress, amount: u256) -> bool;
-
- #[external]
- fn approve(spender: ContractAddress, amount: u256) -> bool;
-}
-
-//ANCHOR: here
-#[contract]
-mod contract {
- use super::IERC20DispatcherTrait;
- use super::IERC20LibraryDispatcher;
- use starknet::ContractAddress;
-
- #[view]
- fn token_name() -> felt252 {
- IERC20LibraryDispatcher { class_hash: starknet::class_hash_const::<0x1234>() }.name()
- }
-
- #[external]
- fn transfer_token(recipient: ContractAddress, amount: u256) -> bool {
- IERC20LibraryDispatcher {
- class_hash: starknet::class_hash_const::<0x1234>()
- }.transfer(recipient, amount)
- }
-}
-//ANCHOR_END: here
-
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_08_using_library_dispatcher/.gitignore b/listings/ch99-starknet-smart-contracts/listing_99_08_using_library_dispatcher/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_08_using_library_dispatcher/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_08_using_library_dispatcher/Scarb.toml b/listings/ch99-starknet-smart-contracts/listing_99_08_using_library_dispatcher/Scarb.toml
new file mode 100644
index 000000000..e0ac69641
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_08_using_library_dispatcher/Scarb.toml
@@ -0,0 +1,9 @@
+[package]
+name = "listing_99_08_using_library_dispatcher"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
+starknet = ">=2.2.0"
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_08_using_library_dispatcher/src/lib.cairo b/listings/ch99-starknet-smart-contracts/listing_99_08_using_library_dispatcher/src/lib.cairo
new file mode 100644
index 000000000..b659b96fa
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_08_using_library_dispatcher/src/lib.cairo
@@ -0,0 +1,35 @@
+//ANCHOR: here
+use starknet::ContractAddress;
+#[starknet::interface]
+trait IContractB {
+ fn set_value(ref self: TContractState, value: u128);
+
+ fn get_value(self: @TContractState) -> u128;
+}
+
+#[starknet::contract]
+mod ContractA {
+ use super::{IContractBDispatcherTrait, IContractBLibraryDispatcher};
+ use starknet::ContractAddress;
+
+ #[storage]
+ struct Storage {
+ value: u128
+ }
+
+ #[generate_trait]
+ #[external(v0)]
+ impl ContractA of IContractA {
+ fn set_value(ref self: ContractState, value: u128) {
+ IContractBLibraryDispatcher { class_hash: starknet::class_hash_const::<0x1234>() }
+ .set_value(value)
+ }
+
+ fn get_value(self: @ContractState) -> u128 {
+ self.value.read()
+ }
+ }
+}
+//ANCHOR_END: here
+
+
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_09_call_contract_syscall.cairo b/listings/ch99-starknet-smart-contracts/listing_99_09_call_contract_syscall.cairo
deleted file mode 100644
index ad7aa3919..000000000
--- a/listings/ch99-starknet-smart-contracts/listing_99_09_call_contract_syscall.cairo
+++ /dev/null
@@ -1,10 +0,0 @@
-#[contract]
-mod Contract {
- use array::ArrayTrait;
- #[external]
- fn transfer_token(
- address: starknet::ContractAddress, selector: felt252, calldata: Array
- ) -> Span:: {
- starknet::call_contract_syscall(address, selector, calldata.span()).unwrap_syscall()
- }
-}
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_09_call_contract_syscall/.gitignore b/listings/ch99-starknet-smart-contracts/listing_99_09_call_contract_syscall/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_09_call_contract_syscall/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_09_call_contract_syscall/Scarb.toml b/listings/ch99-starknet-smart-contracts/listing_99_09_call_contract_syscall/Scarb.toml
new file mode 100644
index 000000000..82d16d257
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_09_call_contract_syscall/Scarb.toml
@@ -0,0 +1,9 @@
+[package]
+name = "listing_99_09_call_contract_syscall"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
+starknet = ">=2.2.0"
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_09_call_contract_syscall/src/lib.cairo b/listings/ch99-starknet-smart-contracts/listing_99_09_call_contract_syscall/src/lib.cairo
new file mode 100644
index 000000000..fcf0294ed
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_09_call_contract_syscall/src/lib.cairo
@@ -0,0 +1,31 @@
+#[starknet::interface]
+trait ITokenWrapper {
+ fn transfer_token(
+ ref self: TContractState,
+ address: starknet::ContractAddress,
+ selector: felt252,
+ calldata: Array
+ ) -> bool;
+}
+
+#[starknet::contract]
+mod TokenWrapper {
+ use super::ITokenWrapper;
+ use starknet::SyscallResultTrait;
+
+ #[storage]
+ struct Storage {}
+
+ impl TokenWrapper of ITokenWrapper {
+ fn transfer_token(
+ ref self: ContractState,
+ address: starknet::ContractAddress,
+ selector: felt252,
+ calldata: Array
+ ) -> bool {
+ let mut res = starknet::call_contract_syscall(address, selector, calldata.span())
+ .unwrap_syscall();
+ Serde::::deserialize(ref res).unwrap()
+ }
+ }
+}
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_10_assert_balance/.gitignore b/listings/ch99-starknet-smart-contracts/listing_99_10_assert_balance/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_10_assert_balance/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_10_assert_balance/Scarb.toml b/listings/ch99-starknet-smart-contracts/listing_99_10_assert_balance/Scarb.toml
new file mode 100644
index 000000000..7ce7f8a04
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_10_assert_balance/Scarb.toml
@@ -0,0 +1,9 @@
+[package]
+name = "listing_99_10_assert_balance"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
+starknet = ">=2.2.0"
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_10_assert_balance/src/lib.cairo b/listings/ch99-starknet-smart-contracts/listing_99_10_assert_balance/src/lib.cairo
new file mode 100644
index 000000000..98e6ca3eb
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_10_assert_balance/src/lib.cairo
@@ -0,0 +1,26 @@
+#[starknet::interface]
+trait IContract {
+ fn withdraw(ref self: TContractState, amount: u256);
+}
+
+#[starknet::contract]
+mod contract {
+ use super::IContract;
+ #[storage]
+ struct Storage {
+ balance: u256
+ }
+
+ //ANCHOR: withdraw
+ impl Contract of IContract {
+ fn withdraw(ref self: ContractState, amount: u256) {
+ let current_balance = self.balance.read();
+
+ assert(self.balance.read() >= amount, 'Insufficient funds');
+
+ self.balance.write(current_balance - amount);
+ }
+ //ANCHOR_END: withdraw
+
+ }
+}
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_11_simple_access_control/.gitignore b/listings/ch99-starknet-smart-contracts/listing_99_11_simple_access_control/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_11_simple_access_control/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_11_simple_access_control/Scarb.toml b/listings/ch99-starknet-smart-contracts/listing_99_11_simple_access_control/Scarb.toml
new file mode 100644
index 000000000..0bba51c7b
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_11_simple_access_control/Scarb.toml
@@ -0,0 +1,9 @@
+[package]
+name = "listing_99_11_simple_access_control"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
+starknet = ">=2.2.0"
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_11_simple_access_control/src/lib.cairo b/listings/ch99-starknet-smart-contracts/listing_99_11_simple_access_control/src/lib.cairo
new file mode 100644
index 000000000..984589e6b
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_11_simple_access_control/src/lib.cairo
@@ -0,0 +1,79 @@
+#[starknet::contract]
+mod access_control_contract {
+ use starknet::ContractAddress;
+ use starknet::get_caller_address;
+
+ trait IContract {
+ fn is_owner(self: @TContractState) -> bool;
+ fn is_role_a(self: @TContractState) -> bool;
+ fn only_owner(self: @TContractState);
+ fn only_role_a(self: @TContractState);
+ fn only_allowed(self: @TContractState);
+ fn set_role_a(ref self: TContractState, _target: ContractAddress, _active: bool);
+ fn role_a_action(ref self: ContractState);
+ fn allowed_action(ref self: ContractState);
+ }
+
+ #[storage]
+ struct Storage {
+ // Role 'owner': only one address
+ owner: ContractAddress,
+ // Role 'role_a': a set of addresses
+ role_a: LegacyMap::
+ }
+
+ #[constructor]
+ fn constructor(ref self: ContractState) {
+ self.owner.write(get_caller_address());
+ }
+
+ // Guard functions to check roles
+
+ impl Contract of IContract {
+ #[inline(always)]
+ fn is_owner(self: @ContractState) -> bool {
+ self.owner.read() == get_caller_address()
+ }
+
+ #[inline(always)]
+ fn is_role_a(self: @ContractState) -> bool {
+ self.role_a.read(get_caller_address())
+ }
+
+ #[inline(always)]
+ fn only_owner(self: @ContractState) {
+ assert(Contract::is_owner(self), 'Not owner');
+ }
+
+ #[inline(always)]
+ fn only_role_a(self: @ContractState) {
+ assert(Contract::is_role_a(self), 'Not role A');
+ }
+
+ // You can easily combine guards to perfom complex checks
+ fn only_allowed(self: @ContractState) {
+ assert(Contract::is_owner(self) || Contract::is_role_a(self), 'Not allowed');
+ }
+
+ // Functions to manage roles
+
+ fn set_role_a(ref self: ContractState, _target: ContractAddress, _active: bool) {
+ Contract::only_owner(@self);
+ self.role_a.write(_target, _active);
+ }
+
+ // You can now focus on the business logic of your contract
+ // and reduce the complexity of your code by using guard functions
+
+ fn role_a_action(ref self: ContractState) {
+ Contract::only_role_a(@self);
+ // ...
+ }
+
+ fn allowed_action(ref self: ContractState) {
+ Contract::only_allowed(@self);
+ // ...
+ }
+ }
+}
+
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_12_vote_contract/.gitignore b/listings/ch99-starknet-smart-contracts/listing_99_12_vote_contract/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_12_vote_contract/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_12_vote_contract/Scarb.toml b/listings/ch99-starknet-smart-contracts/listing_99_12_vote_contract/Scarb.toml
new file mode 100644
index 000000000..93227989c
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_12_vote_contract/Scarb.toml
@@ -0,0 +1,9 @@
+[package]
+name = "listing_99_12_vote_contract"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
+starknet = ">=2.2.0"
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_12_vote_contract/src/lib.cairo b/listings/ch99-starknet-smart-contracts/listing_99_12_vote_contract/src/lib.cairo
new file mode 100644
index 000000000..89b67b7ad
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_12_vote_contract/src/lib.cairo
@@ -0,0 +1,172 @@
+/// @dev Core Library Imports for the Traits outside the Starknet Contract
+use starknet::ContractAddress;
+
+/// @dev Trait defining the functions that can be implemented or called by the Starknet Contract
+#[starknet::interface]
+trait VoteTrait {
+ /// @dev Function that returns the current vote status
+ fn get_vote_status(self: @T) -> (u8, u8, u8, u8);
+ /// @dev Function that checks if the user at the specified address is allowed to vote
+ fn voter_can_vote(self: @T, user_address: ContractAddress) -> bool;
+ /// @dev Function that checks if the specified address is registered as a voter
+ fn is_voter_registered(self: @T, address: ContractAddress) -> bool;
+ /// @dev Function that allows a user to vote
+ fn vote(ref self: T, vote: u8);
+}
+
+/// @dev Starknet Contract allowing three registered voters to vote on a proposal
+#[starknet::contract]
+mod Vote {
+ use starknet::ContractAddress;
+ use starknet::get_caller_address;
+
+ const YES: u8 = 1_u8;
+ const NO: u8 = 0_u8;
+
+ /// @dev Structure that stores vote counts and voter states
+ #[storage]
+ struct Storage {
+ yes_votes: u8,
+ no_votes: u8,
+ can_vote: LegacyMap::,
+ registered_voter: LegacyMap::,
+ }
+
+ /// @dev Contract constructor initializing the contract with a list of registered voters and 0 vote count
+ #[constructor]
+ fn constructor(
+ ref self: ContractState,
+ voter_1: ContractAddress,
+ voter_2: ContractAddress,
+ voter_3: ContractAddress
+ ) {
+ // Register all voters by calling the _register_voters function
+ self._register_voters(voter_1, voter_2, voter_3);
+
+ // Initialize the vote count to 0
+ self.yes_votes.write(0_u8);
+ self.no_votes.write(0_u8);
+ }
+
+ /// @dev Event that gets emitted when a vote is cast
+ #[event]
+ #[derive(Drop, starknet::Event)]
+ enum Event {
+ VoteCast: VoteCast,
+ UnauthorizedAttempt: UnauthorizedAttempt,
+ }
+
+ /// @dev Represents a vote that was cast
+ #[derive(Drop, starknet::Event)]
+ struct VoteCast {
+ voter: ContractAddress,
+ vote: u8,
+ }
+
+ /// @dev Represents an unauthorized attempt to vote
+ #[derive(Drop, starknet::Event)]
+ struct UnauthorizedAttempt {
+ unauthorized_address: ContractAddress,
+ }
+
+ /// @dev Implementation of VoteTrait for ContractState
+ #[external(v0)]
+ impl VoteImpl of super::VoteTrait {
+ /// @dev Returns the voting results
+ fn get_vote_status(self: @ContractState) -> (u8, u8, u8, u8) {
+ let (n_yes, n_no) = self._get_voting_result();
+ let (yes_percentage, no_percentage) = self._get_voting_result_in_percentage();
+ return (n_yes, n_no, yes_percentage, no_percentage);
+ }
+
+ /// @dev Check whether a voter is allowed to vote
+ fn voter_can_vote(self: @ContractState, user_address: ContractAddress) -> bool {
+ self.can_vote.read(user_address)
+ }
+
+ /// @dev Check whether an address is registered as a voter
+ fn is_voter_registered(self: @ContractState, address: ContractAddress) -> bool {
+ self.registered_voter.read(address)
+ }
+
+ /// @dev Submit a vote
+ fn vote(ref self: ContractState, vote: u8) {
+ assert(vote == NO || vote == YES, 'VOTE_0_OR_1');
+ let caller: ContractAddress = get_caller_address();
+ self._assert_allowed(caller);
+ self.can_vote.write(caller, false);
+
+ if (vote == NO) {
+ self.no_votes.write(self.no_votes.read() + 1_u8);
+ }
+ if (vote == YES) {
+ self.yes_votes.write(self.yes_votes.read() + 1_u8);
+ }
+
+ self.emit(VoteCast { voter: caller, vote: vote, });
+ }
+ }
+
+ /// @dev Internal Functions implementation for the Vote contract
+ #[generate_trait]
+ impl InternalFunctions of InternalFunctionsTrait {
+ /// @dev Registers the voters and initializes their voting status to true (can vote)
+ fn _register_voters(
+ ref self: ContractState,
+ voter_1: ContractAddress,
+ voter_2: ContractAddress,
+ voter_3: ContractAddress
+ ) {
+ self.registered_voter.write(voter_1, true);
+ self.can_vote.write(voter_1, true);
+
+ self.registered_voter.write(voter_2, true);
+ self.can_vote.write(voter_2, true);
+
+ self.registered_voter.write(voter_3, true);
+ self.can_vote.write(voter_3, true);
+ }
+ }
+
+ /// @dev Asserts implementation for the Vote contract
+ #[generate_trait]
+ impl AssertsImpl of AssertsTrait {
+ // @dev Internal function that checks if an address is allowed to vote
+ fn _assert_allowed(ref self: ContractState, address: ContractAddress) {
+ let is_voter: bool = self.registered_voter.read((address));
+ let can_vote: bool = self.can_vote.read((address));
+
+ if (can_vote == false) {
+ self.emit(UnauthorizedAttempt { unauthorized_address: address, });
+ }
+
+ assert(is_voter == true, 'USER_NOT_REGISTERED');
+ assert(can_vote == true, 'USER_ALREADY_VOTED');
+ }
+ }
+
+ /// @dev Implement the VotingResultTrait for the Vote contract
+ #[generate_trait]
+ impl VoteResultFunctionsImpl of VoteResultFunctionsTrait {
+ // @dev Internal function to get the voting results (yes and no vote counts)
+ fn _get_voting_result(self: @ContractState) -> (u8, u8) {
+ let n_yes: u8 = self.yes_votes.read();
+ let n_no: u8 = self.no_votes.read();
+
+ return (n_yes, n_no);
+ }
+
+ // @dev Internal function to calculate the voting results in percentage
+ fn _get_voting_result_in_percentage(self: @ContractState) -> (u8, u8) {
+ let n_yes: u8 = self.yes_votes.read();
+ let n_no: u8 = self.no_votes.read();
+
+ let total_votes: u8 = n_yes + n_no;
+
+ let yes_percentage: u8 = (n_yes * 100_u8) / (total_votes);
+ let no_percentage: u8 = (n_no * 100_u8) / (total_votes);
+
+ return (yes_percentage, no_percentage);
+ }
+ }
+}
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_13_storage_packing/.gitignore b/listings/ch99-starknet-smart-contracts/listing_99_13_storage_packing/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_13_storage_packing/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_13_storage_packing/Scarb.toml b/listings/ch99-starknet-smart-contracts/listing_99_13_storage_packing/Scarb.toml
new file mode 100644
index 000000000..95d3b7260
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_13_storage_packing/Scarb.toml
@@ -0,0 +1,9 @@
+[package]
+name = "listing_99_13_storage_packing"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
+starknet = ">=2.2.0"
diff --git a/listings/ch99-starknet-smart-contracts/listing_99_13_storage_packing/src/lib.cairo b/listings/ch99-starknet-smart-contracts/listing_99_13_storage_packing/src/lib.cairo
new file mode 100644
index 000000000..ffa80369e
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/listing_99_13_storage_packing/src/lib.cairo
@@ -0,0 +1,83 @@
+//ANCHOR:here
+use starknet::{StorePacking};
+use integer::{u128_safe_divmod, u128_as_non_zero};
+
+#[derive(Drop, Serde)]
+struct Sizes {
+ tiny: u8,
+ small: u32,
+ medium: u64,
+}
+
+const TWO_POW_8: u128 = 0x100;
+const TWO_POW_40: u128 = 0x10000000000;
+
+const MASK_8: u128 = 0xff;
+const MASK_32: u128 = 0xffffffff;
+
+
+impl SizesStorePacking of StorePacking {
+ fn pack(value: Sizes) -> u128 {
+ value.tiny.into() + (value.small.into() * TWO_POW_8) + (value.medium.into() * TWO_POW_40)
+ }
+
+ fn unpack(value: u128) -> Sizes {
+ let tiny = value & MASK_8;
+ let small = (value / TWO_POW_8) & MASK_32;
+ let medium = (value / TWO_POW_40);
+
+ Sizes {
+ tiny: tiny.try_into().unwrap(),
+ small: small.try_into().unwrap(),
+ medium: medium.try_into().unwrap(),
+ }
+ }
+}
+
+#[starknet::contract]
+mod SizeFactory {
+ use super::Sizes;
+ use super::SizesStorePacking; //don't forget to import it!
+
+ #[storage]
+ struct Storage {
+ remaining_sizes: Sizes
+ }
+
+ #[external(v0)]
+ fn update_sizes(ref self: ContractState, sizes: Sizes) {
+ // This will automatically pack the
+ // struct into a single u128
+ self.remaining_sizes.write(sizes);
+ }
+
+
+ #[external(v0)]
+ fn get_sizes(ref self: ContractState) -> Sizes {
+ // this will automatically unpack the
+ // packed-representation into the Sizes struct
+ self.remaining_sizes.read()
+ }
+}
+
+
+//ANCHOR_END:here
+
+#[cfg(test)]
+mod tests {
+ use super::{SizesStorePacking, Sizes};
+ use starknet::StorePacking;
+ #[test]
+ #[available_gas(200000)]
+ fn test_pack_unpack() {
+ let value = Sizes { tiny: 0x12, small: 0x12345678, medium: 0x1234567890, };
+
+ let packed = SizesStorePacking::pack(value);
+ assert(packed == 0x12345678901234567812, 'wrong packed value');
+
+ let unpacked = SizesStorePacking::unpack(packed);
+ assert(unpacked.tiny == 0x12, 'wrong unpacked tiny');
+ assert(unpacked.small == 0x12345678, 'wrong unpacked small');
+ assert(unpacked.medium == 0x1234567890, 'wrong unpacked medium');
+ }
+}
diff --git a/listings/ch99-starknet-smart-contracts/no_listing_01_storage_mapping/.gitignore b/listings/ch99-starknet-smart-contracts/no_listing_01_storage_mapping/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/no_listing_01_storage_mapping/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch99-starknet-smart-contracts/no_listing_01_storage_mapping/Scarb.toml b/listings/ch99-starknet-smart-contracts/no_listing_01_storage_mapping/Scarb.toml
new file mode 100644
index 000000000..20367ea36
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/no_listing_01_storage_mapping/Scarb.toml
@@ -0,0 +1,9 @@
+[package]
+name = "no_listing_01_storage_mapping"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
+starknet = ">=2.2.0"
diff --git a/listings/ch99-starknet-smart-contracts/no_listing_01_storage_mapping.cairo b/listings/ch99-starknet-smart-contracts/no_listing_01_storage_mapping/src/lib.cairo
similarity index 61%
rename from listings/ch99-starknet-smart-contracts/no_listing_01_storage_mapping.cairo
rename to listings/ch99-starknet-smart-contracts/no_listing_01_storage_mapping/src/lib.cairo
index 93796090b..d7d15ce48 100644
--- a/listings/ch99-starknet-smart-contracts/no_listing_01_storage_mapping.cairo
+++ b/listings/ch99-starknet-smart-contracts/no_listing_01_storage_mapping/src/lib.cairo
@@ -1,6 +1,8 @@
-#[contract]
-mod Contract {
+#[starknet::contract]
+mod contract {
+ use starknet::ContractAddress;
//ANCHOR: here
+ #[storage]
struct Storage {
allowances: LegacyMap::<(ContractAddress, ContractAddress), u256>
}
diff --git a/listings/ch99-starknet-smart-contracts/no_listing_99_02_explicit_internal_fn/.gitignore b/listings/ch99-starknet-smart-contracts/no_listing_99_02_explicit_internal_fn/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/no_listing_99_02_explicit_internal_fn/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch99-starknet-smart-contracts/no_listing_99_02_explicit_internal_fn/Scarb.toml b/listings/ch99-starknet-smart-contracts/no_listing_99_02_explicit_internal_fn/Scarb.toml
new file mode 100644
index 000000000..9fb09db64
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/no_listing_99_02_explicit_internal_fn/Scarb.toml
@@ -0,0 +1,9 @@
+[package]
+name = "no_listing_99_02_explicit_internal_fn"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
+starknet = ">=2.2.0"
diff --git a/listings/ch99-starknet-smart-contracts/no_listing_99_02_explicit_internal_fn/src/lib.cairo b/listings/ch99-starknet-smart-contracts/no_listing_99_02_explicit_internal_fn/src/lib.cairo
new file mode 100644
index 000000000..e70703a26
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/no_listing_99_02_explicit_internal_fn/src/lib.cairo
@@ -0,0 +1,57 @@
+//ANCHOR: all
+
+use starknet::ContractAddress;
+
+#[starknet::contract]
+mod NameRegistry {
+ use starknet::{ContractAddress, get_caller_address};
+
+ #[storage]
+ struct Storage {
+ names: LegacyMap::,
+ total_names: u128,
+ owner: Person
+ }
+
+ //ANCHOR: person
+ #[derive(Copy, Drop, Serde, starknet::Store)]
+ struct Person {
+ name: felt252,
+ address: ContractAddress
+ }
+ //ANCHOR_END: person
+
+ //ANCHOR: event
+ #[event]
+ #[derive(Drop, starknet::Event)]
+ enum Event {
+ StoredName: StoredName,
+ }
+
+ #[derive(Drop, starknet::Event)]
+ struct StoredName {
+ #[key]
+ user: ContractAddress,
+ name: felt252
+ }
+
+ // ANCHOR: state_internal
+ trait InternalFunctionsTrait {
+ fn _store_name(ref self: TContractState, user: ContractAddress, name: felt252);
+ }
+ impl InternalFunctions of InternalFunctionsTrait {
+ fn _store_name(ref self: ContractState, user: ContractAddress, name: felt252) {
+ let mut total_names = self.total_names.read();
+ self.names.write(user, name);
+ self.total_names.write(total_names + 1);
+ //ANCHOR: emit_event
+ self.emit(Event::StoredName(StoredName { user: user, name: name }));
+ //ANCHOR_END: emit_event
+
+ }
+ }
+// ANCHOR: state_internal
+}
+//ANCHOR_END: all
+
+
diff --git a/listings/ch99-starknet-smart-contracts/no_listing_event_trait/.gitignore b/listings/ch99-starknet-smart-contracts/no_listing_event_trait/.gitignore
new file mode 100644
index 000000000..eb5a316cb
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/no_listing_event_trait/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/listings/ch99-starknet-smart-contracts/no_listing_event_trait/Scarb.toml b/listings/ch99-starknet-smart-contracts/no_listing_event_trait/Scarb.toml
new file mode 100644
index 000000000..c5fe7e10d
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/no_listing_event_trait/Scarb.toml
@@ -0,0 +1,9 @@
+[package]
+name = "no_listing_event_trait"
+version = "0.1.0"
+
+# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest
+
+[dependencies]
+# foo = { path = "vendor/foo" }
+starknet = ">=2.2.0"
diff --git a/listings/ch99-starknet-smart-contracts/no_listing_event_trait/src/lib.cairo b/listings/ch99-starknet-smart-contracts/no_listing_event_trait/src/lib.cairo
new file mode 100644
index 000000000..bce820c13
--- /dev/null
+++ b/listings/ch99-starknet-smart-contracts/no_listing_event_trait/src/lib.cairo
@@ -0,0 +1,4 @@
+trait Event {
+ fn append_keys_and_data(self: T, ref keys: Array, ref data: Array);
+ fn deserialize(ref keys: Span, ref data: Span) -> Option;
+}
diff --git a/mdbook-cairo/Cargo.toml b/mdbook-cairo/Cargo.toml
index 05cb14a19..1de3d3df1 100644
--- a/mdbook-cairo/Cargo.toml
+++ b/mdbook-cairo/Cargo.toml
@@ -1,16 +1,16 @@
[package]
name = "mdbook-cairo"
-version = "0.1.0"
+version = "0.2.0"
edition = "2021"
license = "MIT"
authors = ["Cairo-book community"]
-description = "A tool for extracting cairo code from Markdown files as compilable cairo programs."
+description = "A mdbook preprocessor to be used with cairo-verify"
repository = "https://github.com/cairo-book/cairo-book.github.io"
[dependencies]
+clap = "4.3.5"
+lazy_static = "1.4.0"
mdbook = "0.4.28"
-pulldown-cmark = { version = "0.9.2", default-features = false }
-serde = "1.0.163"
-serde_derive = "1.0.163"
-lazy_static = "1.4"
-regex = "1.8.1"
+regex = "1.8.4"
+semver = "1.0.17"
+serde_json = "1.0.97"
diff --git a/mdbook-cairo/README.md b/mdbook-cairo/README.md
index a5871ff29..dda6dfaea 100644
--- a/mdbook-cairo/README.md
+++ b/mdbook-cairo/README.md
@@ -1,13 +1,9 @@
-# mdbook backend to generate cairo programs
-
-This backend aims at generating compilable Cairo programs from
-Markdown code blocks.
-
-Only code blocks with ...
-
+# mdbook preprocessor for cairo program
+This mdbook preprocessor removes the `// TAG` lines from the cairo code blocks in the markdown files.
+It was made to be used with the `cairo-verify` tool.
# Useful links:
-- [Markdown backend documentation](https://rust-lang.github.io/mdBook/for_developers/backends.html)
+- [Mdbook preprocessor documentation](https://rust-lang.github.io/mdBook/for_developers/preprocessors.html)
diff --git a/mdbook-cairo/scripts/cairo_local_verify.sh b/mdbook-cairo/scripts/cairo_local_verify.sh
deleted file mode 100644
index b74507532..000000000
--- a/mdbook-cairo/scripts/cairo_local_verify.sh
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/bin/bash
-#
-# Runs locally a CI like workflow to test the Cairo code blocks in the cairo-book sources.
-#
-# This process is using docker, to be consistent with the CI.
-# The version of the docker image must fit the one used in the CI to ensure consistency.
-#
-# This script must be executed being at the root of this repository.
-#
-
-
-
-# https://hub.docker.com/r/starknet/cairo
-STARKNET_CAIRO_IMAGE=starknet/cairo:1.1.0
-
-# 1. Install mdbook-cairo locally.
-cargo install --path mdbook-cairo --locked --force
-
-# 2. Cleanup existing book. As the docker is run as root, some outputed files are not
-# accessible if not used with sudo, which makes mdbook clean unsuitable.
-sudo rm -rf book
-
-# 3. Build the book to have the cairo mdbook backend running and extracting the programs.
-mdbook build -d book
-
-# 4. The cairo_programs_verifier.sh script must be copied in order to be mounted in the
-# docker container with the extracted cairo programs.
-cp mdbook-cairo/scripts/cairo_programs_verifier.sh book/cairo/cairo-programs/
-
-# 5. Run the docker image to actually run the cairo programs.
-sudo docker run --rm \
- -v "$(pwd)"/book/cairo/cairo-programs:/cairo \
- --entrypoint sh \
- "$STARKNET_CAIRO_IMAGE" \
- /cairo/cairo_programs_verifier.sh true
-
diff --git a/mdbook-cairo/scripts/cairo_programs_verifier.sh b/mdbook-cairo/scripts/cairo_programs_verifier.sh
deleted file mode 100644
index 598a97ee0..000000000
--- a/mdbook-cairo/scripts/cairo_programs_verifier.sh
+++ /dev/null
@@ -1,81 +0,0 @@
-#!/bin/bash
-
-IS_RUN_LOCALLY="$1"
-
-GREEN='\033[1;32m'
-RED='\033[1;31m'
-NC='\033[0m'
-
-cd /cairo
-mkdir -p output
-rm -rf output/*
-
-if [ "$IS_RUN_LOCALLY" = true ]; then
- echo -e "\nStarting Cairo programs verifier...\n"
-else
- echo "# Cairo program verifier"
- echo ""
- echo "The list of cairo programs below is auto-generated from the markdown sources."
- echo "Any code block with a main function will be compiled (except if the attribute does_not_compile is manually added)."
- echo "Cairo-format is also executed to enforce consistent code style."
- echo ""
-fi
-
-has_error=false
-has_format_error=false
-
-for prog in *.cairo; do
- # Check compilation if needed
- compile_code=0
- if [[ "$prog" =~ "_checkcomp" ]]; then
- cairo-run --available-gas=20000000 "$prog" > output/"$prog".out 2> output/"$prog".err
- compile_code="$?"
- fi
-
- # Check format if needed
- format_code=0
- if [[ $prog =~ "_checkfmt" ]]; then
- cairo-format --check --print-parsing-errors "$prog" > output/"$prog".err
- format_code="$?"
- fi
-
- if [ $compile_code -ne 0 ] || [ $format_code -ne 0 ]; then
- err="$(cat output/$prog.err)"
- has_error=true
-
- if [ "$IS_RUN_LOCALLY" = true ]; then
- echo -e "\n---- ${RED}${prog}${NC} ----\n"
- echo "$err"
- else
- echo ":x: **$prog**"
- echo "$err
"
- fi
-
- echo ""
- echo "--- "
- echo ""
- fi
-
-
-done
-
-if [ "$has_error" = false ] ; then
- if [ "$IS_RUN_LOCALLY" = true ]; then
- echo -e "\n${GREEN}All Cairo programs were compiled successfully and no formatting mistakes were found${NC}.\n"
- else
- echo ":heavy_check_mark: All Cairo programs were compiled successfully and no formatting mistakes were found."
- echo ""
- fi
-
- exit 0
-else
-
- if [ "$IS_RUN_LOCALLY" = true ]; then
- echo -e "\n${RED}Some Cairo programs have errors, please check the list above.${NC}\n"
- else
- echo ":x: Some Cairo programs have errors, please check the list above."
- echo ""
- fi
-
- exit 1
-fi
diff --git a/mdbook-cairo/src/lib.rs b/mdbook-cairo/src/lib.rs
new file mode 100644
index 000000000..890a9407e
--- /dev/null
+++ b/mdbook-cairo/src/lib.rs
@@ -0,0 +1,63 @@
+use lazy_static::lazy_static;
+use mdbook::book::{Book, BookItem};
+use mdbook::errors::Error;
+use mdbook::preprocess::{Preprocessor, PreprocessorContext};
+use regex::Regex;
+
+const TAG_REGEX_PATTERN: &str = r"^//\s*TAG";
+
+lazy_static! {
+ static ref TAG_REGEX: Regex = Regex::new(TAG_REGEX_PATTERN).unwrap();
+}
+
+/// The actual implementation of the `Cairo` preprocessor.
+pub struct Cairo;
+
+impl Cairo {
+ pub fn new() -> Cairo {
+ Cairo
+ }
+}
+
+impl Default for Cairo {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
+impl Preprocessor for Cairo {
+ fn name(&self) -> &str {
+ "cairo-preprocessor"
+ }
+
+ fn run(&self, _ctx: &PreprocessorContext, mut book: Book) -> Result {
+ book.for_each_mut(|item: &mut BookItem| {
+ if let BookItem::Chapter(ref mut chapter) = *item {
+ let mut new_content = String::new();
+ let lines = chapter.content.split_terminator('\n').peekable();
+ let mut in_code_block = false;
+
+ for line in lines {
+ in_code_block ^= line.starts_with("```");
+
+ if in_code_block && TAG_REGEX.is_match(line) {
+ // delete this line
+ continue;
+ }
+
+ new_content.push_str(line);
+ new_content.push('\n');
+ }
+
+ chapter.content = new_content;
+ }
+ });
+
+ // Return updated version of the book
+ Ok(book)
+ }
+
+ fn supports_renderer(&self, renderer: &str) -> bool {
+ renderer != "not-supported"
+ }
+}
diff --git a/mdbook-cairo/src/main.rs b/mdbook-cairo/src/main.rs
index 5be533805..ab1143871 100644
--- a/mdbook-cairo/src/main.rs
+++ b/mdbook-cairo/src/main.rs
@@ -1,148 +1,68 @@
-use lazy_static::lazy_static;
-use mdbook::book::{Book, BookItem, Chapter};
-use mdbook::renderer::RenderContext;
-use pulldown_cmark::{CodeBlockKind, Event, Parser, Tag};
-use regex::Regex;
-use serde::{Deserialize, Serialize};
-use std::fs::{create_dir_all, remove_dir_all, File};
-use std::io::{self, Write};
-use std::path::Path;
-
-/// The table header expected in book.toml.
-const CAIRO_CONFIG_TABLE_HEADER: &str = "output.cairo";
-
-/// An attribute added to a code block tag to ignore
-/// the code extraction.
-const CODE_BLOCK_DOES_NOT_COMPILE: &str = "does_not_compile";
-
-/// An attribute added to a code block tag to ignore
-/// the format check.
-const CODE_BLOCK_IGNORE_FORMAT: &str = "ignore_format";
-
-/// Main function expected in a code block to be a candidate
-/// for the code extraction.
-const CODE_BLOCK_MAIN_FUNCTION: &str = "fn main()";
-
-/// Struct mapping fields expected in [output.cairo] from book.toml.
-#[derive(Debug, Default, Serialize, Deserialize)]
-#[serde(default, rename_all = "kebab-case")]
-pub struct CairoConfig {
- pub output_dir: String,
+use clap::{Arg, ArgMatches, Command};
+use mdbook::errors::Error;
+use mdbook::preprocess::{CmdPreprocessor, Preprocessor};
+use semver::{Version, VersionReq};
+use std::io;
+use std::process;
+
+use mdbook_cairo::Cairo;
+
+pub fn make_app() -> Command {
+ Command::new("cairo-preprocessor")
+ .about("A mdbook preprocessor which remove '// TAG' lines in cairo code blocks")
+ .subcommand(
+ Command::new("supports")
+ .arg(Arg::new("renderer").required(true))
+ .about("Check whether a renderer is supported by this preprocessor"),
+ )
}
-// Statically initialize the regex to avoid rebuiling at each loop iteration.
-lazy_static! {
- static ref REGEX: Regex =
- Regex::new(r"^ch(\d{2})-(\d{2})-(.*)$").expect("Failed to create regex");
-}
-
-/// Backend entry point, which received the mdbook content directly from stdin.
fn main() {
- let mut stdin = io::stdin();
- let ctx = RenderContext::from_json(&mut stdin)
- .expect("Couldn't get mdbook render context from stdin.");
-
- // Execute the rendered only on english version.
- if !ctx
- .destination
- .as_path()
- .display()
- .to_string()
- .contains("/book/cairo")
- {
- println!("No default english build, skipping cairo output.");
- return;
- }
-
- let cfg: CairoConfig = ctx
- .config
- .get_deserialized_opt(CAIRO_CONFIG_TABLE_HEADER)
- .expect("Couldn't deserialize cairo config from book.toml.")
- .unwrap();
-
- let output_path = Path::new(cfg.output_dir.as_str());
+ let matches = make_app().get_matches();
- remove_dir_all(output_path)
- .unwrap_or_else(|_| println!("Couldn't clean output directory, skip."));
+ // Users will want to construct their own preprocessor here
+ let preprocessor = Cairo::new();
- create_dir_all(output_path).expect("Couldn't create output directory.");
-
- process_chapters(&ctx.book, &output_path);
-}
-
-/// Processes all the chapters to search for code block.
-fn process_chapters(book: &Book, output_dir: &Path) {
- for item in book.iter() {
- if let BookItem::Chapter(chapter) = item {
- if let Some(chapter_prefix) = chapter_prefix_from_name(chapter) {
- process_chapter(output_dir, &chapter_prefix, &chapter.content);
- }
- }
+ if let Some(sub_args) = matches.subcommand_matches("supports") {
+ handle_supports(&preprocessor, sub_args);
+ } else if let Err(e) = handle_preprocessing(&preprocessor) {
+ eprintln!("{}", e);
+ process::exit(1);
}
}
-/// Extract the prefix of the chapter from filename string.
-fn chapter_prefix_from_name(chapter: &Chapter) -> Option {
- if let Some(p) = &chapter.path {
- let file_name = p.to_string_lossy().to_string();
+fn handle_preprocessing(pre: &dyn Preprocessor) -> Result<(), Error> {
+ let (ctx, book) = CmdPreprocessor::parse_input(io::stdin())?;
- if let Some(groups) = REGEX.captures(&file_name) {
- if let (Some(c), Some(s)) = (groups.get(1), groups.get(2)) {
- let c = c.as_str();
- let s = s.as_str();
- return Some(format!("ch{}_{}", c, s));
- }
- }
- }
-
- None
-}
+ let book_version = Version::parse(&ctx.mdbook_version)?;
+ let version_req = VersionReq::parse(mdbook::MDBOOK_VERSION)?;
-/// Processes the content of a chapter to parse code blocks and write them to a file.
-fn process_chapter(output_dir: &Path, prefix: &str, content: &str) {
- let parser = Parser::new(content);
-
- let mut program_counter = 1;
- let mut in_code_block = false;
- let mut is_compilable = false;
- let mut enforce_format = true;
-
- for event in parser {
- match event {
- Event::Start(Tag::CodeBlock(x)) => {
- in_code_block = true;
-
- if let CodeBlockKind::Fenced(tag_value) = x {
- is_compilable = !tag_value.to_string().contains(CODE_BLOCK_DOES_NOT_COMPILE);
- enforce_format = !tag_value.to_string().contains(CODE_BLOCK_IGNORE_FORMAT);
- }
- }
- Event::Text(text) => {
- if in_code_block && text.contains(CODE_BLOCK_MAIN_FUNCTION) {
- if is_compilable || enforce_format {
- let compile_tag = if is_compilable { "_checkcomp" } else { "" };
- let format_tag = if enforce_format { "_checkfmt" } else { "" };
- let file_name = format!(
- "{}_{}{}{}.cairo",
- prefix, program_counter, compile_tag, format_tag
- );
+ if !version_req.matches(&book_version) {
+ eprintln!(
+ "Warning: The {} plugin was built against version {} of mdbook, \
+ but we're being called from version {}",
+ pre.name(),
+ mdbook::MDBOOK_VERSION,
+ ctx.mdbook_version
+ );
+ }
- let file_dir = &output_dir.join(file_name);
- let mut file = File::create(file_dir).expect("Failed to create file.");
+ let processed_book = pre.run(&ctx, book)?;
+ serde_json::to_writer(io::stdout(), &processed_book)?;
- file.write(text.as_bytes()).expect("Can't write to file.");
- }
+ Ok(())
+}
- // To facilitate the debugging, we always increment the counter when a
- // main function is found in a code block. This helps contributors to
- // easily locate the code, without having to skip the `does_not_compile` blocks.
- program_counter += 1;
- }
- }
- Event::End(Tag::CodeBlock(_)) => {
- in_code_block = false;
- }
- _ => {}
- }
+fn handle_supports(pre: &dyn Preprocessor, sub_args: &ArgMatches) -> ! {
+ let renderer = sub_args
+ .get_one::("renderer")
+ .expect("Required argument");
+ let supported = pre.supports_renderer(renderer);
+
+ // Signal whether the renderer is supported by exiting with 1 or 0.
+ if supported {
+ process::exit(0);
+ } else {
+ process::exit(1);
}
}
diff --git a/po/es.po b/po/es.po
index d046f14dd..3c2e2702d 100644
--- a/po/es.po
+++ b/po/es.po
@@ -2,7 +2,7 @@ msgid ""
msgstr ""
"Project-Id-Version: The Cairo Programming Language\n"
"POT-Creation-Date: \n"
-"PO-Revision-Date: 2023-05-31 13:23+0100\n"
+"PO-Revision-Date: 2023-06-26 00:08+0100\n"
"Last-Translator: dami \n"
"Language-Team: Spanish \n"
"Language: es\n"
@@ -168,51 +168,63 @@ msgstr "Errores Irrecuperables con pánico"
msgid "Recoverable Errors with Result"
msgstr "Errores Recuperables con Resultados"
-#: src/SUMMARY.md:77
+#: src/SUMMARY.md:75
+msgid "Advanced Features"
+msgstr "Funciones Avanzadas"
+
+#: src/SUMMARY.md:78
+msgid "Operator Overloading"
+msgstr "Sobrecarga de Operadores"
+
+#: src/SUMMARY.md:82
msgid "Starknet Smart Contracts"
msgstr "Starknet Smart Contracts"
-#: src/SUMMARY.md:79
+#: src/SUMMARY.md:84
msgid "Introduction to smart-contracts"
msgstr "Introducción a los smart-contracts"
-#: src/SUMMARY.md:80
+#: src/SUMMARY.md:85
msgid "Writing Starknet Contracts"
msgstr "Escribiendo Contratos en Starknet"
-#: src/SUMMARY.md:81
+#: src/SUMMARY.md:86
msgid "ABIs and Cross-contract Interactions"
msgstr "ABIs e Interacciones entre Contratos Multicapa"
-#: src/SUMMARY.md:82
+#: src/SUMMARY.md:87
msgid "ABIs and Interfaces"
msgstr "ABIs e interfaces"
-#: src/SUMMARY.md:83
+#: src/SUMMARY.md:88
msgid "Contract Dispatchers, Library Dispachers and system calls"
msgstr "Despachadores de contratos, despachadores de librerías y llamadas del sistema"
-#: src/SUMMARY.md:85
+#: src/SUMMARY.md:89
+msgid "Security Considerations"
+msgstr "Consideraciones de Seguridad"
+
+#: src/SUMMARY.md:91
msgid "Appendix"
msgstr "Apéndice"
-#: src/SUMMARY.md:86
+#: src/SUMMARY.md:92
msgid "A - Keywords"
msgstr "A - Palabras clave"
-#: src/SUMMARY.md:87
+#: src/SUMMARY.md:93
msgid "B - Operators and Symbols"
msgstr "B - Operadores y Símbolos"
-#: src/SUMMARY.md:88
+#: src/SUMMARY.md:94
msgid "C - Derivable Traits"
msgstr "C - Traits Derivables"
-#: src/SUMMARY.md:89
+#: src/SUMMARY.md:95
msgid "D - Useful Development Tools"
msgstr "D - Herramientas de Desarrollo Útiles"
-#: src/SUMMARY.md:90
+#: src/SUMMARY.md:96
msgid "E - Cairo Most Common Types and Traits"
msgstr "E - Tipos y Traits más comunes en Cairo"
@@ -229,8 +241,8 @@ msgstr ""
"[OnlyDust](https://www.onlydust.xyz/), y [Voyager](https://voyager.online/) por apoyar la creación de este libro."
#: src/title-page.md:5
-msgid "This version of the text assumes you’re using Cairo v1.0.0 (released 2023-05-15). See the “Installation” section of Chapter 1 to install or update Cairo."
-msgstr "Esta versión del texto asume que estás usando Cairo v1.0.0 (publicado el 2023-05-15). Consulte la sección \"Instalación\" del Capítulo 1 para instalar o actualizar Cairo."
+msgid "This version of the text assumes you’re using Cairo v1.1.0. See the “Installation” section of Chapter 1 to install or update Cairo."
+msgstr "Esta versión del texto asume que estás usando Cairo v1.1.0. Consulte la sección \"Instalación\" del Capítulo 1 para instalar o actualizar Cairo."
#: src/ch00-01-foreword.md:1
msgid "# Foreword"
@@ -318,16 +330,16 @@ msgstr "## ¿Qué puedes hacer con Cairo?"
msgid ""
"Cairo allows you to compute trustworthy values on untrusted machines. One major usecase is Starknet, a solution to Ethereum scaling. Ethereum is a decentralized blockchain platform "
"that enables the creation of decentralized applications where every single interaction between a user and a d-app is verified by all the participants. Starknet is a Layer 2 built on "
-"top of Ethereum. Instead of having all the participants of the network to verify all user interactions, only one node, called the prover, execute the programs and generate proofs "
-"that the computations were done correctly.These proofs are then verified by an Ethereum smart contract, requiring significantly less computational power compared to executing the "
-"interactions themselves. This approach allows for increased throughput and reduced transaction costs but preserving Ethereum security."
+"top of Ethereum. Instead of having all the participants of the network to verify all user interactions, only one node, called the prover, executes the programs and generates proofs "
+"that the computations were done correctly. These proofs are then verified by an Ethereum smart contract, requiring significantly less computational power compared to executing the "
+"interactions themselves. This approach allows for increased throughput and reduced transaction costs while preserving Ethereum security."
msgstr ""
-"Cairo te permite calcular valores confiables en máquinas no confiables. Un caso de uso importante es Starknet, una solución para la escalabilidad de Ethereum. Ethereum es una "
-"plataforma blockchain descentralizada que permite la creación de aplicaciones descentralizadas donde cada interacción entre un usuario y una d-app es verificada por todos los "
-"participantes. Starknet es una capa 2 construida sobre Ethereum. En lugar de que todos los participantes de la red verifiquen todas las interacciones del usuario, solo un nodo, "
-"llamado el probador, ejecuta los programas y genera pruebas de que los cálculos se realizaron correctamente. Estas pruebas luego son verificadas por un contrato inteligente de "
-"Ethereum, lo que requiere significativamente menos potencia de cálculo en comparación con la ejecución de las interacciones mismas. Este enfoque permite un mayor rendimiento y una "
-"reducción en los costos de transacción, pero preservando la seguridad de Ethereum."
+"Cairo permite calcular valores confiables en máquinas no confiables. Un caso de uso importante es Starknet, una solución para escalar Ethereum. Ethereum es una plataforma de "
+"blockchain descentralizada que permite la creación de aplicaciones descentralizadas donde cada interacción entre un usuario y una dApp es verificada por todos los participantes. "
+"Starknet es una capa 2 construida sobre Ethereum. En lugar de requerir que todos los participantes de la red verifiquen todas las interacciones del usuario, solo un nodo, llamado "
+"probador (prover), ejecuta los programas y genera pruebas de que los cálculos se realizaron correctamente. Estas pruebas luego son verificadas por un contrato inteligente de "
+"Ethereum, lo que requiere significativamente menos potencia de cómputo en comparación con ejecutar las interacciones en sí mismas. Este enfoque permite aumentar la capacidad de "
+"procesamiento y reducir los costos de transacción, al tiempo que se preserva la seguridad de Ethereum."
#: src/ch00-00-introduction.md:12
msgid "## What are the differences with other programming languages?"
@@ -349,17 +361,18 @@ msgid ""
"- When the generated proof is verified by a verifier, it is a bit different. This has to be as cheap as possible since it could potentially be verified on many very small machines. "
"Fortunately verifying is faster than computing and Cairo has some unique advantages to improve it even more. A notable one is non-determinism. This is a topic you will cover in more "
"detail later in this book, but the idea is that you can theoretically use a different algorithm for verifying than for computing. Currently, writing custom non-deterministic code is "
-"not supported for the developers, but the standard library leverages non-determinism for improved performance. For example sorting an array in Cairo costs the same price than copying "
+"not supported for the developers, but the standard library leverages non-determinism for improved performance. For example sorting an array in Cairo costs the same price as copying "
"it. Because the verifier doesn't sort the array, it just checks that it is sorted, which is cheaper."
msgstr ""
-"- Cuando se ejecuta por el probador, es similar a cualquier otro lenguaje. Debido a que Cairo está virtualizado y porque las operaciones no se diseñaron específicamente para la "
-"máxima eficiencia, esto puede llevar a una sobrecarga de rendimiento, pero no es la parte más relevante para optimizar.\n"
+"- Cuando es ejecutado por el probador (prover), es similar a cualquier otro lenguaje. Debido a que Cairo es virtualizado y las operaciones no fueron diseñadas específicamente para "
+"obtener la máxima eficiencia, esto puede generar cierta sobrecarga de rendimiento, pero no es la parte más relevante para optimizar.\n"
"\n"
-"- Cuando el probador genera la prueba, es un poco diferente. Esto tiene que ser lo más barato posible, ya que potencialmente se podría verificar en muchas máquinas muy pequeñas. "
-"Afortunadamente, verificar es más rápido que computar y Cairo tiene algunas ventajas únicas para mejorar aún más. Uno notable es la no determinación. Este es un tema que cubrirás con "
-"más detalle más adelante en este libro, pero la idea es que teóricamente puedes usar un algoritmo diferente para verificar que para calcular. Actualmente, escribir código "
-"personalizado no determinista no está soportado para los desarrolladores, pero la biblioteca estándar aprovecha la no determinación para mejorar el rendimiento. Por ejemplo, ordenar "
-"una matriz en Cairo cuesta lo mismo que copiarla. Debido a que el verificador no ordena la matriz, simplemente verifica que está ordenada, lo que es más barato."
+"- Sin embargo, cuando la prueba generada es verificada por un verificador, es un poco diferente. Esto debe ser lo más económico posible, ya que potencialmente podría ser verificado "
+"en muchas máquinas muy pequeñas. Afortunadamente, la verificación es más rápida que el cálculo y Cairo tiene algunas ventajas únicas para mejorar aún más este proceso. Una notable es "
+"la no determinación. Este es un tema que se tratará con más detalle más adelante en este libro, pero la idea es que teóricamente puedes usar un algoritmo diferente para verificar que "
+"para calcular. Actualmente, no se admite la escritura de código no determinista personalizado para los desarrolladores, pero la biblioteca estándar aprovecha la no determinación para "
+"mejorar el rendimiento. Por ejemplo, ordenar un arreglo en Cairo tiene el mismo costo que copiarlo. Debido a que el verificador no ordena el arreglo, solo verifica que esté ordenado, "
+"lo cual es más barato."
#: src/ch00-00-introduction.md:20
msgid ""
@@ -427,9 +440,10 @@ msgid "### Install"
msgstr "### Instalación"
#: src/ch01-01-installation.md:20
-msgid "If you wish to install a specific release of Cairo rather than the latest head, set the `CAIRO_GIT_TAG` environment variable (e.g. `export CAIRO_GIT_TAG=v1.0.0`)."
+msgid "If you wish to install a specific release of Cairo rather than the latest head, set the `CAIRO_GIT_TAG` environment variable (e.g. `export CAIRO_GIT_TAG=v1.1.0`)."
msgstr ""
-"Si deseas instalar una versión específica de Cairo en lugar de la última versión, debes establecer la variable de entorno `CAIRO_GIT_TAG` (por ejemplo,`export CAIRO_GIT_TAG=v1.0.0`)."
+"Si deseas instalar una versión específica de Cairo en lugar de la última versión disponible, puedes establecer la variable de entorno `CAIRO_GIT_TAG` (por ejemplo, `export "
+"CAIRO_GIT_TAG=v1.1.0`)."
#: src/ch01-01-installation.md:22
msgid ""
@@ -709,7 +723,7 @@ msgid ""
"# View tags (you can also do this in the cairo compiler repository)\n"
"git describe --tags `git rev-list --tags`\n"
"# Checkout the version you want\n"
-"git checkout tags/v1.0.0\n"
+"git checkout tags/v1.1.0\n"
"\n"
"# Generate release binaries\n"
"cargo build --all --release\n"
@@ -731,7 +745,7 @@ msgstr ""
"# View tags (you can also do this in the cairo compiler repository)\n"
"git describe --tags `git rev-list --tags`\n"
"# Checkout the version you want\n"
-"git checkout tags/v1.0.0\n"
+"git checkout tags/v1.1.0\n"
"\n"
"# Generate release binaries\n"
"cargo build --all --release\n"
@@ -791,23 +805,30 @@ msgstr "#### Extensión VS Code"
#: src/ch01-01-installation.md:188
msgid ""
-"- Disable previous Cairo 0.x extension\n"
-"- Install the Cairo 1 extension for proper syntax highlighting and code navigation.\n"
-" Just follow the steps indicated [here](https://github.com/starkware-libs/cairo/blob/main/vscode-cairo/README.md)."
+"- If you have the previous Cairo 0 extension installed, you can disable/uninstall it.\n"
+"- Install the Cairo 1 extension for proper syntax highlighting and code navigation. You can find the link to the extension [here](https://marketplace.visualstudio.com/items?"
+"itemName=starkware.cairo1&ssr=false), or just search for \"Cairo 1.0\" in the VS Code marketplace.\n"
+"- The extension will work out of the box once you will have [Scarb](./ch01-03-hello-scarb.md) installed."
msgstr ""
-"- Deshabilite la extensión anterior Cairo 0.x\n"
-"- Instale la extensión Cairo 1 para un correcto resaltado de sintaxis y navegación por el código.\n"
-" Simplemente siga los pasos indicados [aquí](https://github.com/starkware-libs/cairo/blob/main/vscode-cairo/README.md)."
+"- Si tienes instalada la extensión anterior de Cairo 0, puedes desactivarla/desinstalarla.\n"
+"- Instala la extensión de Cairo 1 para tener resaltado de sintaxis y navegación de código adecuados. Puedes encontrar el enlace a la extensión [aquí](https://marketplace.visualstudio."
+"com/items?itemName=starkware.cairo1&ssr=false), o simplemente busca \"Cairo 1.0\" en el marketplace de VS Code.\n"
+"- La extensión funcionará automáticamente una vez que tengas instalado [Scarb](./ch01-03-hello-scarb.md)."
#: src/ch01-01-installation.md:192
-msgid "#### Cairo Language Server"
-msgstr "#### Servidor de Lenguaje de Cairo"
+msgid "#### Cairo Language Server without Scarb"
+msgstr "#### Servidor de Lenguaje con Scarb"
#: src/ch01-01-installation.md:194
-msgid "From [Step 1](#step-1-install-cairo-10-guide-by-abdel), the `cairo-language-server` binary should be built and executing this command will copy its path into your clipboard."
-msgstr "Desde [Paso 1](#step-1-install-cairo-10-guide-by-abdel), el binario `cairo-language-server` debe ser construido y ejecutando este comando se copiará su ruta en el portapapeles."
+msgid ""
+"If you don't want to depend on Scarb, you can still use the Cairo Language Server with the compiler binary.\n"
+"From [Step 1](#installing-cairo-with-a-script-installer-by-fran), the `cairo-language-server` binary should be built and executing this command will copy its path into your clipboard."
+msgstr ""
+"Si no deseas depender de Scarb, aún puedes usar el Cairo Language Server con el binario del compilador.\n"
+"A partir del [Paso 1](#installing-cairo-with-a-script-installer-by-fran), el binario `cairo-language-server` debería haber sido construido y ejecutar este comando copiará su ruta en "
+"tu portapapeles."
-#: src/ch01-01-installation.md:196
+#: src/ch01-01-installation.md:197
msgid ""
"```bash\n"
"which cairo-language-server | pbcopy\n"
@@ -817,9 +838,9 @@ msgstr ""
"which cairo-language-server | pbcopy\n"
"```"
-#: src/ch01-01-installation.md:200
-msgid "Update the `languageServerPath` of the Cairo 1.0 extension by pasting the path."
-msgstr "Actualiza el `languageServerPath` de la extensión Cairo 1.0 pegando la ruta."
+#: src/ch01-01-installation.md:201
+msgid "Update the `cairo1.languageServerPath` of the Cairo 1.0 extension by pasting the path."
+msgstr "Actualiza la `cairo1.languageServerPath` de la extensión Cairo 1.0 pegando la ruta."
#: src/ch01-02-hello-world.md:1
msgid "## Hello, World"
@@ -842,15 +863,15 @@ msgid ""
"> if you prefer to use an integrated development environment (IDE) instead of\n"
"> the command line, feel free to use your favorite IDE. The Cairo team has developed\n"
"> a VSCode extension for the Cairo language that you can use to get the features from\n"
-"> the language server and code highlighting. See [Appendix B][devtools]\n"
+"> the language server and code highlighting. See [Appendix D][devtools]\n"
"> for more details."
msgstr ""
"> Nota: Este libro asume una familiaridad básica con la línea de comandos. Cairo no hace\n"
"> ninguna demanda específica sobre su edición o herramientas o donde vive su código, así que\n"
-"> si prefiere usar un entorno de desarrollo integrado (IDE) en lugar de la línea de comandos, > siéntase libre de hacerlo.\n"
+"si prefiere usar un entorno de desarrollo integrado (IDE) en lugar de la línea de comandos, > siéntase libre de usar su IDE favorito.\n"
"> la línea de comandos, siéntase libre de usar su IDE favorito. El equipo de Cairo ha desarrollado\n"
"> una extensión VSCode para el lenguaje Cairo que puedes usar para obtener las características de\n"
-"> el servidor de lenguajes y el resaltado de código. Ver [Apéndice A][devtools]\n"
+"> el servidor de lenguajes y el resaltado de código. Ver [Apéndice D][devtools]\n"
"> para más detalles."
#: src/ch01-02-hello-world.md:15
@@ -1013,13 +1034,13 @@ msgstr ""
#: src/ch01-02-hello-world.md:83
msgid ""
-"```rust\n"
+"```rust,ignore_format\n"
"fn main() {\n"
"\n"
"}\n"
"```"
msgstr ""
-"```rust\n"
+"```rust,ignore_format\n"
"fn main() {\n"
"\n"
"}\n"
@@ -1052,14 +1073,14 @@ msgid ""
"> Note: If you want to stick to a standard style across Cairo projects, you can\n"
"> use the automatic formatter tool called `cairo-format` to format your code in a\n"
"> particular style (more on `cairo-format` in\n"
-"> [Appendix B][devtools]). The Cairo team has included this tool\n"
+"> [Appendix D][devtools]). The Cairo team has included this tool\n"
"> with the standard Cairo distribution, as `cairo-run` is, so it should already be\n"
"> installed on your computer!"
msgstr ""
-"> Nota: Si quieres mantener un estilo estándar en todos los proyectos de Cairo, puedes\n"
-"> usar la herramienta de formateo automático llamada `cairo-format` para formatear tu código \n"
-"> en un estilo particular (más sobre `cairo-format` en\n"
-"> [Apéndice A][devtools]). El equipo de Cairo ha incluido esta herramienta\n"
+"> Nota: Si quieres mantener un estilo estándar en todos los proyectos de El Cairo, puedes\n"
+"> usar la herramienta de formateo automático llamada `cairo-format` para formatear tu código en un\n"
+"> estilo particular (más sobre `cairo-format` en\n"
+"> [Apéndice D][devtools]). El equipo de Cairo ha incluido esta herramienta\n"
"> con la distribución estándar de Cairo, como lo es `cairo-run`, así que ya debería estar\n"
"> ¡instalada en tu ordenador!"
@@ -1147,10 +1168,11 @@ msgstr "Scarb es el gestor de paquetes de Cairo y está fuertemente inspirado en
#: src/ch01-03-hello-scarb.md:5
msgid ""
-"Scarb handles a lot of tasks for you, such as building your code (either pure Cairo or Starknet contracts), downloading the libraries your code depends on, and building those "
-"libraries."
+"Scarb handles a lot of tasks for you, such as building your code (either pure Cairo or Starknet contracts), downloading the libraries your code depends on, building those libraries, "
+"and provides LSP support for the VSCode Cairo 1 extension."
msgstr ""
-"Scarb maneja muchas tareas por ti, como construir tu código (ya sea Cairo puro o contratos Starknet), descargar las librerías de las que depende tu código, y construir esas librerías."
+"Scarb se encarga de muchas tareas por ti, como construir tu código (ya sea en Cairo puro o contratos Starknet), descargar las bibliotecas en las que tu código depende, construir esas "
+"bibliotecas y proporcionar soporte LSP (Language Server Protocol) para la extensión de Cairo 1 en VSCode."
#: src/ch01-03-hello-scarb.md:7
msgid ""
@@ -1182,58 +1204,54 @@ msgid "### Installation"
msgstr "### Instalación"
#: src/ch01-03-hello-scarb.md:19
-msgid "As for now, Scarb needs manual installation with the following steps:"
-msgstr "Por ahora, Scarb necesita instalación manual con los siguientes pasos:"
+msgid ""
+"To install Scarb, please refer to the [installation instructions](https://docs.swmansion.com/scarb/download.html).\n"
+"You can simply run the following command in your terminal, then follow the onscreen instructions. This will install the latest stable release."
+msgstr ""
+"Para instalar Scarb, por favor consulta las [instrucciones de instalación](https://docs.swmansion.com/scarb/docs/install.html).\n"
+"Simplemente ejecuta el siguiente comando en tu terminal y sigue las instrucciones en pantalla. Esto instalará la última versión estable."
-#: src/ch01-03-hello-scarb.md:21
+#: src/ch01-03-hello-scarb.md:22
+msgid ""
+"```bash\n"
+"curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh\n"
+"```"
+msgstr ""
+"```bash\n"
+"curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh\n"
+"```"
+
+#: src/ch01-03-hello-scarb.md:26
msgid ""
-"- Download the release archive matching your operating system and CPU architecture, from [Scarb releases on GitHub](https://github.com/software-mansion/scarb/releases)\n"
-"- Extract it to a location where you would like to have Scarb installed, e.g. `~/scarb`\n"
-"- Add path to the `scarb/bin` directory to your `PATH` environment variable.\n"
-"\n"
-" This depend on what shell you are using. Let’s take the example of [zsh](https://ohmyz.sh/) and you have extracted Scarb to `~/scarb`:\n"
-"\n"
-" - Open `~/.zshrc` file in your favorite editor\n"
-" - Add the following line to the end of the file: `export PATH=\"$PATH:~/scarb/bin\"`\n"
-"\n"
"- Verify installation by running the following command in new terminal session, it should print both Scarb and Cairo language versions, e.g:\n"
"\n"
" ```bash\n"
" $ scarb --version\n"
-" scarb 0.1.0 (289137c24 2023-03-28)\n"
-" cairo: 1.0.0-alpha.6\n"
+" scarb 0.4.0 (f813517bf 2023-06-06)\n"
+" cairo: 1.1.0 (43b83560d)\n"
" ```"
msgstr ""
-"- Descargue el archivo de versiones correspondiente a su sistema operativo y arquitectura de CPU desde [Scarb releases on GitHub](https://github.com/software-mansion/scarb/releases)\n"
-"- Extráigalo a una ubicación en la que desee tener Scarb instalado, por ejemplo. `~/scarb`\n"
-"- Añada la ruta al directorio `scarb/bin` a su variable de entorno `PATH`.\n"
-"\n"
-" Esto depende del shell que esté utilizando. Tomemos el ejemplo de [zsh](https://ohmyz.sh/) y has extraido Scarb a `~/scarb`:\n"
-"\n"
-" - Abra el archivo `~/.zshrc` en su editor favorito\n"
-" - Añada la siguiente línea al final del archivo: `export PATH=\"$PATH:~/scarb/bin\"`\n"
-"\n"
-"- Verifique la instalación ejecutando el siguiente comando en una nueva sesión de terminal, debería imprimir las versiones en Scarb y Cairo, por ejemplo:\n"
+"- Verify installation by running the following command in new terminal session, it should print both Scarb and Cairo language versions, e.g:\n"
"\n"
" ```bash\n"
" $ scarb --version\n"
-" scarb 0.1.0 (289137c24 2023-03-28)\n"
-" cairo: 1.0.0-alpha.6\n"
+" scarb 0.4.0 (f813517bf 2023-06-06)\n"
+" cairo: 1.1.0 (43b83560d)\n"
" ```"
-#: src/ch01-03-hello-scarb.md:38
+#: src/ch01-03-hello-scarb.md:34
msgid "### Creating a Project with Scarb"
msgstr "### Creando un Proyecto con Scarb"
-#: src/ch01-03-hello-scarb.md:40
+#: src/ch01-03-hello-scarb.md:36
msgid "Let’s create a new project using Scarb and look at how it differs from our original “Hello, world!” project."
msgstr "Vamos a crear un nuevo proyecto utilizando Scarb y ver en qué se diferencia de nuestro proyecto original “Hello, world!”."
-#: src/ch01-03-hello-scarb.md:42
+#: src/ch01-03-hello-scarb.md:38
msgid "Navigate back to your projects directory (or wherever you decided to store your code). Then run the following:"
msgstr "Navegue de nuevo a su directorio de proyectos (o donde haya decidido almacenar su código). Luego ejecute lo siguiente:"
-#: src/ch01-03-hello-scarb.md:44
+#: src/ch01-03-hello-scarb.md:40
msgid ""
"```bash\n"
"$ scarb new hello_scarb\n"
@@ -1243,11 +1261,11 @@ msgstr ""
"$ scarb new hello_scarb\n"
"```"
-#: src/ch01-03-hello-scarb.md:48
+#: src/ch01-03-hello-scarb.md:44
msgid "It creates a new directory and project called hello_scarb. We’ve named our project hello_scarb, and Scarb creates its files in a directory of the same name."
msgstr "Crea un nuevo directorio y proyecto llamado hello_scarb. Hemos llamado a nuestro proyecto hello_scarb, y Scarb crea sus archivos en un directorio con el mismo nombre."
-#: src/ch01-03-hello-scarb.md:50
+#: src/ch01-03-hello-scarb.md:46
msgid ""
"Go into the hello_scarb directory with the command `cd hello_scarb`. You’ll see that Scarb has generated two files and one directory for us: a `Scarb.toml` file and a src directory "
"with a `lib.cairo` file inside."
@@ -1255,11 +1273,11 @@ msgstr ""
"Entre en el directorio hello_scarb con el comando `cd hello_scarb`.Verás que Scarb ha generado dos archivos y un directorio para nosotros: un archivo `Scarb.toml` y un directorio src "
"con un archivo `lib.cairo` dentro."
-#: src/ch01-03-hello-scarb.md:52
+#: src/ch01-03-hello-scarb.md:48
msgid "It has also initialized a new Git repository along with a `.gitignore` file"
msgstr "También ha inicializado un nuevo repositorio Git junto con un archivo `.gitignore`"
-#: src/ch01-03-hello-scarb.md:54
+#: src/ch01-03-hello-scarb.md:50
msgid ""
"> Note: Git is a common version control system. You can stop using version control system by using the `--vcs` flag.\n"
"> Run `scarb new -help` to see the available options."
@@ -1268,22 +1286,22 @@ msgstr ""
"> usando la bandera `--vcs`.\n"
"> Ejecute `scarb new -help` para ver las opciones disponibles."
-#: src/ch01-03-hello-scarb.md:57
+#: src/ch01-03-hello-scarb.md:53
msgid "Open _Scarb.toml_ in your text editor of choice. It should look similar to the code in Listing 1-2."
msgstr "Abra _Scarb.toml_ en su editor de texto preferido. Debería parecerse al código del Listado 1-2."
-#: src/ch01-03-hello-scarb.md:59
+#: src/ch01-03-hello-scarb.md:55
msgid "Filename: Scarb.toml"
msgstr "Filename: Scarb.toml"
-#: src/ch01-03-hello-scarb.md:61
+#: src/ch01-03-hello-scarb.md:57
msgid ""
"```toml\n"
"[package]\n"
"name = \"hello_scarb\"\n"
"version = \"0.1.0\"\n"
"\n"
-"# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest\n"
+"# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html\n"
"\n"
"[dependencies]\n"
"# foo = { path = \"vendor/foo\" }\n"
@@ -1294,21 +1312,21 @@ msgstr ""
"name = \"hello_scarb\"\n"
"version = \"0.1.0\"\n"
"\n"
-"# Vea más claves y sus definiciones en https://docs.swmansion.com/scarb/docs/reference/manifest\n"
+"# Vea más claves y sus definiciones en https://docs.swmansion.com/scarb/docs/reference/manifest.html\n"
"\n"
"[dependencies]\n"
"# foo = { path = \"vendor/foo\" }\n"
"```"
-#: src/ch01-03-hello-scarb.md:72
+#: src/ch01-03-hello-scarb.md:68
msgid "Listing 1-2: Contents of Scarb.toml generated by `scarb new`"
msgstr "Listing 1-2: Contents of Scarb.toml generated by `scarb new`"
-#: src/ch01-03-hello-scarb.md:74
+#: src/ch01-03-hello-scarb.md:70
msgid "This file is in the [TOML](https://toml.io/) (Tom’s Obvious, Minimal Language) format, which is Scarb’s configuration format."
msgstr "Este archivo se encuentra en formato [TOML](https://toml.io/) (Tom’s Obvious, Minimal Language), que es el formato de configuración de Scarb."
-#: src/ch01-03-hello-scarb.md:76
+#: src/ch01-03-hello-scarb.md:72
msgid ""
"The first line, `[package]`, is a section heading that indicates that the following statements are configuring a package. As we add more information to this file, we’ll add other "
"sections."
@@ -1316,11 +1334,11 @@ msgstr ""
"La primera línea, `[package]`, es un encabezado de sección que indica que las siguientes sentencias están configurando un paquete. A medida que agreguemos más información a este "
"archivo, agregaremos otras secciones."
-#: src/ch01-03-hello-scarb.md:78
+#: src/ch01-03-hello-scarb.md:74
msgid "The next two lines set the configuration information Scarb needs to compile your program: the name and the version of Scarb to use."
msgstr "Las siguientes dos líneas establecen la información de configuración que Scarb necesita para compilar su programa: el nombre y la versión de Scarb a utilizar."
-#: src/ch01-03-hello-scarb.md:80
+#: src/ch01-03-hello-scarb.md:76
msgid ""
"The last line, `[dependencies]`, is the start of a section for you to list any of your project’s dependencies. In Cairo, packages of code are referred to as crates. We won’t need any "
"other crates for this project."
@@ -1328,11 +1346,19 @@ msgstr ""
"La última línea, `[dependencies]`, es el comienzo de una sección para que puedas listar cualquiera de las dependencias de tu proyecto. En Cairo, los paquetes de código se conocen "
"como crates. No necesitaremos ninguna otra crate para este proyecto."
-#: src/ch01-03-hello-scarb.md:82
+#: src/ch01-03-hello-scarb.md:78
+msgid ""
+"> Note: If you're building contracts for Starknet, you will need to add the `starknet` dependency as mentioned in the [Scarb documentation](https://docs.swmansion.com/scarb/docs/"
+"starknet/starknet-package.html)."
+msgstr ""
+"> Nota: Si estás construyendo contratos para Starknet, deberás agregar la dependencia `starknet` como se menciona en la [documentación de Scarb](https://docs.swmansion.com/scarb/docs/"
+"starknet/starknet-package.html)."
+
+#: src/ch01-03-hello-scarb.md:80
msgid "The other file created by Scarb is `src/lib.cairo`, let's delete all the content and put in the following content, we will explain the reason later."
msgstr "El otro archivo creado por Scarb es `src/lib.cairo`, borremos todo el contenido y pongamos el siguiente contenido, explicaremos la razón más adelante."
-#: src/ch01-03-hello-scarb.md:84
+#: src/ch01-03-hello-scarb.md:82
msgid ""
"```rust\n"
"mod hello_scarb;\n"
@@ -1342,15 +1368,15 @@ msgstr ""
"mod hello_scarb;\n"
"```"
-#: src/ch01-03-hello-scarb.md:88
+#: src/ch01-03-hello-scarb.md:86
msgid "Then create a new file called `src/hello_scarb.cairo` and put the following code in it:"
msgstr "A continuación, cree un nuevo archivo llamado `src/hello_scarb.cairo` y ponle el siguiente código:"
-#: src/ch01-03-hello-scarb.md:90
+#: src/ch01-03-hello-scarb.md:88
msgid "Filename: src/hello_scarb.cairo"
msgstr "Filename: src/hello_scarb.cairo"
-#: src/ch01-03-hello-scarb.md:92
+#: src/ch01-03-hello-scarb.md:90
msgid ""
"```rust,file=hello_scarb.cairo\n"
"use debug::PrintTrait;\n"
@@ -1366,19 +1392,19 @@ msgstr ""
"}\n"
"```"
-#: src/ch01-03-hello-scarb.md:99
+#: src/ch01-03-hello-scarb.md:97
msgid ""
-"We have just created a file called `lib.cairo`, which contains a module declaration referencing another module named \"hello_scarb\", as well as the file `hello_scarb.cairo`,"
+"We have just created a file called `lib.cairo`, which contains a module declaration referencing another module named \"hello_scarb\", as well as the file `hello_scarb.cairo`, "
"containing the implementation details of the \"hello_scarb\" module."
msgstr ""
"Acabamos de crear un archivo llamado `lib.cairo`, que contiene una declaración de módulo que hace referencia a otro módulo llamado \"hello_scarb\", así como el archivo `hello_scarb."
"cairo`, que contiene los detalles de implementación del módulo \"hello_scarb\"."
-#: src/ch01-03-hello-scarb.md:101
+#: src/ch01-03-hello-scarb.md:99
msgid "Scarb requires your source files to be located within the src directory."
msgstr "Scarb requiere que sus archivos fuente se encuentren dentro del directorio src."
-#: src/ch01-03-hello-scarb.md:103
+#: src/ch01-03-hello-scarb.md:101
msgid ""
"The top-level project directory is reserved for README files, license information, configuration files, and any other non-code-related content.\n"
"Scarb ensures a designated location for all project components, maintaining a structured organization."
@@ -1387,7 +1413,7 @@ msgstr ""
"otro contenido no relacionado con el código.\n"
"Scarb asegura una ubicación designada para todos los componentes del proyecto, manteniendo una organización estructurada."
-#: src/ch01-03-hello-scarb.md:106
+#: src/ch01-03-hello-scarb.md:104
msgid ""
"If you started a project that doesn’t use Scarb, as we did with the “Hello, world!” project, you can convert it to a project that does use Scarb. Move the project code into the src "
"directory and create an appropriate `Scarb.toml` file."
@@ -1395,15 +1421,15 @@ msgstr ""
"Si ha iniciado un proyecto que no utiliza Scarb, como hicimos con el proyecto “Hello, world!”, puede convertirlo en un proyecto que utilice Scarb. Mueva el código del proyecto al "
"directorio src y cree un archivo `Scarb.toml` apropiado."
-#: src/ch01-03-hello-scarb.md:108
+#: src/ch01-03-hello-scarb.md:106
msgid "### Building a Scarb Project"
msgstr "### Creación de un proyecto Scarb"
-#: src/ch01-03-hello-scarb.md:110
+#: src/ch01-03-hello-scarb.md:108
msgid "From your hello_scarb directory, build your project by entering the following command:"
msgstr "Desde su directorio hello_scarb, construya su proyecto introduciendo el siguiente comando:"
-#: src/ch01-03-hello-scarb.md:112
+#: src/ch01-03-hello-scarb.md:110
msgid ""
"```bash\n"
"$ scarb build\n"
@@ -1417,15 +1443,15 @@ msgstr ""
" Finished release target(s) in 0 seconds\n"
"```"
-#: src/ch01-03-hello-scarb.md:118
+#: src/ch01-03-hello-scarb.md:116
msgid "This command creates a `sierra` file in `target/release`, let's ignore the `sierra` file for now."
msgstr "Este comando crea un archivo `sierra` en `target/release`, ignoremos el archivo `sierra` por ahora."
-#: src/ch01-03-hello-scarb.md:120
+#: src/ch01-03-hello-scarb.md:118
msgid "If you have installed Cairo correctly, you should be able to run and see the following output:"
msgstr "Si has instalado Cairo correctamente, deberías ser capaz de ejecutarlo y ver la siguiente salida:"
-#: src/ch01-03-hello-scarb.md:122
+#: src/ch01-03-hello-scarb.md:120
msgid ""
"```bash\n"
"$ cairo-run src/lib.cairo\n"
@@ -1441,7 +1467,7 @@ msgstr ""
"Run completed successfully, returning []\n"
"```"
-#: src/ch01-03-hello-scarb.md:129
+#: src/ch01-03-hello-scarb.md:127
msgid ""
"> Note: You will notice here that we didn't use a Scarb command, but rather a command from the Cairo binaries directly.\n"
"> As Scarb doesn't have a command to execute Cairo code yet, we have to use the `cairo-run` command directly.\n"
@@ -1451,11 +1477,11 @@ msgstr ""
"> Como Scarb no tiene un comando para ejecutar código de Cairo, tenemos que usar el comando `cairo-run` directamente.\n"
"> Usaremos este comando en el resto del tutorial, pero también usaremos comandos de Scarb para inicializar proyectos."
-#: src/ch01-03-hello-scarb.md:133
+#: src/ch01-03-hello-scarb.md:131
msgid "### Defining Custom Scripts"
msgstr "### Definición de scripts personalizados"
-#: src/ch01-03-hello-scarb.md:135
+#: src/ch01-03-hello-scarb.md:133
msgid ""
"We can define Scarb scripts in `Scarb.toml` file, which can be used to execute custom shell scripts.\n"
"Add the following line to your `Scarb.toml` file:"
@@ -1463,7 +1489,7 @@ msgstr ""
"Podemos definir scripts scarb en el archivo `Scarb.toml`, que puede ser usado para ejecutar scripts shell personalizados.\n"
"Añada la siguiente línea a su fichero `Scarb.toml`:"
-#: src/ch01-03-hello-scarb.md:138
+#: src/ch01-03-hello-scarb.md:136
msgid ""
"```toml\n"
"[scripts]\n"
@@ -1475,11 +1501,11 @@ msgstr ""
"run-lib = \"cairo-run src/lib.cairo\"\n"
"```"
-#: src/ch01-03-hello-scarb.md:143
+#: src/ch01-03-hello-scarb.md:141
msgid "Now you can run the following command to run the project:"
msgstr "Ahora puede ejecutar el siguiente comando para ejecutar el proyecto:"
-#: src/ch01-03-hello-scarb.md:145
+#: src/ch01-03-hello-scarb.md:143
msgid ""
"```bash\n"
"$ scarb run run-lib\n"
@@ -1495,15 +1521,15 @@ msgstr ""
"Run completed successfully, returning []\n"
"```"
-#: src/ch01-03-hello-scarb.md:152
+#: src/ch01-03-hello-scarb.md:150
msgid "Using `scarb run` is a convenient way to run custom shell scripts that can be useful to run files and test your project."
msgstr "Usar `scarb run` es una forma conveniente de ejecutar scripts de shell personalizados que pueden ser útiles para ejecutar archivos y probar su proyecto."
-#: src/ch01-03-hello-scarb.md:154
+#: src/ch01-03-hello-scarb.md:152
msgid "Let’s recap what we’ve learned so far about Scarb:"
msgstr "Recapitulemos lo que hemos aprendido hasta ahora sobre Scarb:"
-#: src/ch01-03-hello-scarb.md:156
+#: src/ch01-03-hello-scarb.md:154
msgid ""
"- We can create a project using `scarb new`.\n"
"- We can build a project using `scarb build` to generate the compiled Sierra code.\n"
@@ -1513,7 +1539,7 @@ msgstr ""
"- Podemos construir un proyecto usando `scarb build` para generar el código Sierra compilado.\n"
"- Podemos definir scripts personalizados en `Scarb.toml` y llamarlos con el comando `scarb run`."
-#: src/ch01-03-hello-scarb.md:160
+#: src/ch01-03-hello-scarb.md:158
msgid ""
"An additional advantage of using Scarb is that the commands are the same no matter which operating system you’re working on. So, at this point, we’ll no longer provide specific "
"instructions for Linux and macOS versus Windows."
@@ -1521,15 +1547,15 @@ msgstr ""
"Una ventaja adicional de usar Scarb es que los comandos son los mismos sin importar el sistema operativo en el que estemos trabajando. Así que, en este punto, ya no proporcionaremos "
"instrucciones específicas para Linux y macOS frente a Windows."
-#: src/ch01-03-hello-scarb.md:162
+#: src/ch01-03-hello-scarb.md:160
msgid "# Summary"
msgstr "# Resumen"
-#: src/ch01-03-hello-scarb.md:164
+#: src/ch01-03-hello-scarb.md:162
msgid "You’re already off to a great start on your Cairo journey! In this chapter, you’ve learned how to:"
msgstr "Ya has empezado con buen pie tu viaje en Cairo. En este capítulo, has aprendido cómo:"
-#: src/ch01-03-hello-scarb.md:166
+#: src/ch01-03-hello-scarb.md:164
msgid ""
"- Install the latest stable version of Cairo\n"
"- Write and run a “Hello, world!” program using `cairo-run` directly\n"
@@ -1539,7 +1565,7 @@ msgstr ""
"- Escribir y ejecutar un programa \" Hello, world!\" usando `cairo-run` directamente\n"
"- Crear y ejecutar un nuevo proyecto usando las convenciones de Scarb"
-#: src/ch01-03-hello-scarb.md:170
+#: src/ch01-03-hello-scarb.md:168
msgid "This is a great time to build a more substantial program to get used to reading and writing Cairo code."
msgstr "Este es un buen momento para construir un programa más sustancial para acostumbrarte a leer y escribir código de Cairo."
@@ -1602,16 +1628,16 @@ msgstr ""
"A continuación, en su nuevo directorio _variables_, abra _src/lib.cairo_ y sustituya \n"
"su código por el siguiente, que todavía no compilará:"
-#: src/ch02-01-variables-and-mutability.md:17 src/ch02-01-variables-and-mutability.md:76 src/ch02-01-variables-and-mutability.md:154 src/ch02-05-control-flow.md:130
-#: src/ch03-02-references-and-snapshots.md:23 src/ch03-02-references-and-snapshots.md:111 src/ch04-02-an-example-program-using-structs.md:7
-#: src/ch04-02-an-example-program-using-structs.md:48 src/ch04-02-an-example-program-using-structs.md:74 src/ch04-02-an-example-program-using-structs.md:106
-#: src/ch04-02-an-example-program-using-structs.md:142 src/ch04-03-method-syntax.md:18 src/ch04-03-method-syntax.md:93 src/ch04-03-method-syntax.md:135 src/ch04-03-method-syntax.md:192
-#: src/ch04-03-method-syntax.md:231 src/ch06-02-defining-modules-to-control-scope.md:90 src/ch06-02-defining-modules-to-control-scope.md:144
+#: src/ch02-01-variables-and-mutability.md:17 src/ch02-01-variables-and-mutability.md:77 src/ch02-01-variables-and-mutability.md:155 src/ch02-05-control-flow.md:130
+#: src/ch03-02-references-and-snapshots.md:23 src/ch03-02-references-and-snapshots.md:130 src/ch04-02-an-example-program-using-structs.md:7
+#: src/ch04-02-an-example-program-using-structs.md:48 src/ch04-02-an-example-program-using-structs.md:74 src/ch04-02-an-example-program-using-structs.md:103
+#: src/ch04-02-an-example-program-using-structs.md:136 src/ch04-03-method-syntax.md:18 src/ch04-03-method-syntax.md:93 src/ch04-03-method-syntax.md:135 src/ch04-03-method-syntax.md:192
+#: src/ch04-03-method-syntax.md:231 src/ch06-02-defining-modules-to-control-scope.md:90 src/ch06-02-defining-modules-to-control-scope.md:143
#: src/ch06-03-paths-for-referring-to-an-item-in-the-module-tree.md:15 src/ch06-03-paths-for-referring-to-an-item-in-the-module-tree.md:62
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:10 src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:35
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:74 src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:131
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:156 src/ch06-05-separating-modules-into-different-files.md:18 src/ch08-01-how-to-write-tests.md:426
-#: src/ch08-01-how-to-write-tests.md:464
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:10 src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:36
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:76 src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:132
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:206 src/ch06-05-separating-modules-into-different-files.md:18 src/ch08-01-how-to-write-tests.md:512
+#: src/ch08-01-how-to-write-tests.md:550
msgid "Filename: src/lib.cairo"
msgstr "Filename: src/lib.cairo"
@@ -1625,6 +1651,7 @@ msgid ""
" x = 6;\n"
" x.print();\n"
"}\n"
+"\n"
"```"
msgstr ""
"```rust,does_not_compile\n"
@@ -1635,9 +1662,10 @@ msgstr ""
" x = 6;\n"
" x.print();\n"
"}\n"
+"\n"
"```"
-#: src/ch02-01-variables-and-mutability.md:29
+#: src/ch02-01-variables-and-mutability.md:30
msgid ""
"Save and run the program using `cairo-run src/lib.cairo`. You should receive an error message\n"
"regarding an immutability error, as shown in this output:"
@@ -1645,7 +1673,7 @@ msgstr ""
"Guarde y ejecute el programa utilizando `cairo-run src/lib.cairo`. Debería recibir un mensaje \n"
"de error relativo a un error de inmutabilidad, como se muestra en esta salida:"
-#: src/ch02-01-variables-and-mutability.md:32
+#: src/ch02-01-variables-and-mutability.md:33
msgid ""
"```console\n"
"error: Cannot assign to an immutable variable.\n"
@@ -1665,7 +1693,7 @@ msgstr ""
"Error: failed to compile: src/lib.cairo\n"
"```"
-#: src/ch02-01-variables-and-mutability.md:41
+#: src/ch02-01-variables-and-mutability.md:42
msgid ""
"This example shows how the compiler helps you find errors in your programs.\n"
"Compiler errors can be frustrating, but really they only mean your program\n"
@@ -1678,7 +1706,7 @@ msgstr ""
"quiere que haga; ¡no significan que usted no sea un buen programador! Los Caironautas \n"
"experimentados siguen teniendo errores de compilador."
-#: src/ch02-01-variables-and-mutability.md:46
+#: src/ch02-01-variables-and-mutability.md:47
msgid ""
"You received the error message `Cannot assign to an immutable variable.`\n"
"because you tried to assign a second value to the immutable `x` variable."
@@ -1686,7 +1714,7 @@ msgstr ""
"Recibiste el mensaje de error `Cannot assign to an immutable variable.` porque \n"
"intentaste asignar un segundo valor a la variable inmutable `x`."
-#: src/ch02-01-variables-and-mutability.md:49
+#: src/ch02-01-variables-and-mutability.md:50
msgid ""
"It’s important that we get compile-time errors when we attempt to change a\n"
"value that’s designated as immutable because this specific situation can lead to\n"
@@ -1709,7 +1737,7 @@ msgstr ""
"cuando dices que un valor no cambiará, realmente no cambiará, por lo que no tiene que hacer \n"
"un seguimiento. Su código es así más fácil de razonar."
-#: src/ch02-01-variables-and-mutability.md:60
+#: src/ch02-01-variables-and-mutability.md:61
msgid ""
"But mutability can be very useful, and can make code more convenient to write.\n"
"Although variables are immutable by default, you can make them mutable by\n"
@@ -1723,7 +1751,7 @@ msgstr ""
"intención a los futuros lectores del código indicando que otras partes del código \n"
"cambiarán el valor de esta variable."
-#: src/ch02-01-variables-and-mutability.md:66
+#: src/ch02-01-variables-and-mutability.md:67
msgid ""
"However, you might be wondering at this point what exactly happens when a variable\n"
"is declared as `mut`, as we previously mentioned that Cairo's memory is immutable.\n"
@@ -1743,11 +1771,11 @@ msgstr ""
"de variables. La única diferencia es que en el nivel la variable no se vuelve a declarar, por lo \n"
"que su tipo no puede cambiar."
-#: src/ch02-01-variables-and-mutability.md:74
+#: src/ch02-01-variables-and-mutability.md:75
msgid "For example, let’s change _src/lib.cairo_ to the following:"
msgstr "Por ejemplo, cambiemos _src/lib.cairo_ por lo siguiente:"
-#: src/ch02-01-variables-and-mutability.md:78
+#: src/ch02-01-variables-and-mutability.md:79
msgid ""
"```rust\n"
"use debug::PrintTrait;\n"
@@ -1769,11 +1797,11 @@ msgstr ""
"}\n"
"```"
-#: src/ch02-01-variables-and-mutability.md:88
+#: src/ch02-01-variables-and-mutability.md:89
msgid "When we run the program now, we get this:"
msgstr "Cuando ejecutamos el programa ahora, obtenemos esto:"
-#: src/ch02-01-variables-and-mutability.md:90
+#: src/ch02-01-variables-and-mutability.md:91
msgid ""
"```console\n"
"❯ cairo-run src/lib.cairo\n"
@@ -1793,7 +1821,7 @@ msgstr ""
"Run completed successfully, returning []\n"
"```"
-#: src/ch02-01-variables-and-mutability.md:99
+#: src/ch02-01-variables-and-mutability.md:100
msgid ""
"We’re allowed to change the value bound to `x` from `5` to `6` when `mut` is\n"
"used. Ultimately, deciding whether to use mutability or not is up to you and\n"
@@ -1803,11 +1831,11 @@ msgstr ""
"En última instancia, la decisión de utilizar la mutabilidad o no es suya y depende \n"
"de lo que usted piensa que es más claro en esa situación particular."
-#: src/ch02-01-variables-and-mutability.md:103
+#: src/ch02-01-variables-and-mutability.md:104
msgid "### Constants"
msgstr "##### Constantes"
-#: src/ch02-01-variables-and-mutability.md:105
+#: src/ch02-01-variables-and-mutability.md:106
msgid ""
"Like immutable variables, _constants_ are values that are bound to a name and\n"
"are not allowed to change, but there are a few differences between constants\n"
@@ -1817,7 +1845,7 @@ msgstr ""
" vinculados a un nombre y no se les permite cambiar, pero hay algunas diferencias \n"
"entre las constantes y las variables."
-#: src/ch02-01-variables-and-mutability.md:109
+#: src/ch02-01-variables-and-mutability.md:110
msgid ""
"First, you aren’t allowed to use `mut` with constants. Constants aren’t just\n"
"immutable by default—they’re always immutable. You declare constants using the\n"
@@ -1833,7 +1861,7 @@ msgstr ""
" sección, [“Tipos de datos”][tipos-de-datos], así que no se preocupe por los \n"
"detalles por ahora. Solo sepa que siempre debe anotar el tipo."
-#: src/ch02-01-variables-and-mutability.md:116
+#: src/ch02-01-variables-and-mutability.md:117
msgid ""
"Constants can only be declared in the global scope, which makes\n"
"them useful for values that many parts of code need to know about."
@@ -1841,7 +1869,7 @@ msgstr ""
"Las constantes solo se pueden declarar en el ámbito global, lo que las hace \n"
"útiles para valores que muchas partes del código deben conocer."
-#: src/ch02-01-variables-and-mutability.md:119
+#: src/ch02-01-variables-and-mutability.md:120
msgid ""
"The last difference is that constants may be set only to a constant expression,\n"
"not the result of a value that could only be computed at runtime. Only literal constants\n"
@@ -1851,21 +1879,21 @@ msgstr ""
"constante, no al resultado de un valor que solo se podría calcular en tiempo de ejecución. \n"
"Actualmente, solo se admiten constantes literales."
-#: src/ch02-01-variables-and-mutability.md:123
+#: src/ch02-01-variables-and-mutability.md:124
msgid "Here’s an example of a constant declaration:"
msgstr "Aquí hay un ejemplo de declaración de constante:"
-#: src/ch02-01-variables-and-mutability.md:125
+#: src/ch02-01-variables-and-mutability.md:126
msgid ""
"```rust\n"
-"const ONE_HOUR_IN_SECONDS: u32 = 3600_u32;\n"
+"const ONE_HOUR_IN_SECONDS: u32 = 3600;\n"
"```"
msgstr ""
"```rust\n"
-"const ONE_HOUR_IN_SECONDS: u32 = 3600_u32;\n"
+"const ONE_HOUR_IN_SECONDS: u32 = 3600;\n"
"```"
-#: src/ch02-01-variables-and-mutability.md:129
+#: src/ch02-01-variables-and-mutability.md:130
msgid ""
"Cairo's naming convention for constants is to use all uppercase with\n"
"underscores between words."
@@ -1873,7 +1901,7 @@ msgstr ""
"La convención de nomenclatura de Cairo para las constantes es usar todas\n"
" las mayúsculas con guiones bajos entre palabras."
-#: src/ch02-01-variables-and-mutability.md:132
+#: src/ch02-01-variables-and-mutability.md:133
msgid ""
"Constants are valid for the entire time a program runs, within the scope in\n"
"which they were declared. This property makes constants useful for values in\n"
@@ -1887,7 +1915,7 @@ msgstr ""
"podrían necesitar conocer, como el número máximo de puntos que cualquier jugador de \n"
"un juego puede ganar o la velocidad de la luz."
-#: src/ch02-01-variables-and-mutability.md:138
+#: src/ch02-01-variables-and-mutability.md:139
msgid ""
"Naming hardcoded values used throughout your program as constants is useful in\n"
"conveying the meaning of that value to future maintainers of the code. It also\n"
@@ -1899,11 +1927,11 @@ msgstr ""
" del código. También ayuda a tener solo un lugar en su código donde tendría que cambiar\n"
" si el valor codificado en duro necesitara ser actualizado en el futuro."
-#: src/ch02-01-variables-and-mutability.md:143
+#: src/ch02-01-variables-and-mutability.md:144
msgid "### Shadowing"
msgstr "### Shadowing"
-#: src/ch02-01-variables-and-mutability.md:145
+#: src/ch02-01-variables-and-mutability.md:146
msgid ""
"Variable shadowing refers to the declaration of a\n"
"new variable with the same name as a previous variable. Caironautes say that the\n"
@@ -1923,9 +1951,9 @@ msgstr ""
"sombrear una variable usando el mismo nombre de la variable y repitiendo el uso de \n"
"la palabra clave `let` de la siguiente manera:"
-#: src/ch02-01-variables-and-mutability.md:156
+#: src/ch02-01-variables-and-mutability.md:157
msgid ""
-"```swift\n"
+"```rust\n"
"use debug::PrintTrait;\n"
"fn main() {\n"
" let x = 5;\n"
@@ -1940,7 +1968,7 @@ msgid ""
"}\n"
"```"
msgstr ""
-"```swift\n"
+"```rust\n"
"use debug::PrintTrait;\n"
"fn main() {\n"
" let x = 5;\n"
@@ -1955,7 +1983,7 @@ msgstr ""
"}\n"
"```"
-#: src/ch02-01-variables-and-mutability.md:171
+#: src/ch02-01-variables-and-mutability.md:172
msgid ""
"This program first binds `x` to a value of `5`. Then it creates a new variable\n"
"`x` by repeating `let x =`, taking the original value and adding `1` so the\n"
@@ -1973,7 +2001,7 @@ msgstr ""
"un valor de `12`. Cuando ese ámbito termina, la sombra interna termina y `x`\n"
" vuelve a ser `6`. Al ejecutar este programa, se mostrará lo siguiente:"
-#: src/ch02-01-variables-and-mutability.md:179
+#: src/ch02-01-variables-and-mutability.md:180
msgid ""
"```console\n"
"cairo-run src/lib.cairo\n"
@@ -2003,7 +2031,7 @@ msgstr ""
"Run completed successfully, returning []\n"
"```"
-#: src/ch02-01-variables-and-mutability.md:193
+#: src/ch02-01-variables-and-mutability.md:194
msgid ""
"Shadowing is different from marking a variable as `mut` because we’ll get a\n"
"compile-time error if we accidentally try to reassign to this variable without\n"
@@ -2017,31 +2045,28 @@ msgstr ""
"valor pero hacer que la variable sea inmutable después de que se hayan completado \n"
"esas transformaciones."
-#: src/ch02-01-variables-and-mutability.md:199
+#: src/ch02-01-variables-and-mutability.md:200
msgid ""
"Another distinction between `mut` and shadowing is that when we use the `let` keyword again,\n"
"we are effectively creating a new variable, which allows us to change the type of the\n"
"value while reusing the same name. As mentioned before, variable shadowing and mutable variables\n"
"are equivalent at the lower level.\n"
-"The only difference is that by shadowing a variable, the compiler will not complain \n"
+"The only difference is that by shadowing a variable, the compiler will not complain\n"
"if you change its type. For example, say our program performs a type conversion between the\n"
"`u64` and `felt252` types."
msgstr ""
-"Otra distinción entre `mut` y shadowing es que cuando usamos de nuevo la palabra clave `let\n"
-"estamos creando una nueva variable, lo que nos permite cambiar el tipo del valor\n"
-"reutilizando el mismo nombre. Como se mencionó antes, la sombra de variables y las variables mutables\n"
-"son equivalentes en el nivel inferior.\n"
-"La única diferencia es que al sombrear una variable, el compilador no se quejará\n"
-"si cambias su tipo. Por ejemplo, digamos que nuestro programa realiza una conversión de tipo entre\n"
-"`u64` y `felt252`."
+"Otra distinción entre `mut` y el shadowing es que al usar nuevamente la palabra clave `let`, estamos creando efectivamente una nueva variable, lo que nos permite cambiar el tipo del "
+"valor mientras reutilizamos el mismo nombre. Como se mencionó anteriormente, el shadowing de variables y las variables mutables son equivalentes a un nivel más bajo. La única "
+"diferencia es que al hacer shadowing de una variable, el compilador no mostrará un error si cambias su tipo. Por ejemplo, supongamos que nuestro programa realiza una conversión de "
+"tipo entre los tipos `u64` y `felt252`."
-#: src/ch02-01-variables-and-mutability.md:207
+#: src/ch02-01-variables-and-mutability.md:208
msgid ""
"```rust\n"
"use debug::PrintTrait;\n"
"use traits::Into;\n"
"fn main() {\n"
-" let x = 2_u64;\n"
+" let x = 2;\n"
" x.print();\n"
" let x: felt252 = x.into(); // converts x to a felt, type annotation is required.\n"
" x.print()\n"
@@ -2052,14 +2077,14 @@ msgstr ""
"use debug::PrintTrait;\n"
"use traits::Into;\n"
"fn main() {\n"
-" let x = 2_u64;\n"
+" let x = 2;\n"
" x.print();\n"
" let x: felt252 = x.into(); // converts x to a felt, type annotation is required.\n"
" x.print()\n"
"}\n"
"```"
-#: src/ch02-01-variables-and-mutability.md:218
+#: src/ch02-01-variables-and-mutability.md:219
msgid ""
"The first `x` variable has a `u64` type while the second `x` variable has a `felt252` type.\n"
"Shadowing thus spares us from having to come up with different names, such as `x_u64`\n"
@@ -2071,13 +2096,13 @@ msgstr ""
"en su lugar, podemos reutilizar el nombre más simple `x`. Sin embargo, si intentamos usar `mut` para esto, \n"
"como se muestra aquí, obtendremos un error en tiempo de compilación:"
-#: src/ch02-01-variables-and-mutability.md:223
+#: src/ch02-01-variables-and-mutability.md:224
msgid ""
"```rust,does_not_compile\n"
"use debug::PrintTrait;\n"
"use traits::Into;\n"
"fn main() {\n"
-" let mut x = 2_u64;\n"
+" let mut x = 2;\n"
" x.print();\n"
" x = x.into();\n"
" x.print()\n"
@@ -2088,18 +2113,18 @@ msgstr ""
"use debug::PrintTrait;\n"
"use traits::Into;\n"
"fn main() {\n"
-" let mut x = 2_u64;\n"
+" let mut x = 2;\n"
" x.print();\n"
" x = x.into();\n"
" x.print()\n"
"}\n"
"```"
-#: src/ch02-01-variables-and-mutability.md:234
-msgid "The error says we’re were expecting a `u64` (the original type) but we got a different type:"
-msgstr "El error dice que se esperaba un `u64` (el tipo original) pero se obtuvo un tipo diferente:"
+#: src/ch02-01-variables-and-mutability.md:235
+msgid "The error says we were expecting a `u64` (the original type) but we got a different type:"
+msgstr "El error indica que se esperaba un `u64` (el tipo original), pero se obtuvo un tipo diferente:"
-#: src/ch02-01-variables-and-mutability.md:236
+#: src/ch02-01-variables-and-mutability.md:237
msgid ""
"```console\n"
"❯ cairo-run src/lib.cairo\n"
@@ -2121,7 +2146,7 @@ msgstr ""
"Error: failed to compile: src/lib.cairo\n"
"```"
-#: src/ch02-01-variables-and-mutability.md:246
+#: src/ch02-01-variables-and-mutability.md:247
msgid ""
"Now that we’ve explored how variables work, let’s look at more data types they\n"
"can have."
@@ -2152,21 +2177,21 @@ msgstr ""
#: src/ch02-02-data-types.md:10
msgid ""
-"```Rust\n"
+"```rust\n"
"use traits::TryInto;\n"
"use option::OptionTrait;\n"
-"fn main(){\n"
+"fn main() {\n"
" let x: felt252 = 3;\n"
-" let y:u32 = x.try_into().unwrap();\n"
+" let y: u32 = x.try_into().unwrap();\n"
"}\n"
"```"
msgstr ""
-"```Rust\n"
+"```rust\n"
"use traits::TryInto;\n"
"use option::OptionTrait;\n"
-"fn main(){\n"
+"fn main() {\n"
" let x: felt252 = 3;\n"
-" let y:u32 = x.try_into().unwrap();\n"
+" let y: u32 = x.try_into().unwrap();\n"
"}\n"
"```"
@@ -2369,7 +2394,7 @@ msgstr ""
msgid ""
"```rust\n"
"fn main() {\n"
-" // addition\n"
+" // addition\n"
" let sum = 5_u128 + 10_u128;\n"
"\n"
" // subtraction\n"
@@ -2389,7 +2414,7 @@ msgid ""
msgstr ""
"```rust\n"
"fn main() {\n"
-" // addition\n"
+" // addition\n"
" let sum = 5_u128 + 10_u128;\n"
"\n"
" // subtraction\n"
@@ -2416,18 +2441,14 @@ msgstr ""
"un único valor, que se asigna a una variable."
#: src/ch02-02-data-types.md:120
-msgid ""
-"\n"
-""
-msgstr ""
-"\n"
-""
+msgid "[Appendix B][appendix_b] contains a list of all operators that Cairo provides."
+msgstr "[Apéndice B][appendix_b] contiene una lista de todos los operadores que Cairo proporciona."
-#: src/ch02-02-data-types.md:123
+#: src/ch02-02-data-types.md:122
msgid "#### The Boolean Type"
msgstr "#### El tipo Booleano"
-#: src/ch02-02-data-types.md:125
+#: src/ch02-02-data-types.md:124
msgid ""
"As in most other programming languages, a Boolean type in Cairo has two possible\n"
"values: `true` and `false`. Booleans are one felt252 in size. The Boolean type in\n"
@@ -2437,7 +2458,7 @@ msgstr ""
"dos posibles valores: `true` y `false`. Los booleanos tienen un byte de tamaño. El tipo booleano \n"
"en Cairo se especifica usando `bool`. Por ejemplo:"
-#: src/ch02-02-data-types.md:129
+#: src/ch02-02-data-types.md:128
msgid ""
"```rust\n"
"fn main() {\n"
@@ -2455,7 +2476,7 @@ msgstr ""
"}\n"
"```"
-#: src/ch02-02-data-types.md:139
+#: src/ch02-02-data-types.md:136
msgid ""
"The main way to use Boolean values is through conditionals, such as an `if`\n"
"expression. We’ll cover how `if` expressions work in Cairo in the [“Control\n"
@@ -2465,11 +2486,11 @@ msgstr ""
"como una expresión `if` expresión. Cubriremos cómo funcionan las expresiones `if` \n"
"en Cairo en la sección. [“Control de flujo”][control-de-flujo]"
-#: src/ch02-02-data-types.md:143
+#: src/ch02-02-data-types.md:140
msgid "#### The Short String Type"
msgstr "#### El tipo de Short String"
-#: src/ch02-02-data-types.md:145
+#: src/ch02-02-data-types.md:142
msgid ""
"Cairo doesn't have a native type for strings, but you can store characters forming what we call a \"short string\" inside `felt252`s. A short string has a max length of 31 chars. "
"This is to ensure that it can fit in a single felt (a felt is 252 bits, one ASCII char is 8 bits).\n"
@@ -2479,28 +2500,31 @@ msgstr ""
"máxima de 31 caracteres. Esto es para asegurar que puede caber en un solo felt (un felt son 252 bits, un char ASCII son 8 bits).\n"
"He aquí algunos ejemplos de declaración de valores entre comillas simples:"
-#: src/ch02-02-data-types.md:148
+#: src/ch02-02-data-types.md:145
msgid ""
"```rust\n"
-"let my_first_char = 'C';\n"
-"let my_first_string = 'Hello world';\n"
+"# fn main() {\n"
+" let my_first_char = 'C';\n"
+" let my_first_string = 'Hello world';\n"
+"# }\n"
"```"
msgstr ""
"```rust\n"
-"let my_first_char = 'C';\n"
-"let my_first_string = 'Hello world';\n"
+"# fn main() {\n"
+" let my_first_char = 'C';\n"
+" let my_first_string = 'Hello world';\n"
+"# }\n"
"```"
-#: src/ch02-02-data-types.md:153
+#: src/ch02-02-data-types.md:152
msgid "### Type casting"
msgstr "### Conversión de Tipos"
-#: src/ch02-02-data-types.md:155
-msgid "In Cairo, you can convert values between common scalar types and `felt252` using the `try_into` and `into` methods provided by the `TryInto` and `Into` traits, respectively."
-msgstr ""
-"En Cairo, puedes convertir valores entre tipos escalares comunes y `felt252` usando los métodos `try_into` e `into` proporcionados por los traits `TryInto` e `Into`, respectivamente."
+#: src/ch02-02-data-types.md:154
+msgid "In Cairo, you can convert types scalar types from one type to another by using the `try_into` and `into` methods provided by the `TryInto` and `Into` traits, respectively."
+msgstr "En Cairo, puedes convertir tipos escalares de un tipo a otro utilizando los métodos `try_into` e `into` proporcionados por los traits `TryInto` e `Into`, respectivamente."
-#: src/ch02-02-data-types.md:157
+#: src/ch02-02-data-types.md:156
msgid ""
"The `try_into` method allows for safe type casting when the target type might not fit the source value. Keep in mind that `try_into` returns an `Option` type, which you'll need to "
"unwrap to access the new value."
@@ -2508,12 +2532,12 @@ msgstr ""
"El método `try_into` permite una conversión de tipos segura cuando el tipo de destino puede no encajar con el valor de origen. Ten en cuenta que `try_into` devuelve un tipo "
"`Option`, que tendrás que desenvolver para acceder al nuevo valor."
-#: src/ch02-02-data-types.md:159
+#: src/ch02-02-data-types.md:158
msgid "On the other hand, the `into` method can be used for type casting when success is guaranteed, such as when the source type is smaller than the destination type."
msgstr ""
"Por otro lado, el método `into` se puede utilizar para la conversión de tipos cuando el éxito está garantizado, como cuando el tipo de destino es más pequeño que el tipo de origen."
-#: src/ch02-02-data-types.md:161
+#: src/ch02-02-data-types.md:160
msgid ""
"To perform the conversion, call `var.into()` or `var.try_into()` on the source value to cast it to another type. The new variable's type must be explicitly defined, as demonstrated "
"in the example below."
@@ -2521,24 +2545,26 @@ msgstr ""
"Para realizar la conversión, llame a `var.into()` o `var.try_into()` sobre el valor fuente para convertirlo a otro tipo. El tipo de la nueva variable debe definirse explícitamente, "
"como se muestra en el siguiente ejemplo."
-#: src/ch02-02-data-types.md:163
+#: src/ch02-02-data-types.md:162
msgid ""
"```rust\n"
"use traits::TryInto;\n"
"use traits::Into;\n"
"use option::OptionTrait;\n"
"\n"
-"fn main(){\n"
-" let my_felt = 10;\n"
-" let my_u8: u8 = my_felt.try_into().unwrap(); // Since a felt252 might not fit in a u8, we need to unwrap the Option type\n"
-" let my_u16: u16 = my_felt.try_into().unwrap();\n"
-" let my_u32: u32 = my_felt.try_into().unwrap();\n"
-" let my_u64: u64 = my_felt.try_into().unwrap();\n"
-" let my_u128: u128 = my_felt.try_into().unwrap();\n"
-" let my_u256: u256 = my_felt.into(); // As a felt252 is smaller than a u256, we can use the into() method\n"
-" let my_usize: usize = my_felt.try_into().unwrap();\n"
-" let my_felt2: felt252 = my_u8.into();\n"
-" let my_felt3: felt252 = my_u16.into();\n"
+"fn main() {\n"
+" let my_felt252 = 10;\n"
+" // Since a felt252 might not fit in a u8, we need to unwrap the Option type\n"
+" let my_u8: u8 = my_felt252.try_into().unwrap();\n"
+" let my_u16: u16 = my_u8.into();\n"
+" let my_u32: u32 = my_u16.into();\n"
+" let my_u64: u64 = my_u32.into();\n"
+" let my_u128: u128 = my_u64.into();\n"
+" // As a felt252 is smaller than a u256, we can use the into() method\n"
+" let my_u256: u256 = my_felt252.into();\n"
+" let my_usize: usize = my_felt252.try_into().unwrap();\n"
+" let my_other_felt252: felt252 = my_u8.into();\n"
+" let my_third_felt252: felt252 = my_u16.into();\n"
"}\n"
"```"
msgstr ""
@@ -2547,25 +2573,27 @@ msgstr ""
"use traits::Into;\n"
"use option::OptionTrait;\n"
"\n"
-"fn main(){\n"
-" let my_felt = 10;\n"
-" let my_u8: u8 = my_felt.try_into().unwrap(); // Since a felt252 might not fit in a u8, we need to unwrap the Option type\n"
-" let my_u16: u16 = my_felt.try_into().unwrap();\n"
-" let my_u32: u32 = my_felt.try_into().unwrap();\n"
-" let my_u64: u64 = my_felt.try_into().unwrap();\n"
-" let my_u128: u128 = my_felt.try_into().unwrap();\n"
-" let my_u256: u256 = my_felt.into(); // As a felt252 is smaller than a u256, we can use the into() method\n"
-" let my_usize: usize = my_felt.try_into().unwrap();\n"
-" let my_felt2: felt252 = my_u8.into();\n"
-" let my_felt3: felt252 = my_u16.into();\n"
-"}\n"
-"```"
-
-#: src/ch02-02-data-types.md:182
+"fn main() {\n"
+" let my_felt252 = 10;\n"
+" // Since a felt252 might not fit in a u8, we need to unwrap the Option type\n"
+" let my_u8: u8 = my_felt252.try_into().unwrap();\n"
+" let my_u16: u16 = my_u8.into();\n"
+" let my_u32: u32 = my_u16.into();\n"
+" let my_u64: u64 = my_u32.into();\n"
+" let my_u128: u128 = my_u64.into();\n"
+" // As a felt252 is smaller than a u256, we can use the into() method\n"
+" let my_u256: u256 = my_felt252.into();\n"
+" let my_usize: usize = my_felt252.try_into().unwrap();\n"
+" let my_other_felt252: felt252 = my_u8.into();\n"
+" let my_third_felt252: felt252 = my_u16.into();\n"
+"}\n"
+"```"
+
+#: src/ch02-02-data-types.md:183
msgid "### The Tuple Type"
msgstr "### El Tipo Tupla"
-#: src/ch02-02-data-types.md:184
+#: src/ch02-02-data-types.md:185
msgid ""
"A _tuple_ is a general way of grouping together a number of values with a\n"
"variety of types into one compound type. Tuples have a fixed length: once\n"
@@ -2575,7 +2603,7 @@ msgstr ""
"de tipos en un tipo compuesto. Las tuplas tienen una longitud fija: una vez declaradas, \n"
"no pueden aumentar ni disminuir de tamaño."
-#: src/ch02-02-data-types.md:188
+#: src/ch02-02-data-types.md:189
msgid ""
"We create a tuple by writing a comma-separated list of values inside\n"
"parentheses. Each position in the tuple has a type, and the types of the\n"
@@ -2587,21 +2615,21 @@ msgstr ""
" de la tupla no tienen por qué ser iguales. Hemos añadido anotaciones opcionales de \n"
"tipo en este ejemplo:"
-#: src/ch02-02-data-types.md:193
+#: src/ch02-02-data-types.md:194
msgid ""
"```rust\n"
"fn main() {\n"
-" let tup: (u32,u64,bool) = (10,20,true);\n"
+" let tup: (u32, u64, bool) = (10, 20, true);\n"
"}\n"
"```"
msgstr ""
"```rust\n"
"fn main() {\n"
-" let tup: (u32,u64,bool) = (10,20,true);\n"
+" let tup: (u32, u64, bool) = (10, 20, true);\n"
"}\n"
"```"
-#: src/ch02-02-data-types.md:199
+#: src/ch02-02-data-types.md:200
msgid ""
"The variable `tup` binds to the entire tuple because a tuple is considered a\n"
"single compound element. To get the individual values out of a tuple, we can\n"
@@ -2611,7 +2639,7 @@ msgstr ""
" elemento compuesto. Para obtener los valores individuales de una tupla, podemos \n"
"utilizar la concordancia de patrones para desestructurar un valor de tupla, así:"
-#: src/ch02-02-data-types.md:203
+#: src/ch02-02-data-types.md:204
msgid ""
"```rust\n"
"use debug::PrintTrait;\n"
@@ -2639,7 +2667,7 @@ msgstr ""
"}\n"
"```"
-#: src/ch02-02-data-types.md:216
+#: src/ch02-02-data-types.md:217
msgid ""
"This program first creates a tuple and binds it to the variable `tup`. It then\n"
"uses a pattern with `let` to take `tup` and turn it into three separate\n"
@@ -2652,15 +2680,15 @@ msgstr ""
" `x`, `y`, y `z`. Esto se llama _desestructuración_ porque divide la tupla en tres partes. \n"
"Finalmente, el programa imprime `y es seis` ya que el valor de `y` es `6`."
-#: src/ch02-02-data-types.md:222
+#: src/ch02-02-data-types.md:223
msgid ""
-"We can also declare the tuple with value and name at the same time.\n"
+"We can also declare the tuple with value and types at the same time.\n"
"For example:"
msgstr ""
-"También podemos declarar la tupla con valor y nombre al mismo tiempo.\n"
+"También podemos declarar la tupla con los valores y los tipos al mismo tiempo. \n"
"Por ejemplo:"
-#: src/ch02-02-data-types.md:225
+#: src/ch02-02-data-types.md:226
msgid ""
"```rust\n"
"fn main() {\n"
@@ -2674,11 +2702,11 @@ msgstr ""
"}\n"
"```"
-#: src/ch02-02-data-types.md:231
+#: src/ch02-02-data-types.md:232
msgid "### The unit type ()"
msgstr "### The unit type ()"
-#: src/ch02-02-data-types.md:233
+#: src/ch02-02-data-types.md:234
msgid ""
"A _unit type_ is a type which has only one value `()`.\n"
"It is represented by a tuple with no elements.\n"
@@ -2688,7 +2716,7 @@ msgstr ""
"Se representa mediante una tupla sin elementos.\n"
"Su tamaño es siempre cero y se garantiza que no existe en el código compilado."
-#: src/ch02-03-functions.md:1 src/ch99-01-02-writing-starknet-contracts.md:134
+#: src/ch02-03-functions.md:1 src/ch99-01-02-writing-starknet-contracts.md:137
msgid "## Functions"
msgstr "## Funciones"
@@ -2706,16 +2734,14 @@ msgstr ""
#: src/ch02-03-functions.md:8
msgid ""
-"Cairo code uses *snake case* as the conventional style for function and variable\n"
+"Cairo code uses _snake case_ as the conventional style for function and variable\n"
"names, in which all letters are lowercase and underscores separate words.\n"
"Here’s a program that contains an example function definition:"
msgstr ""
-"El código de Cairo usa *snake case* como estilo convencional para los nombres de \n"
-"funciones y variables, en el que todas las letras están en minúsculas y los guiones\n"
-" bajos separan las palabras.\n"
-"Aquí hay un programa que contiene un ejemplo de definición de función:"
+"El código de Cairo utiliza el estilo _snake case_ como convención para los nombres de funciones y variables, en el cual todas las letras están en minúscula y los guiones bajos "
+"separan las palabras. Aquí hay un programa que contiene un ejemplo de definición de función:"
-#: src/ch02-03-functions.md:13
+#: src/ch02-03-functions.md:12
msgid ""
"```rust\n"
"use debug::PrintTrait;\n"
@@ -2743,7 +2769,7 @@ msgstr ""
"}\n"
"```"
-#: src/ch02-03-functions.md:26
+#: src/ch02-03-functions.md:25
msgid ""
"We define a function in Cairo by entering `fn` followed by a function name and a\n"
"set of parentheses. The curly brackets tell the compiler where the function\n"
@@ -2753,33 +2779,33 @@ msgstr ""
"conjunto de paréntesis. Las llaves indican al compilador dónde empieza y termina el\n"
" cuerpo de la función."
-#: src/ch02-03-functions.md:30
+#: src/ch02-03-functions.md:29
msgid ""
"We can call any function we’ve defined by entering its name followed by a set\n"
"of parentheses. Because `another_function` is defined in the program, it can be\n"
"called from inside the `main` function. Note that we defined `another_function`\n"
-"*before* the `main` function in the source code; we could have defined it after\n"
+"_before_ the `main` function in the source code; we could have defined it after\n"
"as well. Cairo doesn’t care where you define your functions, only that they’re\n"
"defined somewhere in a scope that can be seen by the caller."
msgstr ""
-"Podemos llamar a cualquier función que hayamos definido introduciendo su nombre \n"
-"seguido de un conjunto de paréntesis. Como `another_function` está definida en el \n"
-"programa, puede ser llamada desde dentro de la función `main`. Ten en cuenta que \n"
-"hemos definido \"another_function\" *antes* de la función `main` en el código fuente; \n"
-"también podríamos haberla definido después. A Cairo no le importa dónde definas tus \n"
-"funciones, sólo que estén definidas en algún lugar en un ámbito que pueda ser visto por quien las llama."
+"Podemos llamar a cualquier función que hayamos definido introduciendo su nombre seguido de unos\n"
+"de paréntesis. Como `otra_funcion` está definida en el programa, puede ser\n"
+"llamada desde dentro de la función `main`. Tenga en cuenta que hemos definido \"otra_función\n"
+"_antes_ de la función `main` en el código fuente; también podríamos haberla definido después.\n"
+"también. A Cairo no le importa dónde definas tus funciones, sólo que estén\n"
+"definidas en algún lugar en un ámbito que pueda ser visto por quien las llame."
-#: src/ch02-03-functions.md:37
+#: src/ch02-03-functions.md:36
msgid ""
-"Let’s start a new project with Scarb named *functions* to explore functions\n"
-"further. Place the `another_function` example in *src/lib.cairo* and run it. You\n"
+"Let’s start a new project with Scarb named _functions_ to explore functions\n"
+"further. Place the `another_function` example in _src/lib.cairo_ and run it. You\n"
"should see the following output:"
msgstr ""
-"Empecemos un nuevo proyecto con Scarb llamado *functions* para explorar las \n"
-"funciones. Coloque el ejemplo `another_function` en *src/lib.cairo* y ejecútelo. Usted\n"
+"Empecemos un nuevo proyecto con Scarb llamado _functions_ para explorar las funciones\n"
+"más a fondo. Coloque el ejemplo `another_function` en _src/lib.cairo_ y ejecútelo. Usted\n"
"Debería ver la siguiente salida:"
-#: src/ch02-03-functions.md:41
+#: src/ch02-03-functions.md:40
msgid ""
"```console\n"
"$ cairo-run src/lib.cairo\n"
@@ -2793,7 +2819,7 @@ msgstr ""
"[DEBUG] Another function. (raw: 22265147635379277118623944509513687592494)\n"
"```"
-#: src/ch02-03-functions.md:47
+#: src/ch02-03-functions.md:46
msgid ""
"The lines execute in the order in which they appear in the `main` function.\n"
"First the “Hello, world!” message prints, and then `another_function` is called\n"
@@ -2803,33 +2829,33 @@ msgstr ""
"Primero se imprime el mensaje \" Hello, world!\", y luego se llama a `another_function`\n"
" y se imprime su mensaje."
-#: src/ch02-03-functions.md:51
+#: src/ch02-03-functions.md:50
msgid "### Parameters"
msgstr "### Parámetros"
-#: src/ch02-03-functions.md:53
+#: src/ch02-03-functions.md:52
msgid ""
-"We can define functions to have *parameters*, which are special variables that\n"
+"We can define functions to have _parameters_, which are special variables that\n"
"are part of a function’s signature. When a function has parameters, you can\n"
"provide it with concrete values for those parameters. Technically, the concrete\n"
-"values are called *arguments*, but in casual conversation, people tend to use\n"
-"the words *parameter* and *argument* interchangeably for either the variables\n"
+"values are called _arguments_, but in casual conversation, people tend to use\n"
+"the words _parameter_ and _argument_ interchangeably for either the variables\n"
"in a function’s definition or the concrete values passed in when you call a\n"
"function."
msgstr ""
-"Podemos definir funciones para que tengan *parámetros*, que son variables especiales \n"
-"que forman parte de la firma de una función. Cuando una función tiene parámetros, \n"
-"puede proporcionarle valores concretos para esos parámetros. Técnicamente, los valores\n"
-"se llaman *argumentos*, pero en una conversación informal, la gente tiende a usar\n"
-"las palabras *parámetro* y *argumento* indistintamente para las variables\n"
-"en la definición de una función o los valores concretos pasados cuando se llama a una\n"
+"Podemos definir funciones para que tengan _parameters_, que son variables especiales que\n"
+"forman parte de la firma de una función. Cuando una función tiene parámetros, puede\n"
+"proporcionarle valores concretos para esos parámetros. Técnicamente, los valores\n"
+"valores concretos se llaman _arguments_, pero en la conversación informal, la gente tiende a usar\n"
+"las palabras _parameters_ y _arguments_ indistintamente para las variables\n"
+"en la definición de una función o los valores concretos que se pasan cuando se llama a una\n"
"función."
-#: src/ch02-03-functions.md:61
+#: src/ch02-03-functions.md:60
msgid "In this version of `another_function` we add a parameter:"
msgstr "En esta versión de `another_function` añadimos un parámetro:"
-#: src/ch02-03-functions.md:63
+#: src/ch02-03-functions.md:62
msgid ""
"```rust\n"
"use debug::PrintTrait;\n"
@@ -2855,11 +2881,11 @@ msgstr ""
"}\n"
"```"
-#: src/ch02-03-functions.md:75
+#: src/ch02-03-functions.md:74
msgid "Try running this program; you should get the following output:"
msgstr "Intente ejecutar este programa; debería obtener la siguiente salida:"
-#: src/ch02-03-functions.md:77 src/ch02-03-functions.md:250
+#: src/ch02-03-functions.md:76 src/ch02-03-functions.md:276
msgid ""
"```console\n"
"$ cairo-run src/lib.cairo\n"
@@ -2871,7 +2897,7 @@ msgstr ""
"[DEBUG] (raw: 5)\n"
"```"
-#: src/ch02-03-functions.md:82
+#: src/ch02-03-functions.md:81
msgid ""
"The declaration of `another_function` has one parameter named `x`. The type of\n"
"`x` is specified as `felt252`. When we pass `5` in to `another_function`, the\n"
@@ -2881,21 +2907,21 @@ msgstr ""
"`x` se especifica como `felt252`. Cuando pasamos `5` a `another_function`, la función\n"
"`print()` muestra `5` en la consola."
-#: src/ch02-03-functions.md:86
+#: src/ch02-03-functions.md:85
msgid ""
-"In function signatures, you *must* declare the type of each parameter. This is\n"
+"In function signatures, you _must_ declare the type of each parameter. This is\n"
"a deliberate decision in Cairo’s design: requiring type annotations in function\n"
"definitions means the compiler almost never needs you to use them elsewhere in\n"
"the code to figure out what type you mean. The compiler is also able to give\n"
"more helpful error messages if it knows what types the function expects."
msgstr ""
-"En las firmas de función, *debes* declarar el tipo de cada parámetro. Esta es\n"
+"En las firmas de función, _must_ declarar el tipo de cada parámetro. Esta es\n"
"una decisión deliberada en el diseño de Cairo: requerir anotaciones de tipo en las\n"
"significa que el compilador casi nunca necesita usarlas en otra parte del código\n"
"el código para averiguar a qué tipo se refiere. El compilador también es capaz de dar\n"
"mensajes de error más útiles si sabe qué tipos espera la función."
-#: src/ch02-03-functions.md:92
+#: src/ch02-03-functions.md:91
msgid ""
"When defining multiple parameters, separate the parameter declarations with\n"
"commas, like this:"
@@ -2903,16 +2929,16 @@ msgstr ""
"Cuando defina múltiples parámetros, separe las declaraciones de parámetros con\n"
"comas, así:"
-#: src/ch02-03-functions.md:95
+#: src/ch02-03-functions.md:94
msgid ""
"```rust\n"
"use debug::PrintTrait;\n"
"\n"
"fn main() {\n"
-" another_function(5,6);\n"
+" another_function(5, 6);\n"
"}\n"
"\n"
-"fn another_function(x: felt252, y:felt252) {\n"
+"fn another_function(x: felt252, y: felt252) {\n"
" x.print();\n"
" y.print();\n"
"}\n"
@@ -2922,16 +2948,16 @@ msgstr ""
"use debug::PrintTrait;\n"
"\n"
"fn main() {\n"
-" another_function(5,6);\n"
+" another_function(5, 6);\n"
"}\n"
"\n"
-"fn another_function(x: felt252, y:felt252) {\n"
+"fn another_function(x: felt252, y: felt252) {\n"
" x.print();\n"
" y.print();\n"
"}\n"
"```"
-#: src/ch02-03-functions.md:108
+#: src/ch02-03-functions.md:107
msgid ""
"This example creates a function named `another_function` with two\n"
"parameters. The first parameter is named `x` and is an `felt252`. The second is\n"
@@ -2941,15 +2967,15 @@ msgstr ""
"parámetro se llama `x` y es un `felt252`. El segundo se llama `y` y también es del tipo `felt252`. \n"
"La función luego imprime el contenido del `x` y luego el contenido del `y`."
-#: src/ch02-03-functions.md:112
+#: src/ch02-03-functions.md:111
msgid ""
-"Let’s try running this code. Replace the program currently in your *functions*\n"
-"project’s *src/lib.cairo* file with the preceding example and run it using `cairo-run src/lib.cairo`:"
+"Let’s try running this code. Replace the program currently in your _functions_\n"
+"project’s _src/lib.cairo_ file with the preceding example and run it using `cairo-run src/lib.cairo`:"
msgstr ""
-"Intentemos ejecutar este código. Reemplaza el programa actualmente en el archivo \n"
-"*src/lib.cairo* de tu proyecto *functions* con el ejemplo anterior y ejecútalo usando `cairo-run src/lib.cairo`:"
+"Intentemos ejecutar este código. Sustituye el programa que actualmente está en tu proyecto _functions_\n"
+"de tu proyecto _src/lib.cairo_ con el ejemplo anterior y ejecútalo usando `cairo-run src/lib.cairo`:"
-#: src/ch02-03-functions.md:115
+#: src/ch02-03-functions.md:114
msgid ""
"```console\n"
"$ cairo-run src/lib.cairo\n"
@@ -2963,7 +2989,7 @@ msgstr ""
"[DEBUG] (raw: 6)\n"
"```"
-#: src/ch02-03-functions.md:121
+#: src/ch02-03-functions.md:120
msgid ""
"Because we called the function with `5` as the value for `x` and `6` as\n"
"the value for `y`, the program output contains those values."
@@ -2971,11 +2997,58 @@ msgstr ""
"Debido a que llamamos a la función con `5` como valor para `x` y `6` como valor\n"
" para `y`, la salida del programa contiene esos valores."
-#: src/ch02-03-functions.md:124
+#: src/ch02-03-functions.md:123
+msgid "#### Named parameters"
+msgstr "#### Parámetros con nombre"
+
+#: src/ch02-03-functions.md:125
+msgid ""
+"In Cairo, named parameters allow you to specify the names of arguments when you call a function. This makes the function calls more readable and self-descriptive.\n"
+"If you want to use named parameters, you need to specify the name of the parameter and the value you want to pass to it. The syntax is `parameter_name: value`. If you pass a variable "
+"that has the same name as the parameter, you can simply write `:parameter_name` instead of `parameter_name: variable_name`."
+msgstr ""
+"En Cairo, los parámetros con nombre permiten especificar los nombres de los argumentos cuando se llama a una función. Esto hace que las llamadas a funciones sean más legibles y "
+"autodescriptivas.\n"
+"Si quieres usar parámetros con nombre, necesitas especificar el nombre del parámetro y el valor que quieres pasarle. La sintaxis es `parameter_name: value`. Si pasas una variable que "
+"tiene el mismo nombre que el parámetro, puedes escribir simplemente `:parameter_name` en lugar de `parameter_name: variable_name`."
+
+#: src/ch02-03-functions.md:128
+msgid "Here is an example:"
+msgstr "Aquí un ejemplo:"
+
+#: src/ch02-03-functions.md:130
+msgid ""
+"```rust\n"
+"fn foo(x: u8, y: u8) {}\n"
+"\n"
+"fn main() {\n"
+" let first_arg = 3;\n"
+" let second_arg = 4;\n"
+" foo(x: first_arg, y: second_arg);\n"
+" let x = 1;\n"
+" let y = 2;\n"
+" foo(:x, :y)\n"
+"}\n"
+"```"
+msgstr ""
+"```rust\n"
+"fn foo(x: u8, y: u8) {}\n"
+"\n"
+"fn main() {\n"
+" let first_arg = 3;\n"
+" let second_arg = 4;\n"
+" foo(x: first_arg, y: second_arg);\n"
+" let x = 1;\n"
+" let y = 2;\n"
+" foo(:x, :y)\n"
+"}\n"
+"```"
+
+#: src/ch02-03-functions.md:143
msgid "### Statements and Expressions"
msgstr "### Declaraciones y Expresiones"
-#: src/ch02-03-functions.md:126
+#: src/ch02-03-functions.md:145
msgid ""
"Function bodies are made up of a series of statements optionally ending in an\n"
"expression. So far, the functions we’ve covered haven’t included an ending\n"
@@ -2993,26 +3066,27 @@ msgstr ""
"distinciones, así que veamos qué son las sentencias y expresiones y cómo sus diferencias \n"
"afectan los cuerpos de las funciones."
-#: src/ch02-03-functions.md:134
+#: src/ch02-03-functions.md:153
msgid ""
-"* **Statements** are instructions that perform some action and do not return\n"
+"- **Statements** are instructions that perform some action and do not return\n"
" a value.\n"
-"* **Expressions** evaluate to a resultant value. Let’s look at some examples."
+"- **Expressions** evaluate to a resultant value. Let’s look at some examples."
msgstr ""
-"* **Declaraciones** son instrucciones que realizan alguna acción y no devuelven un valor.\n"
-"* **Expresiones** se evalúan para producir un valor resultante. Veamos algunos ejemplos."
+"- Las **Declaraciones** son instrucciones que realizan alguna acción y no devuelven\n"
+" un valor.\n"
+"- Las **Expresiones** se evalúan a un valor resultante. Veamos algunos ejemplos."
-#: src/ch02-03-functions.md:138
+#: src/ch02-03-functions.md:157
msgid ""
"We’ve actually already used statements and expressions. Creating a variable and\n"
-"assigning a value to it with the `let` keyword is a statement. In Listing 3-1,\n"
+"assigning a value to it with the `let` keyword is a statement. In Listing 2-1,\n"
"`let y = 6;` is a statement."
msgstr ""
"De hecho, ya hemos utilizado declaraciones y expresiones. Crear una variable y \n"
-"asignarle un valor con la palabra clave `let` es una declaración. En el Listado 3-1,\n"
+"asignarle un valor con la palabra clave `let` es una declaración. En el Listado 2-1,\n"
" `let y = 6;` es una declaración."
-#: src/ch02-03-functions.md:142
+#: src/ch02-03-functions.md:161
msgid ""
"```rust\n"
"fn main() {\n"
@@ -3026,11 +3100,11 @@ msgstr ""
"}\n"
"```"
-#: src/ch02-03-functions.md:148
-msgid "Listing 3-1: A `main` function declaration containing one statement"
-msgstr "Listing 3-1: A `main` function declaration containing one statement"
+#: src/ch02-03-functions.md:167
+msgid "Listing 2-1: A `main` function declaration containing one statement"
+msgstr "Listing 2-1: A `main` declaración de función que contiene una declaración"
-#: src/ch02-03-functions.md:150
+#: src/ch02-03-functions.md:169
msgid ""
"Function definitions are also statements; the entire preceding example is a\n"
"statement in itself."
@@ -3038,7 +3112,7 @@ msgstr ""
"Las definiciones de funciones también son sentencias; todo el ejemplo anterior \n"
"es una sentencia en sí misma."
-#: src/ch02-03-functions.md:153
+#: src/ch02-03-functions.md:172
msgid ""
"Statements do not return values. Therefore, you can’t assign a `let` statement\n"
"to another variable, as the following code tries to do; you’ll get an error:"
@@ -3046,25 +3120,25 @@ msgstr ""
"Las Declaraciones no devuelven valores. Por lo tanto, no se puede asignar una sentencia \n"
"`let` a otra variable, como intenta hacer el siguiente código; se producirá un error:"
-#: src/ch02-03-functions.md:156
+#: src/ch02-03-functions.md:175
msgid ""
-"```rust,does_not_compile\n"
+"```rust,does_not_compile,ignore_format\n"
"fn main() {\n"
" let x = (let y = 6);\n"
"}\n"
"```"
msgstr ""
-"```rust,does_not_compile\n"
+"```rust,does_not_compile,ignore_format\n"
"fn main() {\n"
" let x = (let y = 6);\n"
"}\n"
"```"
-#: src/ch02-03-functions.md:161
+#: src/ch02-03-functions.md:181
msgid "When you run this program, the error you’ll get looks like this:"
msgstr "Cuando ejecutes este programa, el error que obtendrás se verá así:"
-#: src/ch02-03-functions.md:162
+#: src/ch02-03-functions.md:183
msgid ""
"```console\n"
"$ cairo-run src/lib.cairo\n"
@@ -3110,7 +3184,7 @@ msgstr ""
" let x = (let y = 6);\n"
"```"
-#: src/ch02-03-functions.md:184
+#: src/ch02-03-functions.md:205
msgid ""
"The `let y = 6` statement does not return a value, so there isn’t anything for\n"
"`x` to bind to. This is different from what happens in other languages, such as\n"
@@ -3123,24 +3197,25 @@ msgstr ""
"donde la asignación devuelve el valor de la asignación. En esos lenguajes, puedes escribir\n"
" `x = y = 6` y tanto `x` como `y` tendrán el valor `6`; esto no es así en Cairo."
-#: src/ch02-03-functions.md:190
+#: src/ch02-03-functions.md:211
msgid ""
"Expressions evaluate to a value and make up most of the rest of the code that\n"
"you’ll write in Cairo. Consider a math operation, such as `5 + 6`, which is an\n"
"expression that evaluates to the value `11`. Expressions can be part of\n"
-"statements: in Listing 3-1, the `6` in the statement `let y = 6;` is an\n"
+"statements: in Listing 2-1, the `6` in the statement `let y = 6;` is an\n"
"expression that evaluates to the value `6`. Calling a function is an\n"
"expression. A new scope block created with\n"
"curly brackets is an expression, for example:"
msgstr ""
-"Las expresiones evalúan a un valor y componen la mayor parte del código que \n"
-"escribirás en Cairo. Considera una operación matemática, como `5 + 6`, que es \n"
-"una expresión que evalúa al valor `11`. Las expresiones pueden formar parte de \n"
-"las declaraciones: en el Listado 3-1, el `6` en la declaración `let y = 6;` es una expresión \n"
-"que evalúa al valor `6`. Llamar a una función es una expresión. Un bloque de ámbito\n"
-" nuevo creado con llaves es una expresión, por ejemplo:"
+"Las expresiones se evalúan a un valor y forman la mayor parte del resto del código que escribirás en Cairo.\n"
+"escribirás en Cairo. Considera una operación matemática, como `5 + 6`, que es una\n"
+"expresión que se evalúa al valor `11`. Las expresiones pueden ser parte de\n"
+"sentencias: en el Listado 2-1, el `6` en la sentencia `let y = 6;` es una\n"
+"es una expresión que se evalúa al valor `6`. Llamar a una función es una\n"
+"expresión. Un nuevo bloque de ámbito creado con\n"
+"es una expresión, por ejemplo:"
-#: src/ch02-03-functions.md:199
+#: src/ch02-03-functions.md:219
msgid ""
"```rust\n"
"use debug::PrintTrait;\n"
@@ -3166,27 +3241,27 @@ msgstr ""
"}\n"
"```"
-#: src/ch02-03-functions.md:211
+#: src/ch02-03-functions.md:231
msgid "This expression:"
msgstr "Esta expresión:"
-#: src/ch02-03-functions.md:212
+#: src/ch02-03-functions.md:233
msgid ""
-"```rust\n"
+"```rust, does_not_compile, ignore_format\n"
"{\n"
-" let x = 3;\n"
-" x + 1\n"
+" let x = 3;\n"
+" x + 1\n"
"}\n"
"```"
msgstr ""
-"```rust\n"
+"```rust, does_not_compile, ignore_format\n"
"{\n"
-" let x = 3;\n"
-" x + 1\n"
+" let x = 3;\n"
+" x + 1\n"
"}\n"
"```"
-#: src/ch02-03-functions.md:218
+#: src/ch02-03-functions.md:240
msgid ""
"is a block that, in this case, evaluates to `4`. That value gets bound to `y`\n"
"as part of the `let` statement. Note that the `x + 1` line doesn’t have a\n"
@@ -3204,11 +3279,11 @@ msgstr ""
"ese caso no se devolverá ningún valor. Tenlo en cuenta mientras exploras los \n"
"valores de retorno de las funciones y las expresiones a continuación."
-#: src/ch02-03-functions.md:225
+#: src/ch02-03-functions.md:248
msgid "### Functions with Return Values"
msgstr "### Funciones con Valores de Retorno"
-#: src/ch02-03-functions.md:226
+#: src/ch02-03-functions.md:250
msgid ""
"Functions can return values to the code that calls them. We don’t name return\n"
"values, but we must declare their type after an arrow (`->`). In Cairo, the\n"
@@ -3225,13 +3300,13 @@ msgstr ""
"palabra clave `return` y especificando un valor, pero la mayoría de las funciones devuelven\n"
" la última expresión implícitamente. Aquí hay un ejemplo de una función que devuelve un valor:"
-#: src/ch02-03-functions.md:234
+#: src/ch02-03-functions.md:258
msgid ""
"```rust\n"
"use debug::PrintTrait;\n"
"\n"
"fn five() -> u32 {\n"
-" 5_u32\n"
+" 5\n"
"}\n"
"\n"
"fn main() {\n"
@@ -3244,7 +3319,7 @@ msgstr ""
"use debug::PrintTrait;\n"
"\n"
"fn five() -> u32 {\n"
-" 5_u32\n"
+" 5\n"
"}\n"
"\n"
"fn main() {\n"
@@ -3253,7 +3328,7 @@ msgstr ""
"}\n"
"```"
-#: src/ch02-03-functions.md:246
+#: src/ch02-03-functions.md:271
msgid ""
"There are no function calls, or even `let` statements in the `five`\n"
"function—just the number `5` by itself. That’s a perfectly valid function in\n"
@@ -3265,7 +3340,7 @@ msgstr ""
" Observa que se especifica el tipo de retorno de la función como `-> u32`. Intenta\n"
" ejecutar este código; la salida debería verse así:"
-#: src/ch02-03-functions.md:254
+#: src/ch02-03-functions.md:281
msgid ""
"The `5` in `five` is the function’s return value, which is why the return type\n"
"is `u32`. Let’s examine this in more detail. There are two important bits:\n"
@@ -3279,17 +3354,17 @@ msgstr ""
"retorno de una función para inicializar una variable. Debido a que la función `five` \n"
"devuelve un `5`, esa línea es lo mismo que:"
-#: src/ch02-03-functions.md:259
+#: src/ch02-03-functions.md:287
msgid ""
-"```rust\n"
+"```rust, does_not_compile\n"
"let x = 5;\n"
"```"
msgstr ""
-"```rust\n"
+"```rust, does_not_compile\n"
"let x = 5;\n"
"```"
-#: src/ch02-03-functions.md:262
+#: src/ch02-03-functions.md:291
msgid ""
"Second, the `five` function has no parameters and defines the type of the\n"
"return value, but the body of the function is a lonely `5` with no semicolon\n"
@@ -3301,19 +3376,19 @@ msgstr ""
"porque es una expresión cuyo valor queremos devolver.\n"
"Veamos otro ejemplo:"
-#: src/ch02-03-functions.md:267
+#: src/ch02-03-functions.md:296
msgid ""
"```rust\n"
"use debug::PrintTrait;\n"
"\n"
"fn main() {\n"
-" let x = plus_one(5_u32);\n"
+" let x = plus_one(5);\n"
"\n"
" x.print();\n"
"}\n"
"\n"
"fn plus_one(x: u32) -> u32 {\n"
-" x + 1_u32\n"
+" x + 1\n"
"}\n"
"```"
msgstr ""
@@ -3321,17 +3396,17 @@ msgstr ""
"use debug::PrintTrait;\n"
"\n"
"fn main() {\n"
-" let x = plus_one(5_u32);\n"
+" let x = plus_one(5);\n"
"\n"
" x.print();\n"
"}\n"
"\n"
"fn plus_one(x: u32) -> u32 {\n"
-" x + 1_u32\n"
+" x + 1\n"
"}\n"
"```"
-#: src/ch02-03-functions.md:280
+#: src/ch02-03-functions.md:310
msgid ""
"Running this code will print `[DEBUG] (raw: 6)`. But if we place a\n"
"semicolon at the end of the line containing `x + 1`, changing it from an\n"
@@ -3341,19 +3416,19 @@ msgstr ""
"agregamos un punto y coma al final de la línea que contiene `x + 1`, cambiándola \n"
"de una expresión a una declaración, obtendremos un error:"
-#: src/ch02-03-functions.md:284
+#: src/ch02-03-functions.md:314
msgid ""
"```rust,does_not_compile\n"
"use debug::PrintTrait;\n"
"\n"
"fn main() {\n"
-" let x = plus_one(5_u32);\n"
+" let x = plus_one(5);\n"
"\n"
" x.print();\n"
"}\n"
"\n"
"fn plus_one(x: u32) -> u32 {\n"
-" x + 1_u32;\n"
+" x + 1;\n"
"}\n"
"```"
msgstr ""
@@ -3361,21 +3436,21 @@ msgstr ""
"use debug::PrintTrait;\n"
"\n"
"fn main() {\n"
-" let x = plus_one(5_u32);\n"
+" let x = plus_one(5);\n"
"\n"
" x.print();\n"
"}\n"
"\n"
"fn plus_one(x: u32) -> u32 {\n"
-" x + 1_u32;\n"
+" x + 1;\n"
"}\n"
"```"
-#: src/ch02-03-functions.md:298
+#: src/ch02-03-functions.md:328
msgid "Compiling this code produces an error, as follows:"
msgstr "La compilación de este código produce un error, como se muestra a continuación:"
-#: src/ch02-03-functions.md:299
+#: src/ch02-03-functions.md:330
msgid ""
"```console\n"
"error: Unexpected return type. Expected: \"core::integer::u32\", found: \"()\".\n"
@@ -3385,7 +3460,7 @@ msgstr ""
"error: Unexpected return type. Expected: \"core::integer::u32\", found: \"()\".\n"
"```"
-#: src/ch02-03-functions.md:302
+#: src/ch02-03-functions.md:334
msgid ""
"The main error message, `Unexpected return type`, reveals the core issue with this\n"
"code. The definition of the function `plus_one` says that it will return an\n"
@@ -3520,11 +3595,11 @@ msgstr "Intentaré cambiar el valor de number por uno que haga que la condición
#: src/ch02-05-control-flow.md:38
msgid ""
-"```rust\n"
+"```rust, does_not_compile\n"
" let number = 5;\n"
"```"
msgstr ""
-"```rust\n"
+"```rust, does_not_compile\n"
" let number = 5;\n"
"```"
@@ -3729,26 +3804,26 @@ msgstr ""
#: src/ch02-05-control-flow.md:132
msgid ""
-"```rust,ignore,does_not_compile\n"
+"```rust\n"
"use debug::PrintTrait;\n"
"fn main() {\n"
-" let mut i:usize = 0;\n"
+" let mut i: usize = 0;\n"
" loop {\n"
-" if i > 10{\n"
-" break();\n"
+" if i > 10 {\n"
+" break ();\n"
" }\n"
" 'again!'.print();\n"
" }\n"
"}\n"
"```"
msgstr ""
-"```rust,ignore,does_not_compile\n"
+"```rust\n"
"use debug::PrintTrait;\n"
"fn main() {\n"
-" let mut i:usize = 0;\n"
+" let mut i: usize = 0;\n"
" loop {\n"
-" if i > 10{\n"
-" break();\n"
+" if i > 10 {\n"
+" break ();\n"
" }\n"
" 'again!'.print();\n"
" }\n"
@@ -3759,17 +3834,17 @@ msgstr ""
msgid ""
"When we run this program, we’ll see `again!` printed over and over continuously\n"
"until we stop the program manually, because the stop condition is never reached.\n"
-"While the compiler prevents us from writing programs without a stop condition (`break()` statement),\n"
+"While the compiler prevents us from writing programs without a stop condition (`break` statement),\n"
"the stop condition might never be reached, resulting in an infinite loop.\n"
"Most terminals support the keyboard shortcut ctrl-c to interrupt a program that is\n"
"stuck in a continual loop. Give it a try:"
msgstr ""
-"Cuando ejecutemos este programa, veremos impreso `¡otra vez!` una y otra vez continuamente\n"
-"hasta que detengamos el programa manualmente, porque la condición de parada nunca se alcanza.\n"
-"Aunque el compilador nos impide escribir programas sin una condición de parada (sentencia `break()`),\n"
-"la condición de parada podría no alcanzarse nunca, dando lugar a un bucle infinito.\n"
-"La mayoría de los terminales soportan el atajo de teclado ctrl-c para interrumpir un programa que está\n"
-"en un bucle continuo. Pruébalo:"
+"Cuando ejecutamos este programa, veremos que se imprime `again!` una y otra vez continuamente\n"
+"hasta que detengamos el programa manualmente, porque la condición de parada nunca se cumple.\n"
+"Si bien el compilador nos impide escribir programas sin una condición de parada (`break`),\n"
+"es posible que la condición de parada nunca se cumpla, lo que resulta en un bucle infinito. \n"
+"La mayoría de las terminales admiten el atajo de teclado ctrl-c para interrumpir un programa que está\n"
+"atrapado en un bucle continuo. Pruébalo:"
#: src/ch02-05-control-flow.md:152
msgid ""
@@ -3819,11 +3894,11 @@ msgstr ""
#: src/ch02-05-control-flow.md:170
msgid ""
-"To break out of a loop, you can place the `break()` statement within the loop to tell the program when to stop\n"
+"To break out of a loop, you can place the `break` statement within the loop to tell the program when to stop\n"
"executing the loop. Let's fix the infinite loop by adding a making the stop condition `i > 10` reachable."
msgstr ""
-"Para salir de un bucle, puede colocar la sentencia `break()` dentro del bucle para indicar al programa cuándo debe detener la ejecución del bucle\n"
-"la ejecución del bucle. Arreglemos el bucle infinito añadiendo una condición de parada `i > 10` alcanzable."
+"Para salir de un bucle, puedes colocar la instrucción `break` dentro del bucle para indicarle al programa cuándo detener\n"
+"la ejecución del bucle. Vamos a solucionar el bucle infinito haciendo que la condición de parada `i > 10` sea alcanzable."
#: src/ch02-05-control-flow.md:173
msgid ""
@@ -3856,10 +3931,60 @@ msgstr ""
"```"
#: src/ch02-05-control-flow.md:187
+msgid ""
+"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 `print` statement when `i` is equal to `5`."
+msgstr ""
+"La palabra clave `continue` le indica al programa que pase a la siguiente iteración del bucle y omita el resto del código en esta iteración. Agreguemos una instrucción `continue` a "
+"nuestro bucle para saltar la declaración `print` cuando `i` sea igual a `5`."
+
+#: src/ch02-05-control-flow.md:189
+msgid ""
+"```rust\n"
+"use debug::PrintTrait;\n"
+"fn main() {\n"
+" let mut i: usize = 0;\n"
+" loop {\n"
+" if i > 10 {\n"
+" break ();\n"
+" }\n"
+" if i == 5 {\n"
+" i += 1;\n"
+" continue;\n"
+" }\n"
+" i.print();\n"
+" i += 1;\n"
+" }\n"
+"}\n"
+"```"
+msgstr ""
+"```rust\n"
+"use debug::PrintTrait;\n"
+"fn main() {\n"
+" let mut i: usize = 0;\n"
+" loop {\n"
+" if i > 10 {\n"
+" break ();\n"
+" }\n"
+" if i == 5 {\n"
+" i += 1;\n"
+" continue;\n"
+" }\n"
+" i.print();\n"
+" i += 1;\n"
+" }\n"
+"}\n"
+"```"
+
+#: src/ch02-05-control-flow.md:207
+msgid "Executing this program will not print the value of `i` when it is equal to `5`."
+msgstr "Al ejecutar este programa, no se imprimirá el valor de `i` cuando sea igual a `5`."
+
+#: src/ch02-05-control-flow.md:209
msgid "#### Returning Values from Loops"
msgstr "#### Devolución de Valores de Loops"
-#: src/ch02-05-control-flow.md:189
+#: src/ch02-05-control-flow.md:211
msgid ""
"One of the uses of a `loop` is to retry an operation you know might fail, such\n"
"as checking whether an operation has succeeded. You might also need to pass\n"
@@ -3875,7 +4000,7 @@ msgstr ""
"para detener el bucle; ese valor será devuelto fuera del bucle para que pueda utilizarlo, \n"
"como se muestra aquí:"
-#: src/ch02-05-control-flow.md:196
+#: src/ch02-05-control-flow.md:218
msgid ""
"```rust\n"
"use debug::PrintTrait;\n"
@@ -3911,7 +4036,7 @@ msgstr ""
"}\n"
"```"
-#: src/ch02-05-control-flow.md:213
+#: src/ch02-05-control-flow.md:235
msgid ""
"Before the loop, we declare a variable named `counter` and initialize it to\n"
"`0`. Then we declare a variable named `result` to hold the value returned from\n"
@@ -3962,8 +4087,8 @@ msgid "#### Creating an Array"
msgstr "#### Crear un Array"
#: src/ch02-06-common-collections.md:14
-msgid "Creating an Array is done with the `ArrayTrait::new()` call. Here is an example of creation of an array with 3 elements:"
-msgstr "La creación de un Array se realiza con la llamada `ArrayTrait::new()`. He aquí un ejemplo de creación de un array con 3 elementos:"
+msgid "Creating an Array is done with the `ArrayTrait::new()` call. Here is an example of the creation of an array to which we append 3 elements:"
+msgstr "Crear una matriz se realiza con la llamada ArrayTrait::new()`. Aquí tienes un ejemplo de la creación de una matriz a la que agregamos 3 elementos:"
#: src/ch02-06-common-collections.md:16
msgid ""
@@ -3995,11 +4120,11 @@ msgstr "Puede pasar el tipo esperado de elementos dentro de la array al instanci
#: src/ch02-06-common-collections.md:29
msgid ""
-"```rust,\n"
+"```rust, does_not_compile\n"
"let mut arr = ArrayTrait::::new();\n"
"```"
msgstr ""
-"```rust,\n"
+"```rust, does_not_compile\n"
"let mut arr = ArrayTrait::::new();\n"
"```"
@@ -4018,32 +4143,40 @@ msgstr "To add an element to the end of an array, you can use the `append()` met
#: src/ch02-06-common-collections.md:39
msgid ""
"```rust\n"
-" let mut a = ArrayTrait::new();\n"
-" a.append(10);\n"
-" a.append(1);\n"
-" a.append(2);\n"
+"# use array::ArrayTrait;\n"
+"# \n"
+"# fn main() {\n"
+"# let mut a = ArrayTrait::new();\n"
+" a.append(0);\n"
+"# a.append(1);\n"
+"# a.append(2);\n"
+"# }\n"
"```"
msgstr ""
"```rust\n"
-" let mut a = ArrayTrait::new();\n"
-" a.append(10);\n"
-" a.append(1);\n"
-" a.append(2);\n"
+"# use array::ArrayTrait;\n"
+"# \n"
+"# fn main() {\n"
+"# let mut a = ArrayTrait::new();\n"
+" a.append(0);\n"
+"# a.append(1);\n"
+"# a.append(2);\n"
+"# }\n"
"```"
-#: src/ch02-06-common-collections.md:46
+#: src/ch02-06-common-collections.md:50
msgid "##### Removing Elements"
msgstr "##### Eliminar Elementos"
-#: src/ch02-06-common-collections.md:48
+#: src/ch02-06-common-collections.md:52
msgid ""
-"To remove an element from the front of an array, you can use the `pop_front()` method.\n"
+"You can only remove elements from the front of an array by using the `pop_front()` method.\n"
"This method returns an `Option` containing the removed element, or `Option::None` if the array is empty."
msgstr ""
-"Para eliminar un elemento de la parte frontal de un array, puedes utilizar el método `pop_front()`.\n"
+"Sólo se pueden eliminar elementos de la parte frontal de un array utilizando el método `pop_front()`.\n"
"Este método devuelve un `Option` que contiene el elemento eliminado, o `Option::None` si el array está vacío."
-#: src/ch02-06-common-collections.md:51
+#: src/ch02-06-common-collections.md:55
msgid ""
"```rust\n"
"use option::OptionTrait;\n"
@@ -4077,11 +4210,11 @@ msgstr ""
"}\n"
"```"
-#: src/ch02-06-common-collections.md:67
+#: src/ch02-06-common-collections.md:71
msgid "The above code will print `10` as we remove the first element that was added."
msgstr "El código anterior imprimirá `10` cuando eliminemos el primer elemento añadido."
-#: src/ch02-06-common-collections.md:69
+#: src/ch02-06-common-collections.md:73
msgid ""
"In Cairo, memory is immutable, which means that it is not possible to modify the elements of an array once they've been added. You can only add elements to the end of an array and "
"remove elements from the front of an array. These operations do not require memory mutation, as they involve updating pointers rather than directly modifying the memory cells."
@@ -4090,18 +4223,18 @@ msgstr ""
"un array y eliminar elementos de la parte frontal de un array. Estas operaciones no requieren mutación de memoria, ya que implican actualizar punteros en lugar de modificar "
"directamente las celdas de memoria."
-#: src/ch02-06-common-collections.md:71
+#: src/ch02-06-common-collections.md:75
msgid "#### Reading Elements from an Array"
msgstr "#### Lectura de Elementos de un Array"
-#: src/ch02-06-common-collections.md:73
+#: src/ch02-06-common-collections.md:77
msgid ""
"To access array elements, you can use `get()` or `at()` array methods that return different types. Using `arr.at(index)` is equivalent to using the subscripting operator `arr[index]`."
msgstr ""
"Para acceder a los elementos de un array, puedes utilizar los métodos `get()` o `at()` que devuelven diferentes tipos. Utilizar `arr.at(index)` es equivalente a utilizar el operador "
"de subíndice `arr[index]`."
-#: src/ch02-06-common-collections.md:75
+#: src/ch02-06-common-collections.md:79
msgid ""
"The `get` function returns an `Option>`, which means it returns an option to a Box type (Cairo's smart-pointer type) containing a snapshot to the element at the specified "
"index if that element exists in the array. If the element doesn't exist, `get` returns `None`. This method is useful when you expect to access indices that may not be within the "
@@ -4113,7 +4246,7 @@ msgstr ""
"dentro de los límites del array y quieres manejar tales casos con gracia sin pánicos. Las instantáneas se explicarán con más detalle en el capítulo [Referencias y Snapshots](ch03-02-"
"references-and-snapshots.md)."
-#: src/ch02-06-common-collections.md:77
+#: src/ch02-06-common-collections.md:81
msgid ""
"The `at` function, on the other hand, directly returns a snapshot to the element at the specified index using the `unbox()` operator to extract the value stored in a box. If the "
"index is out of bounds, a panic error occurs. You should only use at when you want the program to panic if the provided index is out of the array's bounds, which can prevent "
@@ -4123,13 +4256,13 @@ msgstr ""
"caja. Si el índice está fuera de los límites, se produce un error de pánico. Sólo debe utilizar at cuando desee que el programa entre en pánico si el índice proporcionado está fuera "
"de los límites del array, lo que puede evitar comportamientos inesperados."
-#: src/ch02-06-common-collections.md:79
+#: src/ch02-06-common-collections.md:83
msgid "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."
msgstr ""
"En resumen, usa `at` cuando quieras que el programa entre en pánico ante intentos de acceso fuera de los límites, y usa `get` cuando prefieras manejar estos casos con gracia sin "
"entrar en pánico."
-#: src/ch02-06-common-collections.md:81
+#: src/ch02-06-common-collections.md:85
msgid ""
"```rust\n"
"use array::ArrayTrait;\n"
@@ -4138,8 +4271,8 @@ msgid ""
" a.append(0);\n"
" a.append(1);\n"
"\n"
-" let first = *a.at(0_usize);\n"
-" let second = *a.at(1_usize);\n"
+" let first = *a.at(0);\n"
+" let second = *a.at(1);\n"
"}\n"
"```"
msgstr ""
@@ -4150,12 +4283,12 @@ msgstr ""
" a.append(0);\n"
" a.append(1);\n"
"\n"
-" let first = *a.at(0_usize);\n"
-" let second = *a.at(1_usize);\n"
+" let first = *a.at(0);\n"
+" let second = *a.at(1);\n"
"}\n"
"```"
-#: src/ch02-06-common-collections.md:93
+#: src/ch02-06-common-collections.md:97
msgid ""
"In this example, the variable named `first` will get the value `0` because that\n"
"is the value at index `0` in the array. The variable named `second` will get\n"
@@ -4165,24 +4298,25 @@ msgstr ""
"valor del índice `0` del array. La variable llamada `second` obtendrá el valor `1` \n"
"del índice `1` del array."
-#: src/ch02-06-common-collections.md:97
+#: src/ch02-06-common-collections.md:101
msgid "Here is an example with the `get()` method:"
msgstr "He aquí un ejemplo con el método `get()`:"
-#: src/ch02-06-common-collections.md:99
+#: src/ch02-06-common-collections.md:103
msgid ""
-"```rust\n"
+"```rust,ignore_format\n"
"use array::ArrayTrait;\n"
"use box::BoxTrait;\n"
"fn main() -> u128 {\n"
" let mut arr = ArrayTrait::::new();\n"
-" arr.append(100_u128);\n"
+" arr.append(100);\n"
" let index_to_access =\n"
-" 1_usize; // Change this value to see different results, what would happen if the index doesn't exist ?\n"
+" 1; // Change this value to see different results, what would happen if the index doesn't exist?\n"
" match arr.get(index_to_access) {\n"
" Option::Some(x) => {\n"
-" *x.unbox() // Don't worry about * for now, if you are curious see Chapter 3.2 #desnap operator\n"
-" // It basically means \"transform what get(idx) returned into a real value\"\n"
+" *x.unbox()\n"
+" // Don't worry about * for now, if you are curious see Chapter 3.2 #desnap operator\n"
+" // It basically means \"transform what get(idx) returned into a real value\"\n"
" },\n"
" Option::None(_) => {\n"
" let mut data = ArrayTrait::new();\n"
@@ -4193,18 +4327,19 @@ msgid ""
"}\n"
"```"
msgstr ""
-"```rust\n"
+"```rust,ignore_format\n"
"use array::ArrayTrait;\n"
"use box::BoxTrait;\n"
"fn main() -> u128 {\n"
" let mut arr = ArrayTrait::::new();\n"
-" arr.append(100_u128);\n"
+" arr.append(100);\n"
" let index_to_access =\n"
-" 1_usize; // Change this value to see different results, what would happen if the index doesn't exist ?\n"
+" 1; // Change this value to see different results, what would happen if the index doesn't exist?\n"
" match arr.get(index_to_access) {\n"
" Option::Some(x) => {\n"
-" *x.unbox() // Don't worry about * for now, if you are curious see Chapter 3.2 #desnap operator\n"
-" // It basically means \"transform what get(idx) returned into a real value\"\n"
+" *x.unbox()\n"
+" // Don't worry about * for now, if you are curious see Chapter 3.2 #desnap operator\n"
+" // It basically means \"transform what get(idx) returned into a real value\"\n"
" },\n"
" Option::None(_) => {\n"
" let mut data = ArrayTrait::new();\n"
@@ -4215,27 +4350,27 @@ msgstr ""
"}\n"
"```"
-#: src/ch02-06-common-collections.md:121
+#: src/ch02-06-common-collections.md:126
msgid "#### Size related methods"
msgstr "#### Métodos relacionados con el tamaño"
-#: src/ch02-06-common-collections.md:123
+#: src/ch02-06-common-collections.md:128
msgid "To determine the number of elements in an array, use the `len()` method. The return is of type `usize`."
msgstr "Para determinar el número de elementos de un array, utilice el método `len()`. El valor devuelto es de tipo `usize`."
-#: src/ch02-06-common-collections.md:125
+#: src/ch02-06-common-collections.md:130
msgid "If you want to check if an array is empty or not, you can use the `is_empty()` method, which returns `true` if the array is empty and `false` otherwise."
msgstr "Si quieres comprobar si un array está vacío o no, puedes utilizar el método `is_empty()`, que devuelve `true` si el array está vacío y `false` en caso contrario."
-#: src/ch02-06-common-collections.md:127
+#: src/ch02-06-common-collections.md:132
msgid "#### Storing multiple types with Enums"
msgstr "#### Almacenar multiples tipos con Enums"
-#: src/ch02-06-common-collections.md:129
+#: src/ch02-06-common-collections.md:134
msgid "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."
msgstr "Si desea almacenar elementos de diferentes tipos en una array, puede utilizar un `Enum` para definir un tipo de datos personalizado que pueda contener múltiples tipos."
-#: src/ch02-06-common-collections.md:131
+#: src/ch02-06-common-collections.md:136
msgid ""
"```rust\n"
"use array::ArrayTrait;\n"
@@ -4250,9 +4385,9 @@ msgid ""
"\n"
"fn main() {\n"
" let mut messages: Array = ArrayTrait::new();\n"
-" messages.append(Data::Integer(100_u128));\n"
+" messages.append(Data::Integer(100));\n"
" messages.append(Data::Felt('hello world'));\n"
-" messages.append(Data::Tuple((10_u32, 30_u32)));\n"
+" messages.append(Data::Tuple((10, 30)));\n"
"}\n"
"```"
msgstr ""
@@ -4269,17 +4404,17 @@ msgstr ""
"\n"
"fn main() {\n"
" let mut messages: Array = ArrayTrait::new();\n"
-" messages.append(Data::Integer(100_u128));\n"
+" messages.append(Data::Integer(100));\n"
" messages.append(Data::Felt('hello world'));\n"
-" messages.append(Data::Tuple((10_u32, 30_u32)));\n"
+" messages.append(Data::Tuple((10, 30)));\n"
"}\n"
"```"
-#: src/ch02-06-common-collections.md:150
+#: src/ch02-06-common-collections.md:155
msgid "#### Span"
msgstr "#### Span"
-#: src/ch02-06-common-collections.md:152
+#: src/ch02-06-common-collections.md:157
msgid ""
"`Span` is a struct that represents a snapshot of an `Array`. It is designed to provide safe and controlled access to the elements of an array without modifying the original array. "
"Span is particularly useful for ensuring data integrity and avoiding borrowing issues when passing arrays between functions or when performing read-only operations (cf. [References "
@@ -4289,33 +4424,43 @@ msgstr ""
"array original. Span es particularmente útil para asegurar la integridad de los datos y evitar problemas de préstamo cuando se pasan arrays entre funciones o cuando se realizan "
"operaciones de sólo lectura (cf. [References and Snapshots](ch03-02-references-and-snapshots.md))"
-#: src/ch02-06-common-collections.md:154
+#: src/ch02-06-common-collections.md:159
msgid "All methods provided by `Array` can also be used with `Span`, with the exception of the `append()` method."
msgstr "Todos los métodos proporcionados por `Array` también se pueden utilizar con `Span`, a excepción del método `append()`."
-#: src/ch02-06-common-collections.md:156
+#: src/ch02-06-common-collections.md:161
msgid "##### Turning an Array into span"
msgstr "##### Convertir un Array en span"
-#: src/ch02-06-common-collections.md:158
+#: src/ch02-06-common-collections.md:163
msgid "To create a `Span` of an `Array`, call the `span()` method:"
msgstr "To create a `Span` of an `Array`, call the `span()` method:"
-#: src/ch02-06-common-collections.md:160
+#: src/ch02-06-common-collections.md:165
msgid ""
"```rust\n"
-"let span = array.span();\n"
+"# use array::ArrayTrait;\n"
+"# \n"
+"# fn main() {\n"
+"# let mut array = ArrayTrait::new();\n"
+" array.span()\n"
+"# }\n"
"```"
msgstr ""
"```rust\n"
-"let span = array.span();\n"
+"# use array::ArrayTrait;\n"
+"# \n"
+"# fn main() {\n"
+"# let mut array = ArrayTrait::new();\n"
+" array.span()\n"
+"# }\n"
"```"
-#: src/ch02-06-common-collections.md:164 src/ch04-03-method-syntax.md:286 src/ch06-05-separating-modules-into-different-files.md:98
+#: src/ch02-06-common-collections.md:174 src/ch04-03-method-syntax.md:286 src/ch06-05-separating-modules-into-different-files.md:99
msgid "## Summary"
msgstr "## Resumen"
-#: src/ch02-06-common-collections.md:166
+#: src/ch02-06-common-collections.md:176
msgid ""
"You made it! This was a sizable chapter: you learned about variables, data types, functions, comments,\n"
"`if` expressions, loops, and common collections! To practice with the concepts discussed in this chapter,\n"
@@ -4325,7 +4470,7 @@ msgstr ""
"expresiones `if`, bucles y colecciones comunes. Para practicar con los conceptos discutidos en este capítulo,\n"
"intenta construir programas para hacer lo siguiente:"
-#: src/ch02-06-common-collections.md:170
+#: src/ch02-06-common-collections.md:180
msgid ""
"- Generate the _n_-th Fibonacci number.\n"
"- Compute the factorial of a number _n_."
@@ -4333,7 +4478,7 @@ msgstr ""
"- Generar el _n_-th número de Fibonacci.\n"
"- Calcular el factorial de un número _n_."
-#: src/ch02-06-common-collections.md:173
+#: src/ch02-06-common-collections.md:183
msgid ""
"When you’re ready to move on, we’ll talk about a concept that Cairo shares with Rust and that _doesn’t_\n"
"commonly exist in other programming languages: ownership."
@@ -4456,32 +4601,36 @@ msgstr ""
#: src/ch03-01-what-is-ownership.md:39
msgid ""
"```rust\n"
+"# fn main() {\n"
" { // s is not valid here, it’s not yet declared\n"
" let s = 'hello'; // s is valid from this point forward\n"
"\n"
" // do stuff with s\n"
" } // this scope is now over, and s is no longer valid\n"
+"# }\n"
"```"
msgstr ""
"```rust\n"
+"# fn main() {\n"
" { // s is not valid here, it’s not yet declared\n"
" let s = 'hello'; // s is valid from this point forward\n"
"\n"
" // do stuff with s\n"
" } // this scope is now over, and s is no longer valid\n"
+"# }\n"
"```"
-#: src/ch03-01-what-is-ownership.md:47
+#: src/ch03-01-what-is-ownership.md:49
msgid ""
"Listing 3-1: A variable and the scope in which it is\n"
"valid"
msgstr "Lista 3-1: Una variable y el ámbito en el que es válida"
-#: src/ch03-01-what-is-ownership.md:50
+#: src/ch03-01-what-is-ownership.md:52
msgid "In other words, there are two important points in time here:"
msgstr "En otras palabras, hay dos puntos importantes en el tiempo aquí:"
-#: src/ch03-01-what-is-ownership.md:52
+#: src/ch03-01-what-is-ownership.md:54
msgid ""
"- When `s` comes _into_ scope, it is valid.\n"
"- It remains valid until it goes _out of_ scope."
@@ -4489,7 +4638,7 @@ msgstr ""
"- Cuando `s` entra en el _ámbito_, es válida.\n"
"- Permanece válida hasta que sale del _ámbito_."
-#: src/ch03-01-what-is-ownership.md:55
+#: src/ch03-01-what-is-ownership.md:57
msgid ""
"At this point, the relationship between scopes and when variables are valid is\n"
"similar to that in other programming languages. Now we’ll build on top of this\n"
@@ -4499,11 +4648,11 @@ msgstr ""
"similar a la de otros lenguajes de programación. Ahora nos basaremos en este\n"
"utilizando el tipo `Array` que introdujimos en el [capítulo anterior](ch02-06-common-collections.md)."
-#: src/ch03-01-what-is-ownership.md:59
+#: src/ch03-01-what-is-ownership.md:61
msgid "### Ownership with the `Array` Type"
msgstr "### Ownership con el tipo `Array"
-#: src/ch03-01-what-is-ownership.md:61
+#: src/ch03-01-what-is-ownership.md:63
msgid ""
"To illustrate the rules of ownership, we need a data type that is more complex.\n"
"The types covered in the [“Data Types”][data-types] section\n"
@@ -4511,35 +4660,40 @@ msgid ""
"quickly and trivially copied to make a new, independent instance if another\n"
"part of code needs to use the same value in a different scope, and can easily\n"
"be dropped when they're no longer used. But what is the behavior with the `Array` type whose size\n"
-"is unknown at compile time and which can't be trivially copied ?"
+"is unknown at compile time and which can't be trivially copied?"
msgstr ""
-"Para ilustrar las reglas de propiedad, necesitamos un tipo de datos que sea más complejo.\n"
-"Los tipos cubiertos en la sección [\"Tipos de datos\"][data-types]\n"
-"del capítulo 2 tienen un tamaño conocido, pueden ser\n"
-"pueden copiarse rápida y trivialmente para crear una instancia nueva e\n"
-"si otra parte del código necesita utilizar el mismo valor en un ámbito diferente, y pueden\n"
-"cuando ya no se utilizan. Pero ¿cuál es el comportamiento con el tipo `Array` cuyo tamaño\n"
-"es desconocido en tiempo de compilación y que no puede copiarse trivialmente?"
+"Para ilustrar las reglas de propiedad, necesitamos un tipo de datos más complejo. \n"
+"Los tipos cubiertos en la sección [\"Tipos de datos\"][data-types]section\n"
+"el Capítulo 2 son de un tamaño conocido, pueden ser copiados rápidamente y trivialmente para crear una nueva instancia independiente si otra \n"
+"parte del código necesita usar el mismo valor en un ámbito diferente, y pueden ser fácilmente\n"
+"eliminados cuando ya no se usan. Pero, ¿cuál es el comportamiento con el tipo `Array`, cuyo tamaño\n"
+"es desconocido en tiempo de compilación y no puede ser copiado trivialmente?"
-#: src/ch03-01-what-is-ownership.md:69
+#: src/ch03-01-what-is-ownership.md:71
msgid "Here is a short reminder of what an array looks like:"
msgstr "Aquí tienes un breve recordatorio de cómo es un array:"
-#: src/ch03-01-what-is-ownership.md:71
+#: src/ch03-01-what-is-ownership.md:73
msgid ""
"```rust\n"
-"let mut arr = ArrayTrait::::new();\n"
-"arr.append(1);\n"
-"arr.append(2);\n"
+"# use array::ArrayTrait;\n"
+"# fn main() {\n"
+" let mut arr = ArrayTrait::::new();\n"
+" arr.append(1);\n"
+" arr.append(2);\n"
+"# }\n"
"```"
msgstr ""
"```rust\n"
-"let mut arr = ArrayTrait::::new();\n"
-"arr.append(1);\n"
-"arr.append(2);\n"
+"# use array::ArrayTrait;\n"
+"# fn main() {\n"
+" let mut arr = ArrayTrait::::new();\n"
+" arr.append(1);\n"
+" arr.append(2);\n"
+"# }\n"
"```"
-#: src/ch03-01-what-is-ownership.md:77
+#: src/ch03-01-what-is-ownership.md:82
msgid ""
"So, how does the ownership system ensure that each cell is never written to more than once?\n"
"Consider the following code, where we try to pass the same instance of an array in two consecutive\n"
@@ -4549,15 +4703,13 @@ msgstr ""
"Consideremos el siguiente código, en el que intentamos pasar la misma instancia de un array en dos llamadas consecutivas a la función\n"
"consecutivas:"
-#: src/ch03-01-what-is-ownership.md:81
+#: src/ch03-01-what-is-ownership.md:86
msgid ""
"```rust,does_not_compile\n"
"use array::ArrayTrait;\n"
-"fn foo(arr: Array) {\n"
-"}\n"
+"fn foo(arr: Array) {}\n"
"\n"
-"fn bar(arr:Array){\n"
-"}\n"
+"fn bar(arr: Array) {}\n"
"\n"
"fn main() {\n"
" let mut arr = ArrayTrait::::new();\n"
@@ -4568,11 +4720,9 @@ msgid ""
msgstr ""
"```rust,does_not_compile\n"
"use array::ArrayTrait;\n"
-"fn foo(arr: Array) {\n"
-"}\n"
+"fn foo(arr: Array) {}\n"
"\n"
-"fn bar(arr:Array){\n"
-"}\n"
+"fn bar(arr: Array) {}\n"
"\n"
"fn main() {\n"
" let mut arr = ArrayTrait::::new();\n"
@@ -4581,7 +4731,7 @@ msgstr ""
"}\n"
"```"
-#: src/ch03-01-what-is-ownership.md:96
+#: src/ch03-01-what-is-ownership.md:99
msgid ""
"In this case, we try to pass the same array instance `arr` by value to the functions `foo` and `bar`, which means\n"
"that the parameter used in both function calls is the same instance of the array. If you append a value to the array\n"
@@ -4599,11 +4749,11 @@ msgstr ""
"`bar` con `arr` como parámetro, la propiedad de `arr` ya se movió a la primera llamada. El sistema de propiedad nos impide usar \n"
"la misma instancia de `arr` en `foo`."
-#: src/ch03-01-what-is-ownership.md:104
+#: src/ch03-01-what-is-ownership.md:107
msgid "Running the code above will result in a compile-time error:"
msgstr "Ejecutar el código anterior resultará en un error en tiempo de compilación:"
-#: src/ch03-01-what-is-ownership.md:106
+#: src/ch03-01-what-is-ownership.md:109
msgid ""
"```console\n"
"error: Variable was previously moved. Trait has no implementation in context: core::traits::Copy::>\n"
@@ -4619,11 +4769,11 @@ msgstr ""
" ^*****^\n"
"```"
-#: src/ch03-01-what-is-ownership.md:113
+#: src/ch03-01-what-is-ownership.md:116
msgid "### The `Copy` Trait"
msgstr "### El Trait `Copy`"
-#: src/ch03-01-what-is-ownership.md:115
+#: src/ch03-01-what-is-ownership.md:118
msgid ""
"If a type implements the `Copy` trait, passing it to a function will not move the ownership of the value to the function called, but will instead pass a copy of the value.\n"
"You can implement the `Copy` trait on your type by adding the `#[derive(Copy)]` annotation to your type definition. However, Cairo won't allow a type to be annotated with Copy if the "
@@ -4635,9 +4785,9 @@ msgstr ""
"si el tipo en sí mismo o cualquiera de sus componentes no implementan el trait `Copy`.\n"
"Mientras que los Arrays y Diccionarios no pueden ser copiados, los tipos personalizados que no los contienen sí pueden serlo."
-#: src/ch03-01-what-is-ownership.md:119
+#: src/ch03-01-what-is-ownership.md:122
msgid ""
-"```rust\n"
+"```rust,ignore_format\n"
"#[derive(Copy, Drop)]\n"
"struct Point {\n"
" x: u128,\n"
@@ -4655,7 +4805,7 @@ msgid ""
"}\n"
"```"
msgstr ""
-"```rust\n"
+"```rust,ignore_format\n"
"#[derive(Copy, Drop)]\n"
"struct Point {\n"
" x: u128,\n"
@@ -4673,7 +4823,7 @@ msgstr ""
"}\n"
"```"
-#: src/ch03-01-what-is-ownership.md:137
+#: src/ch03-01-what-is-ownership.md:140
msgid ""
"In this example, we can pass `p1` twice to the foo function because the `Point` type implements the `Copy` trait. This means that when we pass `p1` to `foo`, we are actually passing "
"a copy of `p1`, and the ownership of `p1` remains with the main function.\n"
@@ -4683,15 +4833,15 @@ msgstr ""
"estamos pasando una copia de `p1`, y la propiedad de `p1` permanece en la función principal.\n"
"Si eliminamos la derivación del trait `Copy` del tipo `Point`, obtendremos un error en tiempo de compilación al intentar compilar el código."
-#: src/ch03-01-what-is-ownership.md:140
+#: src/ch03-01-what-is-ownership.md:143
msgid "_Don't worry about the `Struct` keyword. We will introduce this in [Chapter 4](ch04-00-using-structs-to-structure-related-data.md)._"
msgstr "_No te preocupes por la palabra clave `Struct`. La introduciremos en el [Capítulo 4](ch04-00-using-structs-to-structure-related-data.md)._"
-#: src/ch03-01-what-is-ownership.md:142
+#: src/ch03-01-what-is-ownership.md:145
msgid "### The `Drop` Trait"
msgstr "### El Trait `Drop`"
-#: src/ch03-01-what-is-ownership.md:144
+#: src/ch03-01-what-is-ownership.md:147
msgid ""
"You may have noticed that the `Point` type in the previous example also implements the `Drop` trait. In Cairo, a value cannot go out of scope unless it has been previously moved.\n"
"For example, the following code will not compile, because the struct `A` is not moved before it goes out of scope:"
@@ -4700,7 +4850,7 @@ msgstr ""
"previamente.\n"
"Por ejemplo, el siguiente código no se compilará porque la estructura `A` no se mueve antes de que salga del ámbito:"
-#: src/ch03-01-what-is-ownership.md:147
+#: src/ch03-01-what-is-ownership.md:150
msgid ""
"```rust,does_not_compile\n"
"struct A {}\n"
@@ -4718,25 +4868,25 @@ msgstr ""
"}\n"
"```"
-#: src/ch03-01-what-is-ownership.md:155
+#: src/ch03-01-what-is-ownership.md:158
msgid ""
"This is to ensure the soundness of Cairo programs. Soundness refers to the fact that if a\n"
"statement during the execution of the program is false, no cheating prover can convince an\n"
"honest verifier that it is true. In our case, we want to ensure the consistency of\n"
"consecutive dictionary key updates during program execution, which is only checked when\n"
-"the dictionaries are`squashed` - which moves the ownership of the dictionary to the\n"
+"the dictionaries are `squashed` - which moves the ownership of the dictionary to the\n"
"`squash` method, thus allowing the dictionary to go out of scope. Unsquashed dictionaries\n"
"are dangerous, as a malicious prover could prove the correctness of inconsistent updates."
msgstr ""
-"En Cairo, esto se hace para garantizar la solidez de los programas. La solidez se refiere al hecho de\n"
-" que si una declaración durante la ejecución del programa es falsa, ningún probador deshonesto puede\n"
-" convencer a un verificador honesto de que es verdadera. En nuestro caso, queremos asegurar la consistencia \n"
-"de las actualizaciones consecutivas de claves de un diccionario durante la ejecución del programa, lo cua\n"
-"l solo se verifica cuando los diccionarios se \"aplastan\" - lo que mueve la propiedad del diccionario al método `squash`, \n"
-"permitiendo que el diccionario salga de ámbito. Los diccionarios no \"aplastados\" son peligrosos, ya que un probador \n"
-"malintencionado podría probar la corrección de actualizaciones inconsistentes."
+"Con ello se pretende garantizar la solidez de los programas de Cairo. La solidez se refiere al hecho de que si una\n"
+"durante la ejecución del programa es falsa, ningún probador tramposo puede convencer a un verificador honesto de que es verdadera.\n"
+"verificador honesto de que es verdadera. En nuestro caso, queremos garantizar la coherencia de\n"
+"actualizaciones consecutivas de las claves del diccionario durante la ejecución del programa, que sólo se comprueba cuando\n"
+"los diccionarios son `squashed` - que mueve la propiedad del diccionario al método\n"
+"`squash`, lo que permite que el diccionario salga del ámbito. Los diccionarios Unsquashed\n"
+"son peligrosos, ya que un prover malicioso podría probar la corrección de actualizaciones inconsistentes."
-#: src/ch03-01-what-is-ownership.md:163
+#: src/ch03-01-what-is-ownership.md:166
msgid ""
"However, types that implement the `Drop` trait are allowed to go out of scope without being explicitly moved. When a value of a type that implements the `Drop` trait goes out of "
"scope, the `Drop` implementation is called on the type, which moves the value to the `drop` function, allowing it to go out of scope - This is what we call \"dropping\" a value.\n"
@@ -4748,17 +4898,17 @@ msgstr ""
"Es importante tener en cuenta que la implementación de `Drop` es una \"operación nula\", lo que significa que no realiza ninguna acción aparte de permitir que el valor salga de "
"ámbito."
-#: src/ch03-01-what-is-ownership.md:166
+#: src/ch03-01-what-is-ownership.md:169
msgid ""
-"The `Drop` implementation can be derived for all types, allowing them to be dropped when goint out of scope, except for dictionaries (`Felt252Dict`) and types containing "
+"The `Drop` implementation can be derived for all types, allowing them to be dropped when going out of scope, except for dictionaries (`Felt252Dict`) and types containing "
"dictionaries.\n"
"For example, the following code compiles:"
msgstr ""
-"La implementación de `Drop` se puede derivar para todos los tipos, lo que les permite eliminarse al salir de ámbito, excepto para los diccionarios (`Felt252Dict`) y los tipos que "
-"contienen diccionarios.\n"
+"La implementación `Drop` puede ser derivada para todos los tipos, permitiéndoles ser descartados cuando salen del ámbito, excepto para los diccionarios (`Felt252Dict`) y los tipos "
+"que contienen diccionarios.\n"
"Por ejemplo, el siguiente código compila:"
-#: src/ch03-01-what-is-ownership.md:169
+#: src/ch03-01-what-is-ownership.md:172
msgid ""
"```rust\n"
"#[derive(Drop)]\n"
@@ -4778,11 +4928,11 @@ msgstr ""
"}\n"
"```"
-#: src/ch03-01-what-is-ownership.md:178
+#: src/ch03-01-what-is-ownership.md:181
msgid "### The `Destruct` Trait"
msgstr "### El Trait `Destruct`"
-#: src/ch03-01-what-is-ownership.md:180
+#: src/ch03-01-what-is-ownership.md:183
msgid ""
"Manually calling the `squash` method on a dictionary is not very convenient, and it is easy to forget to do so. To make it easier to use dictionaries, Cairo provides the `Destruct` "
"trait, which allows you to specify the behavior of a type when it goes out of scope. While Dictionaries don't implement the `Drop` trait, they do implement the `Destruct` trait, "
@@ -4793,11 +4943,11 @@ msgstr ""
"`Destruct`, lo que les permite ser `aplastados` automáticamente cuando salen del ámbito. Esto significa que puedes usar diccionarios sin tener que llamar manualmente al método "
"`squash`."
-#: src/ch03-01-what-is-ownership.md:182
+#: src/ch03-01-what-is-ownership.md:185
msgid "Consider the following example, in which we define a custom type that contains a dictionary:"
msgstr "Considera el siguiente ejemplo, en el que definimos un tipo personalizado que contiene un diccionario:"
-#: src/ch03-01-what-is-ownership.md:184
+#: src/ch03-01-what-is-ownership.md:187
msgid ""
"```rust,does_not_compile\n"
"use dict::Felt252DictTrait;\n"
@@ -4807,9 +4957,7 @@ msgid ""
"}\n"
"\n"
"fn main() {\n"
-" A {\n"
-" dict: Felt252DictTrait::new()\n"
-" };\n"
+" A { dict: Felt252DictTrait::new() };\n"
"}\n"
"```"
msgstr ""
@@ -4821,17 +4969,15 @@ msgstr ""
"}\n"
"\n"
"fn main() {\n"
-" A {\n"
-" dict: Felt252DictTrait::new()\n"
-" };\n"
+" A { dict: Felt252DictTrait::new() };\n"
"}\n"
"```"
-#: src/ch03-01-what-is-ownership.md:198
+#: src/ch03-01-what-is-ownership.md:199
msgid "If you try to run this code, you will get a compile-time error:"
msgstr "Si intenta ejecutar este código, obtendrá un error de tiempo de compilación:"
-#: src/ch03-01-what-is-ownership.md:200
+#: src/ch03-01-what-is-ownership.md:201
msgid ""
"```console\n"
"error: Variable not dropped. Trait has no implementation in context: core::traits::Drop::. Trait has no implementation in context: core::traits::Destruct:: Note: in the following example, we need to import the `Clone` trait from the corelib `clone` module, and its implementation for the array type from the `array` module."
msgstr ""
"> Nota: en el siguiente ejemplo, necesitamos importar el rasgo `Clone` del módulo `clone` de la biblioteca estándar, y su implementación para el tipo `array` del módulo `array`."
-#: src/ch03-01-what-is-ownership.md:235
+#: src/ch03-01-what-is-ownership.md:234
msgid ""
"```rust\n"
"use array::ArrayTrait;\n"
"use clone::Clone;\n"
"use array::ArrayTCloneImpl;\n"
-"...\n"
-"let arr1 = ArrayTrait::::new();\n"
-"let arr2 = arr1.clone();\n"
-"\n"
+"fn main() {\n"
+" let arr1 = ArrayTrait::::new();\n"
+" let arr2 = arr1.clone();\n"
+"}\n"
"```"
msgstr ""
"```rust\n"
"use array::ArrayTrait;\n"
"use clone::Clone;\n"
"use array::ArrayTCloneImpl;\n"
-"...\n"
-"let arr1 = ArrayTrait::::new();\n"
-"let arr2 = arr1.clone();\n"
-"\n"
+"fn main() {\n"
+" let arr1 = ArrayTrait::::new();\n"
+" let arr2 = arr1.clone();\n"
+"}\n"
"```"
-#: src/ch03-01-what-is-ownership.md:245
+#: src/ch03-01-what-is-ownership.md:244
msgid "> Note: you will need to run `cairo-run` with the `--available-gas=2000000` option to run this example, because it uses a loop and must be ran with a gas limit."
msgstr "> Nota: necesitarás ejecutar `cairo-run` con la opción `--available-gas=2000000` para ejecutar este ejemplo, ya que utiliza un bucle y debe ser ejecutado con un límite de gas."
-#: src/ch03-01-what-is-ownership.md:247
+#: src/ch03-01-what-is-ownership.md:246
msgid ""
"When you see a call to `clone`, you know that some arbitrary code is being\n"
"executed and that code may be expensive. It’s a visual indicator that something\n"
@@ -4950,11 +5092,11 @@ msgstr ""
"Cuando ves una llamada a `clone`, sabes que se está ejecutando algún código arbitrario\n"
" y ese código puede ser costoso. Es un indicador visual de que algo diferente está sucediendo."
-#: src/ch03-01-what-is-ownership.md:251
+#: src/ch03-01-what-is-ownership.md:250
msgid "### Ownership and Functions"
msgstr "### Ownership y Funciones"
-#: src/ch03-01-what-is-ownership.md:253
+#: src/ch03-01-what-is-ownership.md:252
msgid ""
"Passing a variable to a function will either move it or copy it. As seen in the Array section, passing an `Array` as a function parameter transfers its ownership; let's see what "
"happens with other types."
@@ -4962,7 +5104,7 @@ msgstr ""
"Pasar una variable a una función puede moverla o copiarla. Como se vio en la sección de Array, pasar un `Array` como parámetro de función transfiere su propiedad; veamos qué sucede "
"con otros tipos."
-#: src/ch03-01-what-is-ownership.md:255
+#: src/ch03-01-what-is-ownership.md:254
msgid ""
"Listing 3-3 has an example with some annotations\n"
"showing where variables go into and out of scope."
@@ -4970,13 +5112,13 @@ msgstr ""
"El Listado 3-3 tiene un ejemplo con algunas anotaciones \n"
"que muestran dónde las variables entran y salen de ámbito."
-#: src/ch03-01-what-is-ownership.md:258 src/ch03-01-what-is-ownership.md:300 src/ch03-01-what-is-ownership.md:353
+#: src/ch03-01-what-is-ownership.md:257 src/ch03-01-what-is-ownership.md:299 src/ch03-01-what-is-ownership.md:352
msgid "Filename: src/main.cairo"
msgstr "Filename: src/main.cairo"
-#: src/ch03-01-what-is-ownership.md:260
+#: src/ch03-01-what-is-ownership.md:259
msgid ""
-"```rust\n"
+"```rust,ignore_format\n"
"#[derive(Drop)]\n"
"struct MyStruct{}\n"
"\n"
@@ -4986,7 +5128,7 @@ msgid ""
" takes_ownership(my_struct); // my_struct's value moves into the function...\n"
" // ... and so is no longer valid here\n"
"\n"
-" let x = 5_u128; // x comes into scope\n"
+" let x = 5; // x comes into scope\n"
"\n"
" makes_copy(x); // x would move into the function,\n"
" // but u128 implements Copy, so it is okay to still\n"
@@ -5002,7 +5144,7 @@ msgid ""
"} // Here, some_integer goes out of scope and is dropped.\n"
"```"
msgstr ""
-"```rust\n"
+"```rust,ignore_format\n"
"#[derive(Drop)]\n"
"struct MyStruct{}\n"
"\n"
@@ -5012,7 +5154,7 @@ msgstr ""
" takes_ownership(my_struct); // my_struct's value moves into the function...\n"
" // ... and so is no longer valid here\n"
"\n"
-" let x = 5_u128; // x comes into scope\n"
+" let x = 5; // x comes into scope\n"
"\n"
" makes_copy(x); // x would move into the function,\n"
" // but u128 implements Copy, so it is okay to still\n"
@@ -5028,7 +5170,7 @@ msgstr ""
"} // Here, some_integer goes out of scope and is dropped.\n"
"```"
-#: src/ch03-01-what-is-ownership.md:286
+#: src/ch03-01-what-is-ownership.md:285
msgid ""
"Listing 3-3: Functions with ownership and scope\n"
"annotated"
@@ -5036,7 +5178,7 @@ msgstr ""
"Listing 3-3: Functions with ownership and scope\n"
"annotated"
-#: src/ch03-01-what-is-ownership.md:289
+#: src/ch03-01-what-is-ownership.md:288
msgid ""
"If we tried to use `my_struct` after the call to `takes_ownership`, Cairo would throw a\n"
"compile-time error. These static checks protect us from mistakes. Try adding\n"
@@ -5048,11 +5190,11 @@ msgstr ""
"agregar código a `main` que use `my_struct` y `x` para ver dónde puedes usarlos y dónde las \n"
"reglas de propiedad te impiden hacerlo."
-#: src/ch03-01-what-is-ownership.md:294
+#: src/ch03-01-what-is-ownership.md:293
msgid "### Return Values and Scope"
msgstr "### Valores de retorno y alcance"
-#: src/ch03-01-what-is-ownership.md:296
+#: src/ch03-01-what-is-ownership.md:295
msgid ""
"Returning values can also transfer ownership. Listing 3-4 shows an example of a\n"
"function that returns some value, with similar annotations as those in Listing\n"
@@ -5061,17 +5203,17 @@ msgstr ""
"La devolución de valores también puede transferir la propiedad. El Listado 3-4 muestra \n"
"un ejemplo de una función que devuelve algún valor, con anotaciones similares a las del Listado 4-3."
-#: src/ch03-01-what-is-ownership.md:302
+#: src/ch03-01-what-is-ownership.md:301
msgid ""
-"```rust\n"
+"```rust,ignore_format\n"
"#[derive(Drop)]\n"
-"struct A{}\n"
+"struct A {}\n"
"\n"
"fn main() {\n"
" let a1 = gives_ownership(); // gives_ownership moves its return\n"
" // value into a1\n"
"\n"
-" let a2 = A{}; // a2 comes into scope\n"
+" let a2 = A {}; // a2 comes into scope\n"
"\n"
" let a3 = takes_and_gives_back(a2); // a2 is moved into\n"
" // takes_and_gives_back, which also\n"
@@ -5084,7 +5226,7 @@ msgid ""
" // return value into the function\n"
" // that calls it\n"
"\n"
-" let some_a = A{}; // some_a comes into scope\n"
+" let some_a = A {}; // some_a comes into scope\n"
"\n"
" some_a // some_a is returned and\n"
" // moves ownership to the calling\n"
@@ -5101,15 +5243,15 @@ msgid ""
"}\n"
"```"
msgstr ""
-"```rust\n"
+"```rust,ignore_format\n"
"#[derive(Drop)]\n"
-"struct A{}\n"
+"struct A {}\n"
"\n"
"fn main() {\n"
" let a1 = gives_ownership(); // gives_ownership moves its return\n"
" // value into a1\n"
"\n"
-" let a2 = A{}; // a2 comes into scope\n"
+" let a2 = A {}; // a2 comes into scope\n"
"\n"
" let a3 = takes_and_gives_back(a2); // a2 is moved into\n"
" // takes_and_gives_back, which also\n"
@@ -5122,7 +5264,7 @@ msgstr ""
" // return value into the function\n"
" // that calls it\n"
"\n"
-" let some_a = A{}; // some_a comes into scope\n"
+" let some_a = A {}; // some_a comes into scope\n"
"\n"
" some_a // some_a is returned and\n"
" // moves ownership to the calling\n"
@@ -5139,7 +5281,7 @@ msgstr ""
"}\n"
"```"
-#: src/ch03-01-what-is-ownership.md:340
+#: src/ch03-01-what-is-ownership.md:339
msgid ""
"Listing 3-4: Transferring ownership of return\n"
"values"
@@ -5147,11 +5289,11 @@ msgstr ""
"Listado 3-4: Transferencia de propiedad de \n"
"valores devueltos"
-#: src/ch03-01-what-is-ownership.md:343
+#: src/ch03-01-what-is-ownership.md:342
msgid "When a variable goes out of scope, its value is dropped, unless ownership of the value has been moved to another variable."
msgstr "Cuando una variable sale del ámbito, su valor se elimina, a menos que la propiedad del valor se haya transferido a otra variable."
-#: src/ch03-01-what-is-ownership.md:345
+#: src/ch03-01-what-is-ownership.md:344
msgid ""
"While this works, taking ownership and then returning ownership with every\n"
"function is a bit tedious. What if we want to let a function use a value but\n"
@@ -5165,11 +5307,11 @@ msgstr ""
"también deba ser devuelto si queremos usarlo nuevamente, además de cualquier\n"
" dato que resulte del cuerpo de la función que también podríamos querer devolver."
-#: src/ch03-01-what-is-ownership.md:351
+#: src/ch03-01-what-is-ownership.md:350
msgid "Cairo does let us return multiple values using a tuple, as shown in Listing 3-5."
msgstr "Cairo nos permite devolver múltiples valores usando una tupla, como se muestra en el Listado 3-5."
-#: src/ch03-01-what-is-ownership.md:355
+#: src/ch03-01-what-is-ownership.md:354
msgid ""
"```rust\n"
"use array::ArrayTrait;\n"
@@ -5201,11 +5343,11 @@ msgstr ""
"}\n"
"```"
-#: src/ch03-01-what-is-ownership.md:370
+#: src/ch03-01-what-is-ownership.md:369
msgid "Listing 3-5: Returning ownership of parameters"
msgstr "Listado 3-5: Devolviendo propiedad de los parámetros"
-#: src/ch03-01-what-is-ownership.md:372
+#: src/ch03-01-what-is-ownership.md:371
msgid ""
"But this is too much ceremony and a lot of work for a concept that should be\n"
"common. Luckily for us, Cairo has two features for using a value without\n"
@@ -5267,15 +5409,17 @@ msgstr ""
#: src/ch03-02-references-and-snapshots.md:25
msgid ""
-"```rust\n"
+"```rust,ignore_format\n"
"use array::ArrayTrait;\n"
"use debug::PrintTrait;\n"
"\n"
"fn main() {\n"
" let mut arr1 = ArrayTrait::::new();\n"
" let first_snapshot = @arr1; // Take a snapshot of `arr1` at this point in time\n"
-" arr1.append(1_u128); // Mutate `arr1` by appending a value\n"
-" let first_length = calculate_length(first_snapshot); // Calculate the length of the array when the snapshot was taken\n"
+" arr1.append(1); // Mutate `arr1` by appending a value\n"
+" let first_length = calculate_length(\n"
+" first_snapshot\n"
+" ); // Calculate the length of the array when the snapshot was taken\n"
" let second_length = calculate_length(@arr1); // Calculate the current length of the array\n"
" first_length.print();\n"
" second_length.print();\n"
@@ -5286,15 +5430,17 @@ msgid ""
"}\n"
"```"
msgstr ""
-"```rust\n"
+"```rust,ignore_format\n"
"use array::ArrayTrait;\n"
"use debug::PrintTrait;\n"
"\n"
"fn main() {\n"
" let mut arr1 = ArrayTrait::::new();\n"
" let first_snapshot = @arr1; // Take a snapshot of `arr1` at this point in time\n"
-" arr1.append(1_u128); // Mutate `arr1` by appending a value\n"
-" let first_length = calculate_length(first_snapshot); // Calculate the length of the array when the snapshot was taken\n"
+" arr1.append(1); // Mutate `arr1` by appending a value\n"
+" let first_length = calculate_length(\n"
+" first_snapshot\n"
+" ); // Calculate the length of the array when the snapshot was taken\n"
" let second_length = calculate_length(@arr1); // Calculate the current length of the array\n"
" first_length.print();\n"
" second_length.print();\n"
@@ -5305,7 +5451,7 @@ msgstr ""
"}\n"
"```"
-#: src/ch03-02-references-and-snapshots.md:44
+#: src/ch03-02-references-and-snapshots.md:46
msgid ""
"> Note: It is only possible to call the `len()` method on an array snapshot because it is defined as such in the `ArrayTrait` trait. If you try to call a method that is not defined "
"for snapshots on a snapshot, you will get a compilation error. However, you can call methods expecting a snapshot on non-snapshot types."
@@ -5313,11 +5459,11 @@ msgstr ""
"> Nota: Solo es posible llamar al método `len()` en un snapshot de un array porque está definido así en el trait `ArrayTrait`. Si intentas llamar a un método que no está definido "
"para snapshots en un snapshot, obtendrás un error de compilación. Sin embargo, puedes llamar a métodos que esperan un snapshot en tipos que no son snapshots."
-#: src/ch03-02-references-and-snapshots.md:46
+#: src/ch03-02-references-and-snapshots.md:48
msgid "The output of this program is:"
msgstr "La salida de este programa es:"
-#: src/ch03-02-references-and-snapshots.md:48
+#: src/ch03-02-references-and-snapshots.md:50
msgid ""
"```console\n"
"[DEBUG]\t \t(raw: 0)\n"
@@ -5335,7 +5481,7 @@ msgstr ""
"Run completed successfully, returning []\n"
"```"
-#: src/ch03-02-references-and-snapshots.md:56
+#: src/ch03-02-references-and-snapshots.md:58
msgid ""
"First, notice that all the tuple code in the variable declaration and the function return value is gone. Second, note\n"
"that we pass `@arr1` into `calculate_length` and, in its definition, we take `@Array` rather than `Array`."
@@ -5344,23 +5490,55 @@ msgstr ""
"ha desaparecido. La segunda observación es que pasamos `@arr1` a `calculate_length` y, en su definición, tomamos\n"
" `@Array` en lugar de `Array`."
-#: src/ch03-02-references-and-snapshots.md:59
+#: src/ch03-02-references-and-snapshots.md:61
msgid "Let’s take a closer look at the function call here:"
msgstr "Veamos más de cerca la llamada a la función aquí:"
-#: src/ch03-02-references-and-snapshots.md:61
+#: src/ch03-02-references-and-snapshots.md:63
msgid ""
"```rust\n"
-"let mut arr1 = ArrayTrait::::new();\n"
-"let second_length = calculate_length(@arr1); // Calculate the current length of the array\n"
-"```"
-msgstr ""
-"```rust\n"
-"let mut arr1 = ArrayTrait::::new();\n"
-"let second_length = calculate_length(@arr1); // Calculate the current length of the array\n"
+"# use array::ArrayTrait;\n"
+"# use debug::PrintTrait;\n"
+"# \n"
+"# fn main() {\n"
+"# let mut arr1 = ArrayTrait::::new();\n"
+"# let first_snapshot = @arr1; // Take a snapshot of `arr1` at this point in time\n"
+"# arr1.append(1); // Mutate `arr1` by appending a value\n"
+"# let first_length = calculate_length(\n"
+"# first_snapshot\n"
+"# ); // Calculate the length of the array when the snapshot was taken\n"
+" let second_length = calculate_length(@arr1); // Calculate the current length of the array\n"
+"# first_length.print();\n"
+"# second_length.print();\n"
+"# }\n"
+"# \n"
+"# fn calculate_length(arr: @Array) -> usize {\n"
+"# arr.len()\n"
+"# }\n"
+"```"
+msgstr ""
+"```rust\n"
+"# use array::ArrayTrait;\n"
+"# use debug::PrintTrait;\n"
+"# \n"
+"# fn main() {\n"
+"# let mut arr1 = ArrayTrait::::new();\n"
+"# let first_snapshot = @arr1; // Take a snapshot of `arr1` at this point in time\n"
+"# arr1.append(1); // Mutate `arr1` by appending a value\n"
+"# let first_length = calculate_length(\n"
+"# first_snapshot\n"
+"# ); // Calculate the length of the array when the snapshot was taken\n"
+" let second_length = calculate_length(@arr1); // Calculate the current length of the array\n"
+"# first_length.print();\n"
+"# second_length.print();\n"
+"# }\n"
+"# \n"
+"# fn calculate_length(arr: @Array) -> usize {\n"
+"# arr.len()\n"
+"# }\n"
"```"
-#: src/ch03-02-references-and-snapshots.md:66
+#: src/ch03-02-references-and-snapshots.md:84
msgid ""
"The `@arr1` syntax lets us create a snapshot of the value in `arr1`. Because a snapshot is an immutable view of a value, the value it points to cannot be modified through the "
"snapshot, and the value it refers to will not be dropped once the snapshot stops being used."
@@ -5368,27 +5546,31 @@ msgstr ""
"La sintaxis `@arr1` nos permite crear una instantánea (snapshot) del valor en `arr1`. Como una instantánea es una vista inmutable de un valor, el valor al que apunta no puede ser "
"modificado a través de la instantánea y el valor al que se refiere no será eliminado una vez que la instantánea deje de ser usada."
-#: src/ch03-02-references-and-snapshots.md:68
+#: src/ch03-02-references-and-snapshots.md:86
msgid "Similarly, the signature of the function uses `@` to indicate that the type of the parameter `arr` is a snapshot. Let’s add some explanatory annotations:"
msgstr "De manera similar, la firma de la función utiliza `@` para indicar que el tipo del parámetro `arr` es una instantánea. Añadamos algunas anotaciones explicativas:"
-#: src/ch03-02-references-and-snapshots.md:70
+#: src/ch03-02-references-and-snapshots.md:88
msgid ""
"```rust\n"
-"fn calculate_length(array_snapshot: @Array) -> usize { // array_snapshot is a snapshot of an Array\n"
+"fn calculate_length(\n"
+" array_snapshot: @Array\n"
+") -> usize { // array_snapshot is a snapshot of an Array\n"
" array_snapshot.len()\n"
"} // Here, array_snapshot goes out of scope and is dropped.\n"
"// However, because it is only a view of what the original array `arr` contains, the original `arr` can still be used.\n"
"```"
msgstr ""
"```rust\n"
-"fn calculate_length(array_snapshot: @Array) -> usize { // array_snapshot is a snapshot of an Array\n"
+"fn calculate_length(\n"
+" array_snapshot: @Array\n"
+") -> usize { // array_snapshot is a snapshot of an Array\n"
" array_snapshot.len()\n"
"} // Here, array_snapshot goes out of scope and is dropped.\n"
"// However, because it is only a view of what the original array `arr` contains, the original `arr` can still be used.\n"
"```"
-#: src/ch03-02-references-and-snapshots.md:77
+#: src/ch03-02-references-and-snapshots.md:97
msgid ""
"The scope in which the variable `array_snapshot` is valid is the same as any function parameter’s scope, but the underlying value of the snapshot is not dropped when `array_snapshot` "
"stops being used. When functions have snapshots as parameters instead of the actual values, we won’t need to return the values in order to give back ownership of the original value, "
@@ -5398,7 +5580,7 @@ msgstr ""
"`array_snapshot` deje de usarse. Cuando las funciones tienen snapshots como parámetros en lugar de los valores reales, no necesitamos devolver los valores para devolver la propiedad "
"del valor original, porque nunca la tuvimos."
-#: src/ch03-02-references-and-snapshots.md:79
+#: src/ch03-02-references-and-snapshots.md:99
msgid ""
"Snapshots can be converted back into regular values using the `desnap` operator `*`, as long as the value type is copyable (which is not the case for Arrays, as they don't implement "
"`Copy`). In the following example, we want to calculate the area of a rectangle, but we don't want to take ownership of the rectangle in the `calculate_area` function, because we "
@@ -5410,26 +5592,25 @@ msgstr ""
"`calculate_area`, porque podríamos querer usar el rectángulo de nuevo después de la llamada a la función. Dado que nuestra función no muta la instancia del rectángulo, podemos pasar "
"el snapshot del rectángulo a la función, y luego transformar los snapshots de nuevo en valores usando el operador `desnap` `*`."
-#: src/ch03-02-references-and-snapshots.md:81
+#: src/ch03-02-references-and-snapshots.md:101
msgid "The snapshot type is always copyable and droppable, so that you can use it multiple times without worrying about ownership transfers."
msgstr "El tipo de snapshot siempre es copiable y eliminable, para que pueda usarlo varias veces sin preocuparse por las transferencias de propiedad."
-#: src/ch03-02-references-and-snapshots.md:83
+#: src/ch03-02-references-and-snapshots.md:103
msgid ""
"```rust\n"
"use debug::PrintTrait;\n"
"\n"
-"#[derive(Copy,Drop)]\n"
+"#[derive(Copy, Drop)]\n"
"struct Rectangle {\n"
" height: u64,\n"
" width: u64,\n"
"}\n"
"\n"
-"fn main(){\n"
-" let rec = Rectangle{height:3_u64, width:10_u64};\n"
+"fn main() {\n"
+" let rec = Rectangle { height: 3, width: 10 };\n"
" let area = calculate_area(@rec);\n"
" area.print();\n"
-"\n"
"}\n"
"\n"
"fn calculate_area(rec: @Rectangle) -> u64 {\n"
@@ -5444,17 +5625,16 @@ msgstr ""
"```rust\n"
"use debug::PrintTrait;\n"
"\n"
-"#[derive(Copy,Drop)]\n"
+"#[derive(Copy, Drop)]\n"
"struct Rectangle {\n"
" height: u64,\n"
" width: u64,\n"
"}\n"
"\n"
-"fn main(){\n"
-" let rec = Rectangle{height:3_u64, width:10_u64};\n"
+"fn main() {\n"
+" let rec = Rectangle { height: 3, width: 10 };\n"
" let area = calculate_area(@rec);\n"
" area.print();\n"
-"\n"
"}\n"
"\n"
"fn calculate_area(rec: @Rectangle) -> u64 {\n"
@@ -5466,7 +5646,7 @@ msgstr ""
"}\n"
"```"
-#: src/ch03-02-references-and-snapshots.md:108
+#: src/ch03-02-references-and-snapshots.md:127
msgid ""
"But, what happens if we try to modify something we’re passing as snapshot? Try the code in\n"
"Listing 3-6. Spoiler alert: it doesn’t work!"
@@ -5474,17 +5654,18 @@ msgstr ""
"Pero, ¿qué sucede si intentamos modificar algo que estamos pasando como instantánea? Prueba el código \n"
"en la Lista 3-6. ¡Alerta de spoiler: no funciona!"
-#: src/ch03-02-references-and-snapshots.md:113
+#: src/ch03-02-references-and-snapshots.md:132
msgid ""
"```rust,does_not_compile\n"
-"#[derive(Copy,Drop)]\n"
+"// does_not_compile\n"
+"#[derive(Copy, Drop)]\n"
"struct Rectangle {\n"
" height: u64,\n"
" width: u64,\n"
"}\n"
"\n"
-"fn main(){\n"
-" let rec = Rectangle{height:3_u64, width:10_u64};\n"
+"fn main() {\n"
+" let rec = Rectangle { height: 3, width: 10 };\n"
" flip(@rec);\n"
"}\n"
"\n"
@@ -5496,14 +5677,15 @@ msgid ""
"```"
msgstr ""
"```rust,does_not_compile\n"
-"#[derive(Copy,Drop)]\n"
+"// does_not_compile\n"
+"#[derive(Copy, Drop)]\n"
"struct Rectangle {\n"
" height: u64,\n"
" width: u64,\n"
"}\n"
"\n"
-"fn main(){\n"
-" let rec = Rectangle{height:3_u64, width:10_u64};\n"
+"fn main() {\n"
+" let rec = Rectangle { height: 3, width: 10 };\n"
" flip(@rec);\n"
"}\n"
"\n"
@@ -5514,15 +5696,15 @@ msgstr ""
"}\n"
"```"
-#: src/ch03-02-references-and-snapshots.md:132
+#: src/ch03-02-references-and-snapshots.md:152
msgid "Listing 3-6: Attempting to modify a snapshot value"
msgstr "Listado 3-6: Intentando modificar un valor de snapshot"
-#: src/ch03-02-references-and-snapshots.md:134
+#: src/ch03-02-references-and-snapshots.md:154
msgid "Here’s the error:"
msgstr "Aquí está el error:"
-#: src/ch03-02-references-and-snapshots.md:136
+#: src/ch03-02-references-and-snapshots.md:156
msgid ""
"```console\n"
"error: Invalid left-hand side of assignment.\n"
@@ -5538,15 +5720,15 @@ msgstr ""
" ^********^\n"
"```"
-#: src/ch03-02-references-and-snapshots.md:143
+#: src/ch03-02-references-and-snapshots.md:163
msgid "The compiler prevents us from modifying values associated to snapshots."
msgstr "El compilador nos impide modificar los valores asociados a las instantáneas."
-#: src/ch03-02-references-and-snapshots.md:145
+#: src/ch03-02-references-and-snapshots.md:165
msgid "### Mutable References"
msgstr "### Referencias Mutables"
-#: src/ch03-02-references-and-snapshots.md:147
+#: src/ch03-02-references-and-snapshots.md:167
msgid ""
"We can achieve the behavior we want in Listing 3-6 by using a _mutable reference_ instead of a snapshot. Mutable references are actually mutable values passed to a function that are "
"implicitly returned at the end of the function, returning ownership to the calling context. By doing so, they allow you to mutate the value passed while keeping ownership of it by "
@@ -5558,15 +5740,15 @@ msgstr ""
"propiedad devolviéndolo automáticamente al final de la ejecución.\n"
"En Cairo, se puede pasar un parámetro como _referencia mutable_ utilizando el modificador `ref`."
-#: src/ch03-02-references-and-snapshots.md:150
+#: src/ch03-02-references-and-snapshots.md:170
msgid "> **Note**: In Cairo, a parameter can only be passed as _mutable reference_ using the `ref` modifier if the variable is declared as mutable with `mut`."
msgstr "> **Nota**: En Cairo, un parámetro solo se puede pasar como _referencia mutable_ utilizando el modificador `ref` si la variable se declara como mutable con `mut`."
-#: src/ch03-02-references-and-snapshots.md:152
+#: src/ch03-02-references-and-snapshots.md:172
msgid "In Listing 3-7, we use a mutable reference to modify the value of the `height` and `width` fields of the `Rectangle` instance in the `flip` function."
msgstr "En el Listado 3-7, usamos una referencia mutable para modificar el valor del campo `height` de la instancia de `Rectangle` en la función `flip`."
-#: src/ch03-02-references-and-snapshots.md:154
+#: src/ch03-02-references-and-snapshots.md:174
msgid ""
"```rust\n"
"use debug::PrintTrait;\n"
@@ -5577,7 +5759,7 @@ msgid ""
"}\n"
"\n"
"fn main() {\n"
-" let mut rec = Rectangle { height: 3_u64, width: 10_u64 };\n"
+" let mut rec = Rectangle { height: 3, width: 10 };\n"
" flip(ref rec);\n"
" rec.height.print();\n"
" rec.width.print();\n"
@@ -5599,7 +5781,7 @@ msgstr ""
"}\n"
"\n"
"fn main() {\n"
-" let mut rec = Rectangle { height: 3_u64, width: 10_u64 };\n"
+" let mut rec = Rectangle { height: 3, width: 10 };\n"
" flip(ref rec);\n"
" rec.height.print();\n"
" rec.width.print();\n"
@@ -5612,11 +5794,11 @@ msgstr ""
"}\n"
"```"
-#: src/ch03-02-references-and-snapshots.md:176
+#: src/ch03-02-references-and-snapshots.md:196
msgid "Listing 3-7: Use of a mutable reference to modify a value"
msgstr "Listing 3-7: Uso de una referencia mutable para modificar un valor"
-#: src/ch03-02-references-and-snapshots.md:178
+#: src/ch03-02-references-and-snapshots.md:198
msgid ""
"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."
@@ -5624,11 +5806,11 @@ msgstr ""
"Primero, cambiamos `rec` a `mut`. Luego, pasamos una referencia mutable de `rec` a `flip` con `ref rec` y actualizamos la firma de la función para aceptar una referencia mutable con "
"`ref rec: Rectangle`. Esto deja muy claro que la función `flip` modificará el valor de la instancia de `Rectangle` pasada como parámetro."
-#: src/ch03-02-references-and-snapshots.md:180
+#: src/ch03-02-references-and-snapshots.md:200
msgid "The output of the program is:"
msgstr "La salida del programa es:"
-#: src/ch03-02-references-and-snapshots.md:182
+#: src/ch03-02-references-and-snapshots.md:202
msgid ""
"```console\n"
"[DEBUG]\n"
@@ -5644,19 +5826,19 @@ msgstr ""
"[DEBUG]\t (raw: 3)\n"
"```"
-#: src/ch03-02-references-and-snapshots.md:189
+#: src/ch03-02-references-and-snapshots.md:209
msgid "As expected, the `height` and `width` fields of the `rec` variable have been swapped."
msgstr "Como era de esperar, los campos `height` y `width` de la variable `rec` se han intercambiado."
-#: src/ch03-02-references-and-snapshots.md:191
+#: src/ch03-02-references-and-snapshots.md:211
msgid "### Small recap"
msgstr "### Pequeño resumen"
-#: src/ch03-02-references-and-snapshots.md:193
+#: src/ch03-02-references-and-snapshots.md:213
msgid "Let’s recap what we’ve discussed about ownership, snapshots, and references:"
msgstr "Como resumen, lo que hemos discutido acerca de ownership, snapshots y las referencias es:"
-#: src/ch03-02-references-and-snapshots.md:195
+#: src/ch03-02-references-and-snapshots.md:215
msgid ""
"- At any given time, a variable can only have one owner.\n"
"- You can pass a variable by-value, by-snapshot, or by-reference to a function.\n"
@@ -5718,8 +5900,8 @@ msgstr ""
"agrupan. Después, entre llaves, definimos los nombres y tipos de los datos, que llamamos campos. Por ejemplo, el Listado 4-1 muestra una estructura que almacena información sobre una "
"cuenta de usuario."
-#: src/ch04-01-defining-and-instantiating-structs.md:7 src/ch04-01-defining-and-instantiating-structs.md:26 src/ch04-01-defining-and-instantiating-structs.md:50
-#: src/ch04-01-defining-and-instantiating-structs.md:72 src/ch04-01-defining-and-instantiating-structs.md:93
+#: src/ch04-01-defining-and-instantiating-structs.md:7 src/ch04-01-defining-and-instantiating-structs.md:26 src/ch04-01-defining-and-instantiating-structs.md:48
+#: src/ch04-01-defining-and-instantiating-structs.md:83 src/ch04-01-defining-and-instantiating-structs.md:118
msgid "Filename: structs.cairo"
msgstr "Filename: structs.cairo"
@@ -5777,12 +5959,10 @@ msgid ""
"}\n"
"fn main() {\n"
" let user1 = User {\n"
-" active: true,\n"
-" username: 'someusername123',\n"
-" email: 'someone@example.com',\n"
-" sign_in_count: 1_u64,\n"
+" active: true, username: 'someusername123', email: 'someone@example.com', sign_in_count: 1\n"
" };\n"
"}\n"
+"\n"
"```"
msgstr ""
"```rust\n"
@@ -5795,19 +5975,17 @@ msgstr ""
"}\n"
"fn main() {\n"
" let user1 = User {\n"
-" active: true,\n"
-" username: 'someusername123',\n"
-" email: 'someone@example.com',\n"
-" sign_in_count: 1_u64,\n"
+" active: true, username: 'someusername123', email: 'someone@example.com', sign_in_count: 1\n"
" };\n"
"}\n"
+"\n"
"```"
-#: src/ch04-01-defining-and-instantiating-structs.md:46
+#: src/ch04-01-defining-and-instantiating-structs.md:44
msgid "Listing 4-2: Creating an instance of the `User` struct"
msgstr "Listado 4-2: Creando una instancia de la estructura `User`"
-#: src/ch04-01-defining-and-instantiating-structs.md:48
+#: src/ch04-01-defining-and-instantiating-structs.md:46
msgid ""
"To get a specific value from a struct, we use dot notation. For example, to access this user’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 4-3 shows how to change the value in the `email` field of a mutable `User` instance."
@@ -5816,47 +5994,73 @@ msgstr ""
"la instancia es mutable, podemos cambiar un valor usando la notación punto y asignándolo a un campo en particular. El listado 4-3 muestra cómo cambiar el valor en el campo `email`de "
"una instancia mutable de `User`."
-#: src/ch04-01-defining-and-instantiating-structs.md:52
+#: src/ch04-01-defining-and-instantiating-structs.md:50
msgid ""
-"```rust,does_not_compile\n"
+"```rust\n"
+"# #[derive(Copy, Drop)]\n"
+"# struct User {\n"
+"# active: bool,\n"
+"# username: felt252,\n"
+"# email: felt252,\n"
+"# sign_in_count: u64,\n"
+"# }\n"
"fn main() {\n"
" let mut user1 = User {\n"
-" active: true,\n"
-" username: 'someusername123',\n"
-" email: 'someone@example.com',\n"
-" sign_in_count: 1_u64,\n"
+" active: true, username: 'someusername123', email: 'someone@example.com', sign_in_count: 1\n"
" };\n"
" user1.email = 'anotheremail@example.com';\n"
"}\n"
-"```"
-msgstr ""
-"```rust,does_not_compile\n"
+"# \n"
+"# fn build_user(email: felt252, username: felt252) -> User {\n"
+"# User { active: true, username: username, email: email, sign_in_count: 1, }\n"
+"# }\n"
+"# \n"
+"# fn build_user_short(email: felt252, username: felt252) -> User {\n"
+"# User { active: true, username, email, sign_in_count: 1, }\n"
+"# }\n"
+"# \n"
+"```"
+msgstr ""
+"```rust\n"
+"# #[derive(Copy, Drop)]\n"
+"# struct User {\n"
+"# active: bool,\n"
+"# username: felt252,\n"
+"# email: felt252,\n"
+"# sign_in_count: u64,\n"
+"# }\n"
"fn main() {\n"
" let mut user1 = User {\n"
-" active: true,\n"
-" username: 'someusername123',\n"
-" email: 'someone@example.com',\n"
-" sign_in_count: 1_u64,\n"
+" active: true, username: 'someusername123', email: 'someone@example.com', sign_in_count: 1\n"
" };\n"
" user1.email = 'anotheremail@example.com';\n"
"}\n"
+"# \n"
+"# fn build_user(email: felt252, username: felt252) -> User {\n"
+"# User { active: true, username: username, email: email, sign_in_count: 1, }\n"
+"# }\n"
+"# \n"
+"# fn build_user_short(email: felt252, username: felt252) -> User {\n"
+"# User { active: true, username, email, sign_in_count: 1, }\n"
+"# }\n"
+"# \n"
"```"
-#: src/ch04-01-defining-and-instantiating-structs.md:64
+#: src/ch04-01-defining-and-instantiating-structs.md:75
msgid "Listing 4-3: Changing the value in the email field of a `User` instance"
msgstr "Listado 4-3: Cambiando el valor del campo email de la instancia `User`"
-#: src/ch04-01-defining-and-instantiating-structs.md:66
+#: src/ch04-01-defining-and-instantiating-structs.md:77
msgid "Note that the entire instance must be mutable; Cairo doesn’t allow us to mark only certain fields as mutable."
msgstr "Tenga en cuenta que toda la instancia debe ser mutable; Cairo no nos permite marcar solo ciertos campos como mutables."
-#: src/ch04-01-defining-and-instantiating-structs.md:68
+#: src/ch04-01-defining-and-instantiating-structs.md:79
msgid "As with any expression, we can construct a new instance of the struct as the last expression in the function body to implicitly return that new instance."
msgstr ""
"Como con cualquier expresión, podemos construir una nueva instancia de la estructura como la última expresión en el cuerpo de la función para devolver implícitamente esa nueva "
"instancia."
-#: src/ch04-01-defining-and-instantiating-structs.md:70
+#: src/ch04-01-defining-and-instantiating-structs.md:81
msgid ""
"Listing 4-4 shows a `build_user` function that returns a `User` instance with the given email and username. The `active` field gets the value of `true`, and the `sign_in_count` gets "
"a value of `1`."
@@ -5864,35 +6068,63 @@ msgstr ""
"Listado 4-4 muestra la función `build_user` que retorna una instancia de la estructura `User` con el email y el username. Al campo `active` se le asigna el valor `true`,y el campo "
"`sign_in_count` obtiene el valor de `1`."
-#: src/ch04-01-defining-and-instantiating-structs.md:74
+#: src/ch04-01-defining-and-instantiating-structs.md:85
msgid ""
"```rust\n"
+"# #[derive(Copy, Drop)]\n"
+"# struct User {\n"
+"# active: bool,\n"
+"# username: felt252,\n"
+"# email: felt252,\n"
+"# sign_in_count: u64,\n"
+"# }\n"
+"# fn main() {\n"
+"# let mut user1 = User {\n"
+"# active: true, username: 'someusername123', email: 'someone@example.com', sign_in_count: 1\n"
+"# };\n"
+"# user1.email = 'anotheremail@example.com';\n"
+"# }\n"
+"# \n"
"fn build_user(email: felt252, username: felt252) -> User {\n"
-" User {\n"
-" active: true,\n"
-" username: username,\n"
-" email: email,\n"
-" sign_in_count: 1,\n"
-" }\n"
-"}\n"
-"```"
-msgstr ""
-"```rust\n"
+" User { active: true, username: username, email: email, sign_in_count: 1, }\n"
+"}\n"
+"# \n"
+"# fn build_user_short(email: felt252, username: felt252) -> User {\n"
+"# User { active: true, username, email, sign_in_count: 1, }\n"
+"# }\n"
+"# \n"
+"```"
+msgstr ""
+"```rust\n"
+"# #[derive(Copy, Drop)]\n"
+"# struct User {\n"
+"# active: bool,\n"
+"# username: felt252,\n"
+"# email: felt252,\n"
+"# sign_in_count: u64,\n"
+"# }\n"
+"# fn main() {\n"
+"# let mut user1 = User {\n"
+"# active: true, username: 'someusername123', email: 'someone@example.com', sign_in_count: 1\n"
+"# };\n"
+"# user1.email = 'anotheremail@example.com';\n"
+"# }\n"
+"# \n"
"fn build_user(email: felt252, username: felt252) -> User {\n"
-" User {\n"
-" active: true,\n"
-" username: username,\n"
-" email: email,\n"
-" sign_in_count: 1,\n"
-" }\n"
+" User { active: true, username: username, email: email, sign_in_count: 1, }\n"
"}\n"
+"# \n"
+"# fn build_user_short(email: felt252, username: felt252) -> User {\n"
+"# User { active: true, username, email, sign_in_count: 1, }\n"
+"# }\n"
+"# \n"
"```"
-#: src/ch04-01-defining-and-instantiating-structs.md:85
+#: src/ch04-01-defining-and-instantiating-structs.md:110
msgid "Listing 4-4: A `build_user` function that takes an email and username and returns a `User` instance"
msgstr "Listado 4-4: Función `build_user` que toma los argumentos email y username, y retorna una instancia de la estructura `User`"
-#: src/ch04-01-defining-and-instantiating-structs.md:87
+#: src/ch04-01-defining-and-instantiating-structs.md:112
msgid ""
"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!"
@@ -5900,11 +6132,11 @@ msgstr ""
"Tiene sentido nombrar los parámetros de la función con el mismo nombre que los campos de la estructura, porque tener que repetir los nombres y variables de los campos `email`y "
"`username` es un poco tedioso. Si la estructura tuviera más campos, repetir cada nombre sería aún más molesto. ¡Afortunadamente, hay una forma abreviada!"
-#: src/ch04-01-defining-and-instantiating-structs.md:89
+#: src/ch04-01-defining-and-instantiating-structs.md:114
msgid "## Using the Field Init Shorthand"
msgstr "## Usando la Abreviatura Field Init"
-#: src/ch04-01-defining-and-instantiating-structs.md:91
+#: src/ch04-01-defining-and-instantiating-structs.md:116
msgid ""
"Because the parameter names and the struct field names are exactly the same in Listing 4-4, we can use the field init shorthand syntax to rewrite `build_user` so it behaves exactly "
"the same but doesn’t have the repetition of `username` and `email`, as shown in Listing 4-5."
@@ -5912,38 +6144,66 @@ msgstr ""
"Como los nombres de los parámetros y los nombres de los campos struct son exactamente los mismos en el Listado 4-4, podemos usar la sintaxis abreviada de field init para reescribir "
"`build_user` de forma que se comporte exactamente igual pero sin la repetición de `username` y `email`, como se muestra en el Listado 4-5."
-#: src/ch04-01-defining-and-instantiating-structs.md:95
-msgid ""
-"```rust\n"
-"fn build_user(email: felt252, username: felt252) -> User {\n"
-" User {\n"
-" active: true,\n"
-" username,\n"
-" email,\n"
-" sign_in_count: 1_u64,\n"
-" }\n"
-"}\n"
-"```"
-msgstr ""
-"```rust\n"
-"fn build_user(email: felt252, username: felt252) -> User {\n"
-" User {\n"
-" active: true,\n"
-" username,\n"
-" email,\n"
-" sign_in_count: 1_u64,\n"
-" }\n"
-"}\n"
-"```"
-
-#: src/ch04-01-defining-and-instantiating-structs.md:106
+#: src/ch04-01-defining-and-instantiating-structs.md:120
+msgid ""
+"```rust\n"
+"# #[derive(Copy, Drop)]\n"
+"# struct User {\n"
+"# active: bool,\n"
+"# username: felt252,\n"
+"# email: felt252,\n"
+"# sign_in_count: u64,\n"
+"# }\n"
+"# fn main() {\n"
+"# let mut user1 = User {\n"
+"# active: true, username: 'someusername123', email: 'someone@example.com', sign_in_count: 1\n"
+"# };\n"
+"# user1.email = 'anotheremail@example.com';\n"
+"# }\n"
+"# \n"
+"# fn build_user(email: felt252, username: felt252) -> User {\n"
+"# User { active: true, username: username, email: email, sign_in_count: 1, }\n"
+"# }\n"
+"# \n"
+"fn build_user_short(email: felt252, username: felt252) -> User {\n"
+" User { active: true, username, email, sign_in_count: 1, }\n"
+"}\n"
+"# \n"
+"```"
+msgstr ""
+"```rust\n"
+"# #[derive(Copy, Drop)]\n"
+"# struct User {\n"
+"# active: bool,\n"
+"# username: felt252,\n"
+"# email: felt252,\n"
+"# sign_in_count: u64,\n"
+"# }\n"
+"# fn main() {\n"
+"# let mut user1 = User {\n"
+"# active: true, username: 'someusername123', email: 'someone@example.com', sign_in_count: 1\n"
+"# };\n"
+"# user1.email = 'anotheremail@example.com';\n"
+"# }\n"
+"# \n"
+"# fn build_user(email: felt252, username: felt252) -> User {\n"
+"# User { active: true, username: username, email: email, sign_in_count: 1, }\n"
+"# }\n"
+"# \n"
+"fn build_user_short(email: felt252, username: felt252) -> User {\n"
+" User { active: true, username, email, sign_in_count: 1, }\n"
+"}\n"
+"# \n"
+"```"
+
+#: src/ch04-01-defining-and-instantiating-structs.md:145
msgid ""
"Listing 4-5: A `build_user` function that uses field init shorthand because the `username` and `email` parameters have the same name as struct fields"
msgstr ""
"Lista 4-5: Una función `build_user` que utiliza la abreviatura field init porque los parámetros `username` y `email` tienen el mismo nombre que los campos "
"struct"
-#: src/ch04-01-defining-and-instantiating-structs.md:108
+#: src/ch04-01-defining-and-instantiating-structs.md:147
msgid ""
"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`."
@@ -5976,8 +6236,8 @@ msgid ""
"```rust\n"
"use debug::PrintTrait;\n"
"fn main() {\n"
-" let width1 = 30_u64;\n"
-" let height1 = 10_u64;\n"
+" let width1 = 30;\n"
+" let height1 = 10;\n"
" let area = area(width1, height1);\n"
" area.print();\n"
"}\n"
@@ -5990,8 +6250,8 @@ msgstr ""
"```rust\n"
"use debug::PrintTrait;\n"
"fn main() {\n"
-" let width1 = 30_u64;\n"
-" let height1 = 10_u64;\n"
+" let width1 = 30;\n"
+" let height1 = 10;\n"
" let area = area(width1, height1);\n"
" area.print();\n"
"}\n"
@@ -6066,13 +6326,13 @@ msgid ""
"```rust\n"
"use debug::PrintTrait;\n"
"fn main() {\n"
-" let rectangle = (30_u64, 10_u64);\n"
+" let rectangle = (30, 10);\n"
" let area = area(rectangle);\n"
" area.print(); // print out the area\n"
"}\n"
"\n"
"fn area(dimension: (u64, u64)) -> u64 {\n"
-" let (x,y) = dimension;\n"
+" let (x, y) = dimension;\n"
" x * y\n"
"}\n"
"```"
@@ -6080,13 +6340,13 @@ msgstr ""
"```rust\n"
"use debug::PrintTrait;\n"
"fn main() {\n"
-" let rectangle = (30_u64, 10_u64);\n"
+" let rectangle = (30, 10);\n"
" let area = area(rectangle);\n"
" area.print(); // print out the area\n"
"}\n"
"\n"
"fn area(dimension: (u64, u64)) -> u64 {\n"
-" let (x,y) = dimension;\n"
+" let (x, y) = dimension;\n"
" x * y\n"
"}\n"
"```"
@@ -6125,7 +6385,7 @@ msgstr ""
#: src/ch04-02-an-example-program-using-structs.md:76
msgid ""
-"```rust\n"
+"```rust,ignore_format\n"
"use debug::PrintTrait;\n"
"\n"
"struct Rectangle {\n"
@@ -6134,10 +6394,7 @@ msgid ""
"}\n"
"\n"
"fn main() {\n"
-" let rectangle = Rectangle {\n"
-" width: 30_u64,\n"
-" height: 10_u64,\n"
-" };\n"
+" let rectangle = Rectangle { width: 30, height: 10, };\n"
" let area = area(rectangle);\n"
" area.print(); // print out the area\n"
"}\n"
@@ -6147,7 +6404,7 @@ msgid ""
"}\n"
"```"
msgstr ""
-"```rust\n"
+"```rust,ignore_format\n"
"use debug::PrintTrait;\n"
"\n"
"struct Rectangle {\n"
@@ -6156,10 +6413,7 @@ msgstr ""
"}\n"
"\n"
"fn main() {\n"
-" let rectangle = Rectangle {\n"
-" width: 30_u64,\n"
-" height: 10_u64,\n"
-" };\n"
+" let rectangle = Rectangle { width: 30, height: 10, };\n"
" let area = area(rectangle);\n"
" area.print(); // print out the area\n"
"}\n"
@@ -6169,11 +6423,11 @@ msgstr ""
"}\n"
"```"
-#: src/ch04-02-an-example-program-using-structs.md:98
+#: src/ch04-02-an-example-program-using-structs.md:95
msgid "Listing 4-8: Defining a `Rectangle` struct"
msgstr "Listado 4-8: Definición de una estructura llamada `Rectangle`"
-#: src/ch04-02-an-example-program-using-structs.md:100
+#: src/ch04-02-an-example-program-using-structs.md:97
msgid ""
"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 "
@@ -6185,11 +6439,11 @@ msgstr ""
"llamado `rectangle` que es de tipo de la estructura `Rectangle`. Luego podemos acceder a los campos de la instancia con notación de punto, y dar nombres descriptivos a los valores en "
"lugar de usar los valores de índice de tupla de `0` y `1`."
-#: src/ch04-02-an-example-program-using-structs.md:102
+#: src/ch04-02-an-example-program-using-structs.md:99
msgid "## Adding Useful Functionality with Trait"
msgstr "## Agregando Funcionalidades Útiles con Trait"
-#: src/ch04-02-an-example-program-using-structs.md:104
+#: src/ch04-02-an-example-program-using-structs.md:101
msgid ""
"It’d be useful to be able to print an instance of `Rectangle` while we’re debugging our program and see the values for all its fields. Listing 4-9 tries using the `print` as we have "
"used in previous chapters. This won’t work."
@@ -6197,9 +6451,9 @@ msgstr ""
"Sería útil poder imprimir una instancia de `Rectangle` mientras estamos depurando nuestro programa y ver los valores de todos sus campos. El Listado 4-9 intenta usar `print` como lo "
"hemos usado en capítulos anteriores. Esto no funcionará."
-#: src/ch04-02-an-example-program-using-structs.md:108
+#: src/ch04-02-an-example-program-using-structs.md:105
msgid ""
-"```rust,does_not_compile\n"
+"```rust\n"
"use debug::PrintTrait;\n"
"\n"
"struct Rectangle {\n"
@@ -6208,15 +6462,12 @@ msgid ""
"}\n"
"\n"
"fn main() {\n"
-" let rectangle = Rectangle {\n"
-" width: 30_u64,\n"
-" height: 10_u64,\n"
-" };\n"
+" let rectangle = Rectangle { width: 30, height: 10, };\n"
" rectangle.print();\n"
"}\n"
"```"
msgstr ""
-"```rust,does_not_compile\n"
+"```rust\n"
"use debug::PrintTrait;\n"
"\n"
"struct Rectangle {\n"
@@ -6225,23 +6476,20 @@ msgstr ""
"}\n"
"\n"
"fn main() {\n"
-" let rectangle = Rectangle {\n"
-" width: 30_u64,\n"
-" height: 10_u64,\n"
-" };\n"
+" let rectangle = Rectangle { width: 30, height: 10, };\n"
" rectangle.print();\n"
"}\n"
"```"
-#: src/ch04-02-an-example-program-using-structs.md:125
+#: src/ch04-02-an-example-program-using-structs.md:119
msgid "Listing 4-9: Attempting to print a `Rectangle` instance"
msgstr "Listado 4-9: Intentando imprimir una instancia de `Rectangle`"
-#: src/ch04-02-an-example-program-using-structs.md:127
+#: src/ch04-02-an-example-program-using-structs.md:121
msgid "When we compile this code, we get an error with this message:"
msgstr "Cuando compilamos este código, obtenemos un error con el siguiente mensaje:"
-#: src/ch04-02-an-example-program-using-structs.md:129
+#: src/ch04-02-an-example-program-using-structs.md:123
msgid ""
"```bash\n"
"$ cairo-compile src/lib.cairo\n"
@@ -6263,7 +6511,7 @@ msgstr ""
"Error: Compilation failed.\n"
"```"
-#: src/ch04-02-an-example-program-using-structs.md:139
+#: src/ch04-02-an-example-program-using-structs.md:133
msgid ""
"The `print` trait is implemented for many data types, but not for the `Rectangle` struct. We can fix this by implementing the `PrintTrait` trait on `Rectangle` as shown in Listing "
"4-10.\n"
@@ -6273,9 +6521,9 @@ msgstr ""
"`Rectangle` como se muestra en el Listado 4-10.\n"
"Para aprender más sobre traits,[Traits en Cairo](ch07-02-traits-in-cairo.md)."
-#: src/ch04-02-an-example-program-using-structs.md:144
+#: src/ch04-02-an-example-program-using-structs.md:138
msgid ""
-"```rust\n"
+"```rust,ignore_format\n"
"use debug::PrintTrait;\n"
"\n"
"struct Rectangle {\n"
@@ -6284,10 +6532,7 @@ msgid ""
"}\n"
"\n"
"fn main() {\n"
-" let rectangle = Rectangle {\n"
-" width: 30_u64,\n"
-" height: 10_u64,\n"
-" };\n"
+" let rectangle = Rectangle { width: 30, height: 10, };\n"
" rectangle.print();\n"
"}\n"
"\n"
@@ -6299,7 +6544,7 @@ msgid ""
"}\n"
"```"
msgstr ""
-"```rust\n"
+"```rust,ignore_format\n"
"use debug::PrintTrait;\n"
"\n"
"struct Rectangle {\n"
@@ -6308,10 +6553,7 @@ msgstr ""
"}\n"
"\n"
"fn main() {\n"
-" let rectangle = Rectangle {\n"
-" width: 30_u64,\n"
-" height: 10_u64,\n"
-" };\n"
+" let rectangle = Rectangle { width: 30, height: 10, };\n"
" rectangle.print();\n"
"}\n"
"\n"
@@ -6323,11 +6565,11 @@ msgstr ""
"}\n"
"```"
-#: src/ch04-02-an-example-program-using-structs.md:168
+#: src/ch04-02-an-example-program-using-structs.md:159
msgid "Listing 4-10: Implementing the `PrintTrait` trait on `Rectangle`"
msgstr "Listado 4-10: Implementación del trait `PrintTrait` en `Rectangle`"
-#: src/ch04-02-an-example-program-using-structs.md:170
+#: src/ch04-02-an-example-program-using-structs.md:161
msgid "Nice! It’s not the prettiest output, but it shows the values of all the fields for this instance, which would definitely help during debugging."
msgstr "¡Bien! No es el resultado más bonito, pero muestra los valores de todos los campos para esta instancia, lo que definitivamente ayudaría durante la depuración."
@@ -6363,11 +6605,11 @@ msgstr "### Definición de Détodos"
msgid ""
"Let’s change the `area` function that has a `Rectangle` instance as a parameter\n"
"and instead make an `area` method defined on the `RectangleTrait` trait, as shown\n"
-"in Listing 5-13."
+"in Listing 4-13."
msgstr ""
"Cambiemos la función `area` que tiene una instancia `Rectangle` como parámetro\n"
-"y en su lugar hagamos un método `area` definido en el trait `RectangleTrait`, como se muestra\n"
-" en el Listado 5-13."
+"y en su lugar hagamos un método `area` definido en el rasgo `RectangleTrait`, como se muestra en el Listado 4-13.\n"
+"en el Listado 4-13."
#: src/ch04-03-method-syntax.md:20
msgid ""
@@ -6390,7 +6632,7 @@ msgid ""
"}\n"
"\n"
"fn main() {\n"
-" let rect1 = Rectangle { width: 30_u64, height: 50_u64, };\n"
+" let rect1 = Rectangle { width: 30, height: 50, };\n"
"\n"
" rect1.area().print();\n"
"}\n"
@@ -6415,7 +6657,7 @@ msgstr ""
"}\n"
"\n"
"fn main() {\n"
-" let rect1 = Rectangle { width: 30_u64, height: 50_u64, };\n"
+" let rect1 = Rectangle { width: 30, height: 50, };\n"
"\n"
" rect1.area().print();\n"
"}\n"
@@ -6431,7 +6673,7 @@ msgstr ""
#: src/ch04-03-method-syntax.md:48
msgid ""
-"To define the function within the context of `Rectangle`, we start by definining a `trait`\n"
+"To define the function within the context of `Rectangle`, we start by defining a `trait`\n"
"block with the signature of the method that we want to implement. Traits are not linked to\n"
"a specific type; only the `self` parameter of the method defines which type it can be used\n"
"with. Then, we define an `impl` (implementation) block for `RectangleTrait`, that defines\n"
@@ -6447,20 +6689,21 @@ msgid ""
"instance. The method syntax goes after an instance: we add a dot followed by\n"
"the method name, parentheses, and any arguments."
msgstr ""
-"Para definir la función dentro del contexto de `Rectangle`, comenzamos definiendo un `trait` \n"
-"con la declaración del método que queremos implementar. Los *Traits* no están vinculados a un\n"
-" tipo específico; solo el parámetro `self` del método define qué tipo se puede usar con dicho *trait*. \n"
-"Luego, definimos un bloque con la palabra clave `impl` para `RectangleTrait`, que define el \n"
-"comportamiento de los métodos implementados. Todo dentro de este bloque `impl` será asociado con \n"
-"el tipo del parámetro `self` del método llamado. Si bien es técnicamente posible definir métodos para \n"
-"múltiples tipos dentro del mismo bloque `impl`, no es una práctica recomendada, ya que puede producir\n"
-" una confusión. Recomendamos que el tipo del parámetro `self` permanece consistente dentro del mismo\n"
-" bloque `impl`. \n"
-"Luego movemos la función `area` dentro de los corchetes `impl` y cambiamos el primer (y en\n"
-" este caso, único) parámetro para ser `self` en la declaración y en todas partes dentro del cuerpo. En `main`,\n"
-" donde llamamos a la función `area` y pasamos `rect1` como argumento, en su lugar, podemos usar la _sintaxis \n"
-"del método_ para llamar al método `area` en nuestra instancia del `Rectangle`. La sintaxis del método va \n"
-"después de una instancia: agregamos un punto seguido del nombre del método, los paréntesis y los argumentos."
+"Para definir la función en el contexto de `Rectangle`, empezamos definiendo un bloque `trait`\n"
+"con la firma del método que queremos implementar. Los traits no están vinculados a\n"
+"sólo el parámetro `self` del método define con qué tipo se puede utilizar.\n"
+"puede utilizar. A continuación, definimos un bloque `impl` (implementación) para `RectangleTrait`, que define\n"
+"el comportamiento de los métodos implementados. Todo dentro de este bloque `impl` será\n"
+"asociado con el tipo del parámetro `self` del método llamado. Aunque técnicamente es posible\n"
+"definir métodos para múltiples tipos dentro del mismo bloque `impl`, no es una\n"
+"una práctica recomendada, ya que puede dar lugar a confusión. Recomendamos que el tipo del parámetro `self\n"
+"sea consistente dentro del mismo bloque `impl`.\n"
+"Entonces movemos la función `area` dentro de las llaves `impl` y cambiamos el primer (y en este caso, único) parámetro\n"
+"para que sea `self` en la firma y en todo el cuerpo. En\n"
+"donde llamamos a la función `area` y pasamos `rect1` como argumento,\n"
+"podemos usar la sintaxis _method_ para llamar al método `area` en nuestra instancia `Rectangle`.\n"
+"de nuestro `Rectángulo`. La sintaxis de método va después de una instancia: añadimos un punto seguido de\n"
+"el nombre del método, los paréntesis y los argumentos."
#: src/ch04-03-method-syntax.md:64
msgid ""
@@ -6550,12 +6793,12 @@ msgid ""
"\n"
"impl RectangleImpl of RectangleTrait {\n"
" fn width(self: @Rectangle) -> bool {\n"
-" (*self.width) > 0_u64\n"
+" (*self.width) > 0\n"
" }\n"
"}\n"
"\n"
"fn main() {\n"
-" let rect1 = Rectangle { width: 30_u64, height: 50_u64, };\n"
+" let rect1 = Rectangle { width: 30, height: 50, };\n"
" rect1.width().print();\n"
"}\n"
"```"
@@ -6574,12 +6817,12 @@ msgstr ""
"\n"
"impl RectangleImpl of RectangleTrait {\n"
" fn width(self: @Rectangle) -> bool {\n"
-" (*self.width) > 0_u64\n"
+" (*self.width) > 0\n"
" }\n"
"}\n"
"\n"
"fn main() {\n"
-" let rect1 = Rectangle { width: 30_u64, height: 50_u64, };\n"
+" let rect1 = Rectangle { width: 30, height: 50, };\n"
" rect1.width().print();\n"
"}\n"
"```"
@@ -6610,12 +6853,14 @@ msgid ""
"of `Rectangle` and return `true` if the second `Rectangle` can fit completely\n"
"within `self` (the first `Rectangle`); otherwise, it should return `false`.\n"
"That is, once we’ve defined the `can_hold` method, we want to be able to write\n"
-"the program shown in Listing 5-14."
+"the program shown in Listing 4-14."
msgstr ""
-"Practiquemos el uso de métodos implementando un segundo método en la estructura `Rectangle`. \n"
-"Esta vez queremos que una instancia de `Rectangle` tome otra instancia de `Rectangle` y devolver \n"
-"`true` si el segundo `Rectangle` puede caber completamente dentro de `self` (el primer `Rectangle`); \n"
-"de lo contrario, debería devolver `false`. Es decir, una vez que hemos definido el método `can_hold`, queremos poder escribir el programa que se muestra en el Listado 5-14."
+"Practiquemos el uso de métodos implementando un segundo método en la estructura `Rectangle`.\n"
+"struct. Esta vez queremos que una instancia de `Rectangle` tome otra instancia de `Rectangle\n"
+"de `Rectangle` y devuelva `true` si el segundo `Rectangle` cabe completamente dentro de\n"
+"dentro de `self` (el primer `Rectangle`); en caso contrario, devolverá `false`.\n"
+"Es decir, una vez que hemos definido el método `can_hold`, queremos ser capaces de escribir\n"
+"el programa mostrado en el Listado 4-14."
#: src/ch04-03-method-syntax.md:137
msgid ""
@@ -6628,9 +6873,9 @@ msgid ""
"}\n"
"\n"
"fn main() {\n"
-" let rect1 = Rectangle { width: 30_u64, height: 50_u64, };\n"
-" let rect2 = Rectangle { width: 10_u64, height: 40_u64, };\n"
-" let rect3 = Rectangle { width: 60_u64, height: 45_u64, };\n"
+" let rect1 = Rectangle { width: 30, height: 50, };\n"
+" let rect2 = Rectangle { width: 10, height: 40, };\n"
+" let rect3 = Rectangle { width: 60, height: 45, };\n"
"\n"
" 'Can rect1 hold rect2?'.print();\n"
" rect1.can_hold(@rect2).print();\n"
@@ -6649,9 +6894,9 @@ msgstr ""
"}\n"
"\n"
"fn main() {\n"
-" let rect1 = Rectangle { width: 30_u64, height: 50_u64, };\n"
-" let rect2 = Rectangle { width: 10_u64, height: 40_u64, };\n"
-" let rect3 = Rectangle { width: 60_u64, height: 45_u64, };\n"
+" let rect1 = Rectangle { width: 30, height: 50, };\n"
+" let rect2 = Rectangle { width: 10, height: 40, };\n"
+" let rect3 = Rectangle { width: 60, height: 45, };\n"
"\n"
" 'Can rect1 hold rect2?'.print();\n"
" rect1.can_hold(@rect2).print();\n"
@@ -6663,9 +6908,11 @@ msgstr ""
#: src/ch04-03-method-syntax.md:158
msgid ""
-"Listing 5-14: Using the as-yet-unwritten `can_hold`\n"
+"Listing 4-14: Using the as-yet-unwritten `can_hold`\n"
"method"
-msgstr "Listing 5-14: Usando el método todavia no escrito `can_hold`"
+msgstr ""
+"Listado 4-14: Utilizando el método `can_hold` \n"
+"aún no escrito"
#: src/ch04-03-method-syntax.md:161
msgid ""
@@ -6717,24 +6964,24 @@ msgid ""
"Boolean, and the implementation will check whether the width and height of\n"
"`self` are greater than the width and height of the other `Rectangle`,\n"
"respectively. Let’s add the new `can_hold` method to the `trait` and `impl` blocks from\n"
-"Listing 5-13, shown in Listing 5-15."
+"Listing 4-13, shown in Listing 4-15."
msgstr ""
-"Sabemos que queremos definir un método, así que estará dentro de los bloques `trait RectangleTrait` y `impl RectangleImpl of RectangleTrait`.\n"
+"Sabemos que queremos definir un método, así que estará dentro de los bloques `trait RectangleTrait`\n"
"y `impl RectangleImpl of RectangleTrait`.\n"
"El nombre del método será `can_hold`, y tomará una instantánea\n"
"de otro `Rectangle` como parámetro. Podemos saber cuál será el tipo del parámetro\n"
-"parámetro mirando el código que llama al método:\n"
+"mirando el código que llama al método:\n"
"rect1.can_hold(@rect2)` pasa `@rect2`, que es una instantánea de\n"
"`rect2`, una instancia de `Rectangle`. Esto tiene sentido porque sólo necesitamos\n"
"leer `rect2` (en lugar de escribir, lo que significaría que necesitaríamos un préstamo mutable),\n"
"y queremos que `main` conserve la propiedad de `rect2` para poder volver a usarla después de\n"
-"después de llamar al método `can_hold`. El valor de retorno de `can_hold` será un booleano\n"
+"llamar al método `can_hold`. El valor de retorno de `can_hold` será un booleano\n"
"y la implementación comprobará si la anchura y la altura de\n"
"`self` son mayores que la anchura y la altura del otro `Rectangle`,\n"
"respectivamente. Añadamos el nuevo método `can_hold` a los bloques `trait` e `impl` de\n"
-"Listado 5-13, mostrados en el Listado 5-15."
+"Listado 4-13, mostrados en el Listado 4-15."
-#: src/ch04-03-method-syntax.md:194
+#: src/ch04-03-method-syntax.md:194 src/ch08-01-how-to-write-tests.md:134
msgid ""
"```rust\n"
"trait RectangleTrait {\n"
@@ -6772,21 +7019,23 @@ msgstr ""
#: src/ch04-03-method-syntax.md:211
msgid ""
-"Listing 5-15: Implementing the `can_hold` method on\n"
+"Listing 4-15: Implementing the `can_hold` method on\n"
"`Rectangle` that takes another `Rectangle` instance as a parameter"
-msgstr "Listing 4-15: Implementación del método `can_hold` en `Rectangle` que recibe una instancia de `Rectangle` como parámetro"
+msgstr ""
+"Listado 4-15: Implementación del método `can_hold` en\n"
+"`Rectangle` que toma otra instancia de `Rectangle` como parámetro"
#: src/ch04-03-method-syntax.md:214
msgid ""
-"When we run this code with the `main` function in Listing 5-14, we’ll get our\n"
+"When we run this code with the `main` function in Listing 4-14, we’ll get our\n"
"desired output. Methods can take multiple parameters that we add to the\n"
"signature after the `self` parameter, and those parameters work just like\n"
"parameters in functions."
msgstr ""
-"Cuando ejecutemos este código con la función `main` del Listado 5-14, obtendremos la salida deseada.\n"
+"Cuando ejecutemos este código con la función `main` del Listado 4-14, obtendremos\n"
"salida deseada. Los métodos pueden tomar múltiples parámetros que añadimos a la firma\n"
-"después del parámetro `self`, y esos parámetros funcionan igual que los parámetros de las funciones.\n"
-"en las funciones."
+"después del parámetro `self`, y esos parámetros funcionan igual que los\n"
+"parámetros en las funciones."
#: src/ch04-03-method-syntax.md:219
msgid "### Accessing implementation functions"
@@ -6843,18 +7092,18 @@ msgstr ""
#: src/ch04-03-method-syntax.md:245
msgid ""
"To call this function, we use the `::` syntax with the implementation name;\n"
-"`let square = RectangleImpl::square(10_u64);` is an example. This function is namespaced by\n"
+"`let square = RectangleImpl::square(10);` is an example. This function is namespaced by\n"
"the implementation; the `::` syntax is used for both trait functions and\n"
"namespaces created by modules. We’ll discuss modules in [Chapter 7][modules]."
msgstr ""
-"Para llamar a esta función, usamos la sintaxis `::` con el nombre de implementación; por ejemplo, \n"
-"`let square = RectangleImpl::square(10_u64);`. Esta función está espaciada por la implementación: l\n"
-"a sintaxis `::` se usa tanto para funciones del *trait* y espacios de nombres creados por módulos. \n"
-"Lo discutiremos en el [Capítulo 7][modules]."
+"Para llamar a esta función, usamos la sintaxis `::` con el nombre\n"
+"de implementación; `let square = RectangleImpl::square(10);` es un ejemplo. Esta función está en el espacio de nombres \n"
+"de la implementación; la sintaxis `::` se utiliza tanto para las funciones \n"
+"de los traits como para los espacios de nombres creados por los módulos. Discutiremos los módulos en el [Capítulo 7][modules]."
#: src/ch04-03-method-syntax.md:250
-msgid "> Note: It is also possible to call this function using the trait name, with `RectangleTrait::square(10_u64)`."
-msgstr "> Nota: También es posible llamar a esta función usando el nombre del *trait*, con `RectangleTrait::square(10_u64)`."
+msgid "> Note: It is also possible to call this function using the trait name, with `RectangleTrait::square(10)`."
+msgstr "> Nota: También es posible llamar a esta función utilizando el nombre del trait, con `RectangleTrait::square(10)`."
#: src/ch04-03-method-syntax.md:252
msgid "### Multiple `impl` Blocks"
@@ -6863,12 +7112,12 @@ msgstr "### Multiples Bloques con `impl`"
#: src/ch04-03-method-syntax.md:254
msgid ""
"Each struct is allowed to have multiple `trait` and `impl` blocks. For example, Listing\n"
-"5-15 is equivalent to the code shown in Listing 5-16, which has each method in\n"
+"5-15 is equivalent to the code shown in Listing 4-16, which has each method in\n"
"its own `trait` and `impl` blocks."
msgstr ""
-"Cada estructura tiene permitido tener múltiples bloques con `trait` e `impl`. Por ejemplo,\n"
-" en el Listado 5-15 es equivalente al código mostrado en el Listado 5-16, que tiene cada método \n"
-"en su propio bloque de `trait` e `impl`."
+"Cada estructura puede tener múltiples bloques `trait` e `impl`. Por ejemplo, el Listado \n"
+"5-15 es equivalente al código mostrado en el Listado 4-16, que tiene cada método en\n"
+"sus propios bloques `trait` e `impl`."
#: src/ch04-03-method-syntax.md:258
msgid ""
@@ -6916,9 +7165,9 @@ msgstr ""
#: src/ch04-03-method-syntax.md:279
msgid ""
-"Listing 5-16: Rewriting Listing 5-15 using multiple `impl`\n"
+"Listing 4-16: Rewriting Listing 4-15 using multiple `impl`\n"
"blocks"
-msgstr "Listado 5-16: Reescribiendo el Listado 5-15 usando múltiples bloques de `impl`"
+msgstr "Listado 4-16: Reescribiendo el Listado 4-15 usando múltiples bloques `impl`"
#: src/ch04-03-method-syntax.md:282
msgid ""
@@ -6978,7 +7227,7 @@ msgstr "Aquí hay un ejemplo sencillo de un enum:"
#: src/ch05-01-enums.md:9
msgid ""
-"```rs\n"
+"```rust\n"
"#[derive(Drop)]\n"
"enum Direction {\n"
" North: (),\n"
@@ -6986,10 +7235,9 @@ msgid ""
" South: (),\n"
" West: (),\n"
"}\n"
-"\n"
"```"
msgstr ""
-"```rs\n"
+"```rust\n"
"#[derive(Drop)]\n"
"enum Direction {\n"
" North: (),\n"
@@ -6997,10 +7245,9 @@ msgstr ""
" South: (),\n"
" West: (),\n"
"}\n"
-"\n"
"```"
-#: src/ch05-01-enums.md:20
+#: src/ch05-01-enums.md:19
msgid ""
"Unlike other languages like Rust, every variant has a type. In this example, we've defined an enum called `Direction` with four variants: `North`, `East`, `South`, and `West`. The "
"naming convention is to use PascalCase for enum variants. Each variant represents a distinct value of the Direction type and is associated with a unit type `()`. One variant can be "
@@ -7010,57 +7257,81 @@ msgstr ""
"`West`. La convención de nomenclatura es utilizar PascalCase para las variantes del enum. Cada variante representa un valor distinto del tipo `Direction` y está asociada con un tipo "
"unitario `()`. Una variante puede ser instanciada utilizando esta sintaxis:"
-#: src/ch05-01-enums.md:22
+#: src/ch05-01-enums.md:21
msgid ""
-"```rs\n"
-"let direction = Direction::North(());\n"
+"```rust\n"
+"# #[derive(Drop)]\n"
+"# enum Direction {\n"
+"# North: (),\n"
+"# East: (),\n"
+"# South: (),\n"
+"# West: (),\n"
+"# }\n"
+"# \n"
+"# fn main() {\n"
+" let direction = Direction::North(());\n"
+"# }\n"
+"# \n"
+"# \n"
"```"
msgstr ""
-"```rs\n"
-"let direction = Direction::North(());\n"
+"```rust\n"
+"# #[derive(Drop)]\n"
+"# enum Direction {\n"
+"# North: (),\n"
+"# East: (),\n"
+"# South: (),\n"
+"# West: (),\n"
+"# }\n"
+"# \n"
+"# fn main() {\n"
+" let direction = Direction::North(());\n"
+"# }\n"
+"# \n"
+"# \n"
"```"
-#: src/ch05-01-enums.md:26
+#: src/ch05-01-enums.md:37
msgid ""
"It's easy to write code that acts differently depending on the variant of an enum instance, in this example to run specific code according to a Direction. You can learn more about it "
-"on the [The Match Control Flow Construct page](ch05-02-the-match-control-flow-construct.md)."
+"on [The Match Control Flow Construct page](ch05-02-the-match-control-flow-construct.md)."
msgstr ""
-"Es fácil escribir código que se comporte de manera diferente según la variante de una instancia de un enum, como en este ejemplo, donde se ejecuta un código específico según una "
-"dirección. Puedes obtener más información sobre esto en la página [The Match Control Flow Construct](ch05-02-the-match-control-flow-construct.md)."
+"Es fácil escribir código que se comporte de manera diferente según la variante de una instancia de enum, en este ejemplo para ejecutar código específico según una dirección "
+"(`Direction`). Puedes obtener más información al respecto en la página [La construcción de flujo de control Match](ch05-02-the-match-control-flow-construct.md)."
-#: src/ch05-01-enums.md:28
+#: src/ch05-01-enums.md:39
msgid "## Enums Combined with Custom Types"
msgstr "## Enums combinados con Tipos Personalizados"
-#: src/ch05-01-enums.md:30
+#: src/ch05-01-enums.md:41
msgid "Enums can also be used to store more interesting data associated with each variant. For example:"
msgstr "Los enums también pueden ser utilizados para almacenar datos más interesantes asociados con cada variante. Por ejemplo:"
-#: src/ch05-01-enums.md:32
+#: src/ch05-01-enums.md:43
msgid ""
-"```rs\n"
+"```rust\n"
"#[derive(Drop)]\n"
"enum Message {\n"
-" Quit : (),\n"
-" Echo : felt252,\n"
-" Move : (u128, u128),\n"
+" Quit: (),\n"
+" Echo: felt252,\n"
+" Move: (u128, u128),\n"
"}\n"
"```"
msgstr ""
-"```rs\n"
+"```rust\n"
"#[derive(Drop)]\n"
"enum Message {\n"
-" Quit : (),\n"
-" Echo : felt252,\n"
-" Move : (u128, u128),\n"
+" Quit: (),\n"
+" Echo: felt252,\n"
+" Move: (u128, u128),\n"
"}\n"
"```"
-#: src/ch05-01-enums.md:41
+#: src/ch05-01-enums.md:52
msgid "In this example, the `Message` enum has three variants: `Quit`, `Echo` and `Move`, all with different types:"
msgstr "En este ejemplo, el enum `Message` tiene tres variantes: `Quit`, `Echo` y `Move`, todas con tipos diferentes:"
-#: src/ch05-01-enums.md:43
+#: src/ch05-01-enums.md:54
msgid ""
"- `Quit` is the unit type - it has no data associated with it at all.\n"
"- `Echo` is a single felt.\n"
@@ -7070,15 +7341,15 @@ msgstr ""
"- `Echo` incluye un solo campo.\n"
"- `Move` incluye dos valores u128."
-#: src/ch05-01-enums.md:47
+#: src/ch05-01-enums.md:58
msgid "You could even use a Struct or another Enum you defined inside one of your Enum variants."
msgstr "Incluso puedes usar una estructura o otro enum que hayas definido dentro de una de las variantes de tu enum."
-#: src/ch05-01-enums.md:49
+#: src/ch05-01-enums.md:60
msgid "## Trait Implementations for Enums"
msgstr "## Implementaciones de Traits para Enums"
-#: src/ch05-01-enums.md:51
+#: src/ch05-01-enums.md:62
msgid ""
"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:"
@@ -7086,7 +7357,7 @@ msgstr ""
"En Cairo, puedes definir traits e implementarlos para tus enums personalizados. Esto te permite definir métodos y comportamientos asociados con el enum. Aquí hay un ejemplo de cómo "
"definir un trait e implementarlo para el enum `Message` anterior:"
-#: src/ch05-01-enums.md:53
+#: src/ch05-01-enums.md:64
msgid ""
"```rs\n"
"trait Processing {\n"
@@ -7132,31 +7403,93 @@ msgstr ""
"}\n"
"```"
-#: src/ch05-01-enums.md:75
+#: src/ch05-01-enums.md:86
msgid "In this example, we implemented the `Processing` trait for `Message`. Here is how it could be used to process a Quit message:"
msgstr "En este ejemplo, implementamos el trait `Processing` para `Message`. Así es cómo podría ser utilizado para procesar un mensaje Quit:"
-#: src/ch05-01-enums.md:77
+#: src/ch05-01-enums.md:88
msgid ""
"```rust\n"
-"let msg: Message = Message::Quit(());\n"
-"msg.process();\n"
-"```"
-msgstr ""
-"```rust\n"
-"let msg: Message = Message::Quit(());\n"
-"msg.process();\n"
-"```"
-
-#: src/ch05-01-enums.md:82
+"# use debug::PrintTrait;\n"
+"# #[derive(Drop)]\n"
+"# enum Message {\n"
+"# Quit: (),\n"
+"# Echo: felt252,\n"
+"# Move: (u128, u128),\n"
+"# }\n"
+"# \n"
+"# trait Processing {\n"
+"# fn process(self: Message);\n"
+"# }\n"
+"# \n"
+"# impl ProcessingImpl of Processing {\n"
+"# fn process(self: Message) {\n"
+"# match self {\n"
+"# Message::Quit(()) => {\n"
+"# 'quitting'.print();\n"
+"# },\n"
+"# Message::Echo(value) => {\n"
+"# value.print();\n"
+"# },\n"
+"# Message::Move((x, y)) => {\n"
+"# 'moving'.print();\n"
+"# },\n"
+"# }\n"
+"# }\n"
+"# }\n"
+"# fn main() {\n"
+" let msg: Message = Message::Quit(());\n"
+" msg.process();\n"
+"# }\n"
+"# \n"
+"# \n"
+"```"
+msgstr ""
+"```rust\n"
+"# use debug::PrintTrait;\n"
+"# #[derive(Drop)]\n"
+"# enum Message {\n"
+"# Quit: (),\n"
+"# Echo: felt252,\n"
+"# Move: (u128, u128),\n"
+"# }\n"
+"# \n"
+"# trait Processing {\n"
+"# fn process(self: Message);\n"
+"# }\n"
+"# \n"
+"# impl ProcessingImpl of Processing {\n"
+"# fn process(self: Message) {\n"
+"# match self {\n"
+"# Message::Quit(()) => {\n"
+"# 'quitting'.print();\n"
+"# },\n"
+"# Message::Echo(value) => {\n"
+"# value.print();\n"
+"# },\n"
+"# Message::Move((x, y)) => {\n"
+"# 'moving'.print();\n"
+"# },\n"
+"# }\n"
+"# }\n"
+"# }\n"
+"# fn main() {\n"
+" let msg: Message = Message::Quit(());\n"
+" msg.process();\n"
+"# }\n"
+"# \n"
+"# \n"
+"```"
+
+#: src/ch05-01-enums.md:124
msgid "Running this code would print `quitting`."
msgstr "Al ejecutar este código se imprimiría `quitting`."
-#: src/ch05-01-enums.md:84
+#: src/ch05-01-enums.md:126
msgid "## The Option Enum and Its Advantages"
msgstr "## El Enum Option y sus Ventajas"
-#: src/ch05-01-enums.md:86
+#: src/ch05-01-enums.md:128
msgid ""
"The Option enum is a standard Cairo enum that represents the concept of an optional value. It has two variants: `Some: T` and `None: ()`. `Some: T ` indicates that there's a value of "
"type `T`, while `None` represents the absence of a value."
@@ -7164,23 +7497,23 @@ msgstr ""
"El enum Option es un enum estándar en Cairo que representa el concepto de un valor opcional. Tiene dos variantes: `Some: T` y `None: ()`. `Some: T` indica que hay un valor de tipo "
"`T`, mientras que `None` representa la ausencia de un valor."
-#: src/ch05-01-enums.md:88
+#: src/ch05-01-enums.md:130 src/ch05-02-the-match-control-flow-construct.md:136 src/ch07-01-generic-data-types.md:174
msgid ""
-"```rs\n"
+"```rust\n"
"enum Option {\n"
" Some: T,\n"
" None: (),\n"
"}\n"
"```"
msgstr ""
-"```rs\n"
+"```rust\n"
"enum Option {\n"
" Some: T,\n"
" None: (),\n"
"}\n"
"```"
-#: src/ch05-01-enums.md:95
+#: src/ch05-01-enums.md:137
msgid ""
"The `Option` enum is helpful because it allows you to explicitly represent the possibility of a value being absent, making your code more expressive and easier to reason about. Using "
"`Option` can also help prevent bugs caused by using uninitialized or unexpected `null` values."
@@ -7188,15 +7521,15 @@ msgstr ""
"El enum `Option` es útil porque te permite representar explícitamente la posibilidad de que un valor esté ausente, lo que hace que tu código sea más expresivo y fácil de entender. "
"Usar `Option` también puede ayudar a prevenir errores causados por el uso de valores `null` no inicializados o inesperados."
-#: src/ch05-01-enums.md:97
+#: src/ch05-01-enums.md:139
msgid "To give you an example, here is a function which returns the index of the first element of an array with a given value, or None if the element is not present."
msgstr "Para darte un ejemplo, aquí hay una función que devuelve el índice del primer elemento de un arreglo con un valor dado, o `None` si el elemento no está presente."
-#: src/ch05-01-enums.md:99
+#: src/ch05-01-enums.md:141
msgid "We are demonstrating two approaches for the above function:"
msgstr "Estamos demostrando dos enfoques para la función anterior:"
-#: src/ch05-01-enums.md:101
+#: src/ch05-01-enums.md:143
msgid ""
"- Recursive Approach `find_value_recursive`\n"
"- Iterative Approach `find_value_iterative`"
@@ -7204,25 +7537,17 @@ msgstr ""
"- Método recursivo `find_value_recursive`\n"
"- Método iterativo find_value_iterative"
-#: src/ch05-01-enums.md:104
+#: src/ch05-01-enums.md:146
msgid "> Note: in the future it would be nice to replace this example by something simpler using a loop and without gas related code."
msgstr "> Nota: en el futuro sería bueno reemplazar este ejemplo con algo más simple que use un ciclo y sin código relacionado con el gas."
-#: src/ch05-01-enums.md:106
+#: src/ch05-01-enums.md:148
msgid ""
"```rust\n"
"use array::ArrayTrait;\n"
"use debug::PrintTrait;\n"
+"use option::OptionTrait;\n"
"fn find_value_recursive(arr: @Array, value: felt252, index: usize) -> Option {\n"
-" match gas::withdraw_gas() {\n"
-" Option::Some(_) => {},\n"
-" Option::None(_) => {\n"
-" let mut data = ArrayTrait::new();\n"
-" data.append('OOG');\n"
-" panic(data);\n"
-" },\n"
-" }\n"
-"\n"
" if index >= arr.len() {\n"
" return Option::None(());\n"
" }\n"
@@ -7231,12 +7556,12 @@ msgid ""
" return Option::Some(index);\n"
" }\n"
"\n"
-" find_value_recursive(arr, value, index + 1_usize)\n"
+" find_value_recursive(arr, value, index + 1)\n"
"}\n"
"\n"
"fn find_value_iterative(arr: @Array, value: felt252) -> Option {\n"
" let length = arr.len();\n"
-" let mut index = 0_usize;\n"
+" let mut index = 0;\n"
" let mut found: Option = Option::None(());\n"
" loop {\n"
" if index < length {\n"
@@ -7247,7 +7572,7 @@ msgid ""
" } else {\n"
" break ();\n"
" }\n"
-" index += 1_usize;\n"
+" index += 1;\n"
" };\n"
" return found;\n"
"}\n"
@@ -7262,13 +7587,12 @@ msgid ""
" my_array.append(5);\n"
"\n"
" let value_to_find = 7;\n"
-" let result = find_value_recursive(@my_array, value_to_find, 0_usize);\n"
+" let result = find_value_recursive(@my_array, value_to_find, 0);\n"
" let result_i = find_value_iterative(@my_array, value_to_find);\n"
"\n"
-"\n"
" match result {\n"
" Option::Some(index) => {\n"
-" if index == 1_usize {\n"
+" if index == 1 {\n"
" 'it worked'.print();\n"
" }\n"
" },\n"
@@ -7278,7 +7602,7 @@ msgid ""
" }\n"
" match result_i {\n"
" Option::Some(index) => {\n"
-" if index == 1_usize {\n"
+" if index == 1 {\n"
" 'it worked'.print();\n"
" }\n"
" },\n"
@@ -7293,16 +7617,8 @@ msgstr ""
"```rust\n"
"use array::ArrayTrait;\n"
"use debug::PrintTrait;\n"
+"use option::OptionTrait;\n"
"fn find_value_recursive(arr: @Array, value: felt252, index: usize) -> Option {\n"
-" match gas::withdraw_gas() {\n"
-" Option::Some(_) => {},\n"
-" Option::None(_) => {\n"
-" let mut data = ArrayTrait::new();\n"
-" data.append('OOG');\n"
-" panic(data);\n"
-" },\n"
-" }\n"
-"\n"
" if index >= arr.len() {\n"
" return Option::None(());\n"
" }\n"
@@ -7311,12 +7627,12 @@ msgstr ""
" return Option::Some(index);\n"
" }\n"
"\n"
-" find_value_recursive(arr, value, index + 1_usize)\n"
+" find_value_recursive(arr, value, index + 1)\n"
"}\n"
"\n"
"fn find_value_iterative(arr: @Array, value: felt252) -> Option {\n"
" let length = arr.len();\n"
-" let mut index = 0_usize;\n"
+" let mut index = 0;\n"
" let mut found: Option = Option::None(());\n"
" loop {\n"
" if index < length {\n"
@@ -7327,7 +7643,7 @@ msgstr ""
" } else {\n"
" break ();\n"
" }\n"
-" index += 1_usize;\n"
+" index += 1;\n"
" };\n"
" return found;\n"
"}\n"
@@ -7342,13 +7658,12 @@ msgstr ""
" my_array.append(5);\n"
"\n"
" let value_to_find = 7;\n"
-" let result = find_value_recursive(@my_array, value_to_find, 0_usize);\n"
+" let result = find_value_recursive(@my_array, value_to_find, 0);\n"
" let result_i = find_value_iterative(@my_array, value_to_find);\n"
"\n"
-"\n"
" match result {\n"
" Option::Some(index) => {\n"
-" if index == 1_usize {\n"
+" if index == 1 {\n"
" 'it worked'.print();\n"
" }\n"
" },\n"
@@ -7358,7 +7673,7 @@ msgstr ""
" }\n"
" match result_i {\n"
" Option::Some(index) => {\n"
-" if index == 1_usize {\n"
+" if index == 1 {\n"
" 'it worked'.print();\n"
" }\n"
" },\n"
@@ -7370,7 +7685,7 @@ msgstr ""
"\n"
"```"
-#: src/ch05-01-enums.md:186
+#: src/ch05-01-enums.md:219
msgid "Running this code would print `it worked`."
msgstr "Al ejecutar este código se imprimiría `it worked`."
@@ -7502,44 +7817,24 @@ msgstr ""
#: src/ch05-02-the-match-control-flow-construct.md:43
msgid ""
"```rust\n"
-"fn value_in_cents(coin: Coin) -> felt252 {\n"
-" match coin {\n"
-" Coin::Penny(_) => {\n"
-" ('Lucky penny!').print();\n"
-" 1\n"
-" },\n"
-" Coin::Nickel(_) => 5,\n"
-" Coin::Dime(_) => 10,\n"
-" Coin::Quarter(_)=> 25,\n"
-" }\n"
-"}\n"
+"\n"
"```"
msgstr ""
"```rust\n"
-"fn value_in_cents(coin: Coin) -> felt252 {\n"
-" match coin {\n"
-" Coin::Penny(_) => {\n"
-" ('Lucky penny!').print();\n"
-" 1\n"
-" },\n"
-" Coin::Nickel(_) => 5,\n"
-" Coin::Dime(_) => 10,\n"
-" Coin::Quarter(_)=> 25,\n"
-" }\n"
-"}\n"
+"\n"
"```"
-#: src/ch05-02-the-match-control-flow-construct.md:57
+#: src/ch05-02-the-match-control-flow-construct.md:47
msgid "## Patterns That Bind to Values"
msgstr "## Patrones que se Vinculan con Valores"
-#: src/ch05-02-the-match-control-flow-construct.md:59
+#: src/ch05-02-the-match-control-flow-construct.md:49
msgid "Another useful feature of match arms is that they can bind to the parts of the values that match the pattern. This is how we can extract values out of enum variants."
msgstr ""
"Otra característica útil de los brazos de coincidencia es que pueden vincularse con las partes de los valores que coinciden con el patrón. Así es como podemos extraer valores de las "
"variantes de una enum."
-#: src/ch05-02-the-match-control-flow-construct.md:61
+#: src/ch05-02-the-match-control-flow-construct.md:51
msgid ""
"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 "
@@ -7549,7 +7844,7 @@ msgstr ""
"25 centavos con diseños diferentes para cada uno de los 50 estados en un lado. Ninguna otra moneda tenía diseños estatales, por lo que solo los cuartos tienen este valor adicional. "
"Podemos agregar esta información a nuestra `enum` cambiando la variante `Quarter` para incluir un valor `UsState` almacenado en su interior, lo cual hemos hecho en la Lista 5-4."
-#: src/ch05-02-the-match-control-flow-construct.md:63
+#: src/ch05-02-the-match-control-flow-construct.md:53
msgid ""
"```rust\n"
"#[derive(Drop)]\n"
@@ -7563,7 +7858,7 @@ msgid ""
" Penny: (),\n"
" Nickel: (),\n"
" Dime: (),\n"
-" Quarter: (UsState),\n"
+" Quarter: (UsState, ),\n"
"}\n"
"```"
msgstr ""
@@ -7579,15 +7874,15 @@ msgstr ""
" Penny: (),\n"
" Nickel: (),\n"
" Dime: (),\n"
-" Quarter: (UsState),\n"
+" Quarter: (UsState, ),\n"
"}\n"
"```"
-#: src/ch05-02-the-match-control-flow-construct.md:79
+#: src/ch05-02-the-match-control-flow-construct.md:69
msgid "Listing 5-4: A `Coin` enum in which the `Quarter` variant also holds a `UsState` value"
msgstr "Listado 5-4: Un enum `Coin` en el que la variante `Quarter` también tiene un valor `UsState`"
-#: src/ch05-02-the-match-control-flow-construct.md:81
+#: src/ch05-02-the-match-control-flow-construct.md:71
msgid ""
"Let’s imagine that a friend is trying to collect all 50 state quarters. While we sort our loose change by coin type, we’ll also call out the name of the state associated with each "
"quarter so that if it’s one our friend doesn’t have, they can add it to their collection."
@@ -7595,7 +7890,7 @@ msgstr ""
"Imaginemos que un amigo está tratando de recolectar todas las 50 monedas de cuarto de estado. Mientras clasificamos nuestro cambio suelto por tipo de moneda, también llamaremos el "
"nombre del estado asociado con cada cuarto para que si es uno que nuestro amigo no tiene, puedan agregarlo a su colección."
-#: src/ch05-02-the-match-control-flow-construct.md:83
+#: src/ch05-02-the-match-control-flow-construct.md:73
msgid ""
"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:"
@@ -7603,7 +7898,7 @@ msgstr ""
"En la expresión `match` de este código, agregamos una variable llamada `state` al patrón que coincide con los valores de la variante `Coin::Quarter`. Cuando se hace una coincidencia "
"de `Coin::Quarter`, la variable `state` se vinculará al valor del estado de ese cuarto. Luego podemos usar `state` en el código para ese brazo, así:"
-#: src/ch05-02-the-match-control-flow-construct.md:85
+#: src/ch05-02-the-match-control-flow-construct.md:75
msgid ""
"```rust\n"
"fn value_in_cents(coin: Coin) -> felt252 {\n"
@@ -7611,7 +7906,7 @@ msgid ""
" Coin::Penny(_) => 1,\n"
" Coin::Nickel(_) => 5,\n"
" Coin::Dime(_) => 10,\n"
-" Coin::Quarter(state)=> {\n"
+" Coin::Quarter(state) => {\n"
" state.print();\n"
" 25\n"
" },\n"
@@ -7625,7 +7920,7 @@ msgstr ""
" Coin::Penny(_) => 1,\n"
" Coin::Nickel(_) => 5,\n"
" Coin::Dime(_) => 10,\n"
-" Coin::Quarter(state)=> {\n"
+" Coin::Quarter(state) => {\n"
" state.print();\n"
" 25\n"
" },\n"
@@ -7633,14 +7928,14 @@ msgstr ""
"}\n"
"```"
-#: src/ch05-02-the-match-control-flow-construct.md:99
+#: src/ch05-02-the-match-control-flow-construct.md:89
msgid "To print the value of a variant of an enum in Cairo, we need to add an implementation for the `print` function for the `debug::PrintTrait`:"
msgstr "Para imprimir el valor de una variante de un enum en Cairo, necesitamos agregar una implementación para la función `print` de `debug::PrintTrait`:"
-#: src/ch05-02-the-match-control-flow-construct.md:101
+#: src/ch05-02-the-match-control-flow-construct.md:91
msgid ""
"```rust\n"
-"impl UsStatePrintImpl of PrintTrait:: {\n"
+"impl UsStatePrintImpl of PrintTrait {\n"
" fn print(self: UsState) {\n"
" match self {\n"
" UsState::Alabama(_) => ('Alabama').print(),\n"
@@ -7651,7 +7946,7 @@ msgid ""
"```"
msgstr ""
"```rust\n"
-"impl UsStatePrintImpl of PrintTrait:: {\n"
+"impl UsStatePrintImpl of PrintTrait {\n"
" fn print(self: UsState) {\n"
" match self {\n"
" UsState::Alabama(_) => ('Alabama').print(),\n"
@@ -7661,7 +7956,7 @@ msgstr ""
"}\n"
"```"
-#: src/ch05-02-the-match-control-flow-construct.md:112
+#: src/ch05-02-the-match-control-flow-construct.md:102
msgid ""
"If we were to call `value_in_cents(Coin::Quarter(UsState::Alaska(())))`, `coin` would be `Coin::Quarter(UsState::Alaska())`. When we compare that value with each of the match arms, "
"none of them match until we reach `Coin::Quarter(state)`. At that point, the binding for state will be the value `UsState::Alaska()`. We can then use that binding in the "
@@ -7671,11 +7966,11 @@ msgstr ""
"`match`, ninguno coincide hasta que llegamos a `Coin::Quarter (state)`. En ese momento, la asignación para `state` será el valor `UsState::Alaska()`. Luego podemos usar esa "
"asignación en el `PrintTrait`, obteniendo así el valor interno de estado fuera de la variante `Coin` para `Quarter`."
-#: src/ch05-02-the-match-control-flow-construct.md:114
+#: src/ch05-02-the-match-control-flow-construct.md:104
msgid "## Matching with Options"
msgstr "## Coincidencia Con Opciones"
-#: src/ch05-02-the-match-control-flow-construct.md:116
+#: src/ch05-02-the-match-control-flow-construct.md:106
msgid ""
"In the previous section, we wanted to get the inner `T` value out of the `Some` case when using `Option`; we can also handle `Option` using `match`, as we did with the `Coin` "
"enum! Instead of comparing coins, we’ll compare the variants of `Option`, but the way the `match` expression works remains the same. You can use Options by importing the `option::"
@@ -7685,19 +7980,19 @@ msgstr ""
"`enum` `Coin`! En lugar de comparar monedas, compararemos las variantes de `Option`, pero la forma en que funciona la expresión `match` sigue siendo la misma. Puedes usar opciones "
"importando el trait `option::OptionTrait`."
-#: src/ch05-02-the-match-control-flow-construct.md:118
+#: src/ch05-02-the-match-control-flow-construct.md:108
msgid ""
-"Let’s say we want to write a function that takes an `Option` and, if there’s a value inside, adds `1_u8` to that value. If there isn’t a value inside, the function should return "
-"the `None` value and not attempt to perform any operations."
+"Let’s say we want to write a function that takes an `Option` and, if there’s a value inside, adds `1` to that value. If there isn’t a value inside, the function should return the "
+"`None` value and not attempt to perform any operations."
msgstr ""
-"Digamos que queremos escribir una función que tome una `Option` y, si hay un valor dentro, agregue `1_u8` a ese valor. Si no hay un valor dentro, la función debería devolver el "
+"Digamos que queremos escribir una función que tome una `Opción` y, si hay un valor dentro, añada `1` a ese valor. Si no hay ningún valor dentro, la función debería devolver el "
"valor `None` y no intentar realizar ninguna operación."
-#: src/ch05-02-the-match-control-flow-construct.md:120
+#: src/ch05-02-the-match-control-flow-construct.md:110
msgid "This function is very easy to write, thanks to match, and will look like Listing 5-5."
msgstr "Esta función es muy fácil de escribir, gracias a `match`, y se verá como en el listado 5-5."
-#: src/ch05-02-the-match-control-flow-construct.md:122
+#: src/ch05-02-the-match-control-flow-construct.md:112
msgid ""
"```rust\n"
"use option::OptionTrait;\n"
@@ -7705,13 +8000,13 @@ msgid ""
"\n"
"fn plus_one(x: Option) -> Option {\n"
" match x {\n"
-" Option::Some(val) => Option::Some(val + 1_u8),\n"
+" Option::Some(val) => Option::Some(val + 1),\n"
" Option::None(_) => Option::None(()),\n"
" }\n"
"}\n"
"\n"
"fn main() {\n"
-" let five: Option = Option::Some(5_u8);\n"
+" let five: Option = Option::Some(5);\n"
" let six: Option = plus_one(five);\n"
" six.unwrap().print();\n"
" let none = plus_one(Option::None(()));\n"
@@ -7725,13 +8020,13 @@ msgstr ""
"\n"
"fn plus_one(x: Option) -> Option {\n"
" match x {\n"
-" Option::Some(val) => Option::Some(val + 1_u8),\n"
+" Option::Some(val) => Option::Some(val + 1),\n"
" Option::None(_) => Option::None(()),\n"
" }\n"
"}\n"
"\n"
"fn main() {\n"
-" let five: Option = Option::Some(5_u8);\n"
+" let five: Option = Option::Some(5);\n"
" let six: Option = plus_one(five);\n"
" six.unwrap().print();\n"
" let none = plus_one(Option::None(()));\n"
@@ -7739,81 +8034,65 @@ msgstr ""
"}\n"
"```"
-#: src/ch05-02-the-match-control-flow-construct.md:142
+#: src/ch05-02-the-match-control-flow-construct.md:132
msgid "Listing 5-5: A function that uses a match expression on an `Option`"
msgstr "Listado 5-5: Una función que usa una expresión `match` en un `Option`"
-#: src/ch05-02-the-match-control-flow-construct.md:144
+#: src/ch05-02-the-match-control-flow-construct.md:134
msgid "Note that your arms must respect the same order as the enum defined in the `OptionTrait` of the core Cairo lib."
msgstr "Tenga en cuenta que los brazos (`arms`) deben respetar el mismo orden que el enum definido en `OptionTrait` de la librería central de Cairo."
-#: src/ch05-02-the-match-control-flow-construct.md:146
-msgid ""
-"```rust\n"
-" enum Option {\n"
-" Some: T,\n"
-" None: (),\n"
-" }\n"
-"```"
-msgstr ""
-"```rust\n"
-" enum Option {\n"
-" Some: T,\n"
-" None: (),\n"
-" }\n"
-"```"
-
-#: src/ch05-02-the-match-control-flow-construct.md:153
+#: src/ch05-02-the-match-control-flow-construct.md:143
msgid ""
-"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_u8)`. We then "
+"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:"
msgstr ""
-"Estudiemos con más detalle la primera ejecución de `plus_one`. Cuando llamamos a `plus_one(five)`, la variable `x` en el cuerpo de `plus_one` tendrá el valor `Some(5_u8)`. Luego, lo "
-"comparamos con cada rama del `match`:"
+"Examinemos más detalladamente la primera ejecución de `plus_one`. Cuando llamamos a `plus_one(five)`, la variable `x` en el cuerpo de `plus_one` tendrá el valor `Some(5)`. Luego "
+"comparamos eso con cada rama del `match`:"
-#: src/ch05-02-the-match-control-flow-construct.md:155 src/ch05-02-the-match-control-flow-construct.md:163
+#: src/ch05-02-the-match-control-flow-construct.md:145 src/ch05-02-the-match-control-flow-construct.md:153
msgid ""
"```rust\n"
-" Option::Some(val) => Option::Some(val + 1_u8),\n"
+" Option::Some(val) => Option::Some(val + 1),\n"
"```"
msgstr ""
"```rust\n"
-" Option::Some(val) => Option::Some(val + 1_u8),\n"
+" Option::Some(val) => Option::Some(val + 1),\n"
"```"
-#: src/ch05-02-the-match-control-flow-construct.md:159
+#: src/ch05-02-the-match-control-flow-construct.md:149
msgid ""
-"Does `Option::Some(5_u8)` 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_u8`. The code in the match arm is then executed, so we add `1_u8` to the value of `val` and create a new `Option::Some` value with our total `6_u8` inside. Because the first "
-"arm matched, no other arms are compared."
+"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."
msgstr ""
-"¿El valor `Option::Some(5_u8)` coincide con el patrón `Option::Some(val)`? ¡Sí! Tenemos la misma variante. `val` se vincula al valor contenido en `Option::Some`, por lo que `val` "
-"toma el valor `5_u8`. Luego se ejecuta el código en el brazo del `match`, por lo que agregamos `1_u8` al valor de `val` y creamos un nuevo valor `Option::Some` con nuestro total "
-"`6_u8` en su interior. Debido a que se ha realizado la primera coincidencia, no se comparan otros brazos."
+"¿El valor `Option::Some(5)` coincide con el patrón `Option::Some(val)`? ¡Sí lo hace! Tenemos la misma variante. El `val` se enlaza al valor contenido en `Option::Some`, por lo que "
+"`val` toma el valor `5`. Luego se ejecuta el código en el brazo del `match`, por lo que sumamos `1` al valor de `val` y creamos un nuevo valor `Option::Some` con nuestro total `6` en "
+"su interior. Debido a que el primer brazo coincide, no se comparan los demás brazos."
-#: src/ch05-02-the-match-control-flow-construct.md:161
+#: src/ch05-02-the-match-control-flow-construct.md:151
msgid "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:"
msgstr "Ahora consideremos la segunda llamada de `plus_one` en nuestra función principal, donde `x` es `Option::None(())`. Entramos en el `match` y comparamos con el primer brazo:"
-#: src/ch05-02-the-match-control-flow-construct.md:167
+#: src/ch05-02-the-match-control-flow-construct.md:157
msgid "The `Option::Some(val)` value doesn’t match the pattern `Option::None`, so we continue to the next arm:"
msgstr "El valor `Option::Some(5_u8)` no coincide con el patrón `Option::None`, así que continuamos con el siguiente brazo:"
-#: src/ch05-02-the-match-control-flow-construct.md:169
+#: src/ch05-02-the-match-control-flow-construct.md:159
msgid ""
"```rust\n"
-" Option::None(_) => Option::None(()),\n"
+" Option::None(_) => Option::None(()),\n"
"```"
msgstr ""
"```rust\n"
-" Option::None(_) => Option::None(()),\n"
+" Option::None(_) => Option::None(()),\n"
"```"
-#: src/ch05-02-the-match-control-flow-construct.md:173
+#: src/ch05-02-the-match-control-flow-construct.md:163
msgid "It matches! There’s no value to add to, so the program stops and returns the `Option::None(())` value on the right side of `=>`."
msgstr "¡Coincide! No hay valor al que agregar, por lo que el programa se detiene y devuelve el valor `Option::None(())` en el lado derecho de `=>`."
-#: src/ch05-02-the-match-control-flow-construct.md:175
+#: src/ch05-02-the-match-control-flow-construct.md:165
msgid ""
"Combining `match` and enums is useful in many situations. You’ll see this pattern a lot in Cairo code: `match` against an enum, bind a variable to the data inside, and then execute "
"code based on it. It’s a bit tricky at first, but once you get used to it, you’ll wish you had it in all languages. It’s consistently a user favorite."
@@ -7822,11 +8101,11 @@ msgstr ""
"internos y luego ejecuta código basado en ella. Es un poco complicado al principio, pero una vez que te acostumbras, desearás tenerlo en todos los lenguajes. Es consistentemente "
"favorito de los usuarios."
-#: src/ch05-02-the-match-control-flow-construct.md:177
+#: src/ch05-02-the-match-control-flow-construct.md:167
msgid "## Matches Are Exhaustive"
msgstr "## Los Matches Son Exhaustivos"
-#: src/ch05-02-the-match-control-flow-construct.md:179
+#: src/ch05-02-the-match-control-flow-construct.md:169
msgid ""
"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:"
@@ -7834,7 +8113,25 @@ msgstr ""
"Hay otro aspecto de los matches que necesitamos discutir: los patrones de los brazos deben cubrir todas las posibilidades. Considera esta versión de nuestra función `plus_one`, que "
"tiene un error y no se compilará:"
-#: src/ch05-02-the-match-control-flow-construct.md:181
+#: src/ch05-02-the-match-control-flow-construct.md:171
+msgid ""
+"```rust\n"
+"fn plus_one(x: Option) -> Option {\n"
+" match x {\n"
+" Option::Some(val) => Option::Some(val + 1), \n"
+" }\n"
+"}\n"
+"```"
+msgstr ""
+"```rust\n"
+"fn plus_one(x: Option) -> Option {\n"
+" match x {\n"
+" Option::Some(val) => Option::Some(val + 1), \n"
+" }\n"
+"}\n"
+"```"
+
+#: src/ch05-02-the-match-control-flow-construct.md:179
msgid ""
"```bash\n"
"$ cairo-run src/test.cairo\n"
@@ -7856,7 +8153,7 @@ msgstr ""
" Error: failed to compile: ./src/test.cairo\n"
"```"
-#: src/ch05-02-the-match-control-flow-construct.md:191
+#: src/ch05-02-the-match-control-flow-construct.md:189
msgid ""
"Cairo knows that we didn’t cover every possible case, and even knows which pattern we forgot! Matches in Cairo are exhaustive: we must exhaust every last possibility in order for the "
"code to be valid. Especially in the case of `Option`, when Cairo prevents us from forgetting to explicitly handle the `None` case, it protects us from assuming that we have a "
@@ -7866,26 +8163,26 @@ msgstr ""
"código sea válido. Especialmente en el caso de `Option`, cuando Cairo nos impide olvidar manejar explícitamente el caso `None`, nos protege de asumir que tenemos un valor cuando "
"podríamos tener nulo, lo que hace imposible el error de mil millones de dólares discutido anteriormente."
-#: src/ch05-02-the-match-control-flow-construct.md:193
+#: src/ch05-02-the-match-control-flow-construct.md:191
msgid "## Match 0 and the \\_ Placeholder"
msgstr "## Match 0 y el Comodín \\_"
-#: src/ch05-02-the-match-control-flow-construct.md:195
+#: src/ch05-02-the-match-control-flow-construct.md:193
msgid ""
"Using enums, we can also take special actions for a few particular values, but for all other values take one default action. Currently only `0` and the `_`operator are supported."
msgstr ""
"Usando enums, también podemos tomar acciones especiales para algunos valores particulares, pero para todos los demás valores tomar una acción predeterminada. Actualmente solo se "
"admiten `0` y el operador `_`."
-#: src/ch05-02-the-match-control-flow-construct.md:197
+#: src/ch05-02-the-match-control-flow-construct.md:195
msgid ""
-"Imagine we’re implementing a game where, you get a random number between 0 and 7. If you have 0, you win. For all other values you loose. Here's a match that implements that logic, "
+"Imagine we’re implementing a game where, you get a random number between 0 and 7. If you have 0, you win. For all other values you lose. Here's a match that implements that logic, "
"with the number hardcoded rather than a random value."
msgstr ""
-"Imaginemos que estamos implementando un juego en el que obtienes un número aleatorio entre 0 y 7. Si tienes 0, ganas. Para todos los demás valores pierdes. Aquí hay un match que "
-"implementa esa lógica, con el número codificado en lugar de un valor aleatorio."
+"Imaginemos que estamos implementando un juego en el que obtienes un número aleatorio entre 0 y 7. Si tienes 0, ganas. Para todos los demás valores, pierdes. Aquí hay un `match` que "
+"implementa esa lógica, con el número codificado en lugar de ser un valor aleatorio."
-#: src/ch05-02-the-match-control-flow-construct.md:199
+#: src/ch05-02-the-match-control-flow-construct.md:197
msgid ""
"```rust\n"
"fn did_i_win(nb: felt252) {\n"
@@ -7905,7 +8202,7 @@ msgstr ""
"}\n"
"```"
-#: src/ch05-02-the-match-control-flow-construct.md:208
+#: src/ch05-02-the-match-control-flow-construct.md:206
msgid ""
"The first arm, the pattern is the literal values 0. For the last arm that covers every other possible value, the pattern is the character `_`. This code compiles, even though we "
"haven’t listed all the possible values a `felt252` can have, because the last pattern will match all values not specifically listed. This catch-all pattern meets the requirement that "
@@ -7917,7 +8214,7 @@ msgstr ""
"cumple el requisito de que `match` debe ser exhaustivo. Tenga en cuenta que tenemos que poner la rama catch-all en último lugar porque los patrones se evalúan en orden. Si pusiéramos "
"el brazo catch-all antes, los otros brazos nunca se ejecutarían, ¡así que Cairo nos avisará si añadimos brazos después de un catch-all!"
-#: src/ch05-02-the-match-control-flow-construct.md:210
+#: src/ch05-02-the-match-control-flow-construct.md:208
msgid ""
msgstr ""
@@ -8099,12 +8396,12 @@ msgid ""
"- `src/` is the main directory where all the Cairo source files for the package will be stored.\n"
"- `lib.cairo` is the default root module of the crate, which is also the main entry point of the package. By default, it is empty.\n"
"- `Scarb.toml` is the package manifest file, which contains metadata and configuration options for the package, such as dependencies, package name, version, and authors. You can find "
-"documentation about it on the [scarb reference](https://docs.swmansion.com/scarb/docs/reference/manifest)."
+"documentation about it on the [scarb reference](https://docs.swmansion.com/scarb/docs/reference/manifest.html)."
msgstr ""
"- `src/` es el directorio principal donde se almacenarán todos los archivos de origen de Cairo para el paquete.\n"
"- `lib.cairo` es el módulo raíz predeterminado del crate, que también es el punto de entrada principal del paquete. Por defecto, está vacío.\n"
"- `Scarb.toml` es el archivo de manifiesto del paquete, que contiene metadatos y opciones de configuración para el paquete, como dependencias, nombre del paquete, versión y autores. "
-"Puede encontrar documentación al respecto en la [referencia de Scarb](https://docs.swmansion.com/scarb/docs/reference/manifest)."
+"Puede encontrar documentación al respecto en la [referencia de Scarb](https://docs.swmansion.com/scarb/docs/reference/manifest.html)."
#: src/ch06-01-packages-and-crates.md:33
msgid ""
@@ -8329,39 +8626,37 @@ msgstr "El archivo raíz de la caja en este caso es _src/lib.cairo_, y contiene:
#: src/ch06-02-defining-modules-to-control-scope.md:92
msgid ""
-"```rust,does_not_compile\n"
+"```rust\n"
+"// does_not_compile\n"
"use garden::vegetables::Asparagus;\n"
"\n"
"mod garden;\n"
"\n"
-"fn main(){\n"
-" let Asparagus = Asparagus{};\n"
+"fn main() {\n"
+" let Asparagus = Asparagus {};\n"
"}\n"
-"\n"
-"\n"
"```"
msgstr ""
-"```rust,does_not_compile\n"
+"```rust\n"
+"// does_not_compile\n"
"use garden::vegetables::Asparagus;\n"
"\n"
"mod garden;\n"
"\n"
-"fn main(){\n"
-" let Asparagus = Asparagus{};\n"
+"fn main() {\n"
+" let Asparagus = Asparagus {};\n"
"}\n"
-"\n"
-"\n"
"```"
-#: src/ch06-02-defining-modules-to-control-scope.md:104
+#: src/ch06-02-defining-modules-to-control-scope.md:103
msgid "The `mod garden;` line tells the compiler to include the code it finds in _src/garden.cairo_, which is:"
msgstr "La línea `mod garden;` le indica al compilador que incluya el código que encuentra en _src/garden.cairo_, que es:"
-#: src/ch06-02-defining-modules-to-control-scope.md:106
+#: src/ch06-02-defining-modules-to-control-scope.md:105
msgid "Filename: src/garden.cairo"
msgstr "Filename: src/garden.cairo"
-#: src/ch06-02-defining-modules-to-control-scope.md:108
+#: src/ch06-02-defining-modules-to-control-scope.md:107
msgid ""
"```rust\n"
"mod vegetables;\n"
@@ -8371,25 +8666,25 @@ msgstr ""
"mod vegetables;\n"
"```"
-#: src/ch06-02-defining-modules-to-control-scope.md:112
+#: src/ch06-02-defining-modules-to-control-scope.md:111
msgid ""
"Here, `mod vegetables;` means the code in _src/garden/vegetables.cairo_ is\n"
"included too. That code is:"
msgstr "Aquí, `mod vegetables;` significa que el código en _src/garden/vegetables.cairo_ también está incluido. Ese código es:"
-#: src/ch06-02-defining-modules-to-control-scope.md:115
+#: src/ch06-02-defining-modules-to-control-scope.md:114
msgid ""
"```rust\n"
-"#[derive(Copy,Drop)]\n"
-"struct Asparagus{}\n"
+"#[derive(Copy, Drop)]\n"
+"struct Asparagus {}\n"
"```"
msgstr ""
"```rust\n"
-"#[derive(Copy,Drop)]\n"
-"struct Asparagus{}\n"
+"#[derive(Copy, Drop)]\n"
+"struct Asparagus {}\n"
"```"
-#: src/ch06-02-defining-modules-to-control-scope.md:120
+#: src/ch06-02-defining-modules-to-control-scope.md:119
msgid ""
"The line `use garden::vegetables::Asparagus;` lets us use bring the `Asparagus` type into scope,\n"
"so we can use it in the `main` function."
@@ -8397,15 +8692,15 @@ msgstr ""
"La línea `use garden::vegetables::Asparagus;` nos permite traer el tipo `Asparagus` al ámbito de alcance, \n"
"para que podamos usarlo en la función `main`."
-#: src/ch06-02-defining-modules-to-control-scope.md:123
+#: src/ch06-02-defining-modules-to-control-scope.md:122
msgid "Now let’s get into the details of these rules and demonstrate them in action!"
msgstr "¡Ahora vamos a entrar en los detalles de estas reglas y demostrarlas en acción!"
-#: src/ch06-02-defining-modules-to-control-scope.md:125
+#: src/ch06-02-defining-modules-to-control-scope.md:124
msgid "### Grouping Related Code in Modules"
msgstr "### Agrupando el Código Relacionado en Módulos"
-#: src/ch06-02-defining-modules-to-control-scope.md:127
+#: src/ch06-02-defining-modules-to-control-scope.md:126
msgid ""
"_Modules_ let us organize code within a crate for readability and easy reuse.\n"
"As an example, let’s write a library crate that provides the functionality of a\n"
@@ -8419,7 +8714,7 @@ msgstr ""
"vacíos para concentrarnos en la organización del código, en lugar de \n"
"en la implementación de un restaurante."
-#: src/ch06-02-defining-modules-to-control-scope.md:133
+#: src/ch06-02-defining-modules-to-control-scope.md:132
msgid ""
"In the restaurant industry, some parts of a restaurant are referred to as\n"
"_front of house_ and others as _back of house_. Front of house is where\n"
@@ -8435,7 +8730,7 @@ msgstr ""
"chefs y cocineros trabajan en la cocina, los lavaplatos limpian y los gerentes hacen\n"
" trabajo administrativo."
-#: src/ch06-02-defining-modules-to-control-scope.md:140
+#: src/ch06-02-defining-modules-to-control-scope.md:139
msgid ""
"To structure our crate in this way, we can organize its functions into nested\n"
"modules. Create a new package named `restaurant` by running `scarb new restaurant`; then enter the code in Listing 6-1 into _src/lib.cairo_ to\n"
@@ -8445,7 +8740,7 @@ msgstr ""
"anidados. Cree un nuevo paquete llamado `restaurant` ejecutando el comando `scarb new restaurant`; luego ingrese el código en el Listado 6-1 en _src/lib.cairo_ para definir algunos "
"módulos y firmas de funciones. Aquí está la sección de front of house:"
-#: src/ch06-02-defining-modules-to-control-scope.md:146
+#: src/ch06-02-defining-modules-to-control-scope.md:145
msgid ""
"```rust\n"
"mod front_of_house {\n"
@@ -8483,7 +8778,7 @@ msgstr ""
"}\n"
"```"
-#: src/ch06-02-defining-modules-to-control-scope.md:164
+#: src/ch06-02-defining-modules-to-control-scope.md:163
msgid ""
"Listing 6-1: A `front_of_house` module containing other\n"
"modules that then contain functions"
@@ -8491,7 +8786,7 @@ msgstr ""
"Listado 6-1: Un módulo `front_of_house` que contiene otros \n"
"módulos que a su vez contienen funciones"
-#: src/ch06-02-defining-modules-to-control-scope.md:167
+#: src/ch06-02-defining-modules-to-control-scope.md:166
msgid ""
"We define a module with the `mod` keyword followed by the name of the module\n"
"(in this case, `front_of_house`). The body of the module then goes inside curly\n"
@@ -8507,7 +8802,7 @@ msgstr ""
" elementos, como structs, enums, constantes, traits y, como en el Listado \n"
"6-1, funciones."
-#: src/ch06-02-defining-modules-to-control-scope.md:174
+#: src/ch06-02-defining-modules-to-control-scope.md:173
msgid ""
"By using modules, we can group related definitions together and name why\n"
"they’re related. Programmers using this code can navigate the code based on the\n"
@@ -8521,7 +8816,7 @@ msgstr ""
"encontrar las definiciones relevantes para ellos. Los programadores que agregan nueva funcionalidad \n"
"a este código sabrían dónde colocar el código para mantener el programa organizado."
-#: src/ch06-02-defining-modules-to-control-scope.md:180
+#: src/ch06-02-defining-modules-to-control-scope.md:179
msgid ""
"Earlier, we mentioned that _src/lib.cairo_ is called the crate\n"
"root. The reason for this name is that the content of this file form a module named after the crate name at the root of the crate’s module structure,\n"
@@ -8531,11 +8826,11 @@ msgstr ""
"caja. La razón de este nombre es que el contenido de este archivo forma un módulo con el nombre de la caja en la raíz de la estructura de módulos de la caja, conocido como el _árbol "
"de módulos_."
-#: src/ch06-02-defining-modules-to-control-scope.md:184
+#: src/ch06-02-defining-modules-to-control-scope.md:183
msgid "Listing 6-2 shows the module tree for the structure in Listing 6-1."
msgstr "El Listado 6-2 muestra el árbol de módulos para la estructura en el Listado 6-1."
-#: src/ch06-02-defining-modules-to-control-scope.md:186
+#: src/ch06-02-defining-modules-to-control-scope.md:185
msgid ""
"```text\n"
"restaurant\n"
@@ -8561,7 +8856,7 @@ msgstr ""
" └── take_payment\n"
"```"
-#: src/ch06-02-defining-modules-to-control-scope.md:198
+#: src/ch06-02-defining-modules-to-control-scope.md:197
msgid ""
"Listing 6-2: The module tree for the code in Listing\n"
"6-1"
@@ -8569,7 +8864,7 @@ msgstr ""
"Listing 6-2: El árbol de módulos para el código en el Listado\n"
"6-1"
-#: src/ch06-02-defining-modules-to-control-scope.md:201
+#: src/ch06-02-defining-modules-to-control-scope.md:200
msgid ""
"This tree shows how some of the modules nest inside one another; for example,\n"
"`hosting` nests inside `front_of_house`. The tree also shows that some modules\n"
@@ -8587,7 +8882,7 @@ msgstr ""
"y que el módulo B es el _padre_ del módulo A. Observa que todo el árbol de módulos \n"
"está enraizado en el nombre explícito del paquete `restaurant`."
-#: src/ch06-02-defining-modules-to-control-scope.md:209
+#: src/ch06-02-defining-modules-to-control-scope.md:208
msgid ""
"The module tree might remind you of the filesystem’s directory tree on your\n"
"computer; this is a very apt comparison! Just like directories in a filesystem,\n"
@@ -8657,7 +8952,7 @@ msgid ""
"}\n"
"\n"
"\n"
-"pub fn eat_at_restaurant() {\n"
+"fn eat_at_restaurant() {\n"
" // Absolute path\n"
" restaurant::front_of_house::hosting::add_to_waitlist(); // ✅ Compiles\n"
"\n"
@@ -8684,7 +8979,7 @@ msgstr ""
"}\n"
"\n"
"\n"
-"pub fn eat_at_restaurant() {\n"
+"fn eat_at_restaurant() {\n"
" // Absolute path\n"
" restaurant::front_of_house::hosting::add_to_waitlist(); // ✅ Compiles\n"
"\n"
@@ -8798,6 +9093,7 @@ msgstr ""
#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:12
msgid ""
"```rust\n"
+"// does_not_compile\n"
"mod front_of_house {\n"
" mod hosting {\n"
" fn add_to_waitlist() {}\n"
@@ -8812,6 +9108,7 @@ msgid ""
"```"
msgstr ""
"```rust\n"
+"// does_not_compile\n"
"mod front_of_house {\n"
" mod hosting {\n"
" fn add_to_waitlist() {}\n"
@@ -8825,7 +9122,7 @@ msgstr ""
"}\n"
"```"
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:26
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:27
msgid ""
"Listing 6-5: Bringing a module into scope with\n"
"`use`"
@@ -8833,7 +9130,7 @@ msgstr ""
"Listado 6-5: Introducir un módulo en el ámbito con\n"
"`use`"
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:29
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:30
msgid ""
"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."
@@ -8841,7 +9138,7 @@ msgstr ""
"Añadir use y una ruta en un ámbito es similar a crear un enlace simbólico en el sistema de ficheros. Al añadir `use restaurant::front_of_house::hosting` en la raíz de crate, hosting "
"es ahora un nombre válido en ese ámbito, como si el módulo `hosting` se hubiera definido en la raíz de un crate."
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:31
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:32
msgid ""
"Note that `use` only creates the shortcut for the particular scope in which the `use` occurs. Listing 6-6 moves the `eat_at_restaurant` function into a new\n"
"child module named `customer`, which is then a different scope than the `use`\n"
@@ -8852,9 +9149,10 @@ msgstr ""
"módulo hijo llamado `customer`, que es un ámbito diferente al de la sentencia `use\n"
"por lo que el cuerpo de la función no compilará:"
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:37
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:38
msgid ""
"```rust\n"
+"// does_not_compile\n"
"mod front_of_house {\n"
" mod hosting {\n"
" fn add_to_waitlist() {}\n"
@@ -8871,6 +9169,7 @@ msgid ""
"```"
msgstr ""
"```rust\n"
+"// does_not_compile\n"
"mod front_of_house {\n"
" mod hosting {\n"
" fn add_to_waitlist() {}\n"
@@ -8886,7 +9185,7 @@ msgstr ""
"}\n"
"```"
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:53
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:55
msgid ""
"Listing 6-6: A `use` statement only applies in the scope\n"
"it’s in"
@@ -8894,7 +9193,7 @@ msgstr ""
"Listado 6-6: Una sentencia `use` sólo se aplica en el ámbito\n"
"en el que se encuentra"
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:56
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:58
msgid ""
"The compiler error shows that the shortcut no longer applies within the\n"
"`customer` module:"
@@ -8902,7 +9201,7 @@ msgstr ""
"El error del compilador muestra que el acceso directo ya no se aplica dentro del módulo\n"
"módulo `customer`:"
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:59
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:61
msgid ""
"```console\n"
"❯ scarb build\n"
@@ -8920,11 +9219,11 @@ msgstr ""
" ^*****^\n"
"```"
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:67
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:69
msgid "## Creating Idiomatic `use` Paths"
msgstr "## Crear Rutas idiomáticas `use`"
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:69
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:71
msgid ""
"In Listing 6-5, you might have wondered why we specified `use\n"
"restaurant::front_of_house::hosting` and then called `hosting::add_to_waitlist` in\n"
@@ -8936,39 +9235,37 @@ msgstr ""
"en `eat_at_restaurant` en lugar de especificar la ruta `use\n"
"la función `add_to_waitlist` para conseguir el mismo resultado, como en el Listado 6-7."
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:76
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:78
msgid ""
"```rust\n"
"mod front_of_house {\n"
-" pub mod hosting {\n"
-" pub fn add_to_waitlist() {}\n"
+" mod hosting {\n"
+" fn add_to_waitlist() {}\n"
" }\n"
"}\n"
"\n"
"use restaurant::front_of_house::hosting::add_to_waitlist;\n"
"\n"
-"pub fn eat_at_restaurant() {\n"
+"fn eat_at_restaurant() {\n"
" add_to_waitlist();\n"
"}\n"
-"\n"
"```"
msgstr ""
"```rust\n"
"mod front_of_house {\n"
-" pub mod hosting {\n"
-" pub fn add_to_waitlist() {}\n"
+" mod hosting {\n"
+" fn add_to_waitlist() {}\n"
" }\n"
"}\n"
"\n"
"use restaurant::front_of_house::hosting::add_to_waitlist;\n"
"\n"
-"pub fn eat_at_restaurant() {\n"
+"fn eat_at_restaurant() {\n"
" add_to_waitlist();\n"
"}\n"
-"\n"
"```"
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:91
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:92
msgid ""
"Listing 6-7: Bringing the `add_to_waitlist` function\n"
"into scope with `use`, which is unidiomatic"
@@ -8976,7 +9273,7 @@ msgstr ""
"Listado 6-7: Introduciendo la función `add_to_waitlist\n"
"con `use`, que es poco idiomático"
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:94
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:95
msgid ""
"Although both Listing 6-5 and 6-7 accomplish the same task, Listing 6-5 is\n"
"the idiomatic way to bring a function into scope with `use`. Bringing the\n"
@@ -8994,7 +9291,7 @@ msgstr ""
"a la vez que minimiza la repetición de la ruta completa. El código del Listado 6-7 es\n"
"no está claro dónde está definido `add_to_waitlist`."
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:102
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:103
msgid ""
"On the other hand, when bringing in structs, enums, traits, and other items with `use`,\n"
"it’s idiomatic to specify the full path. Listing 6-8 shows the idiomatic way\n"
@@ -9004,7 +9301,7 @@ msgstr ""
"es idiomático especificar la ruta completa. El listado 6-8 muestra la forma idiomática\n"
"de traer el trait `ArrayTrait` de la librería core al ámbito."
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:106
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:107
msgid ""
"```rust\n"
"use array::ArrayTrait;\n"
@@ -9024,7 +9321,7 @@ msgstr ""
"}\n"
"```"
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:115
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:116
msgid ""
"Listing 6-8: Bringing `ArrayTrait` into scope in an\n"
"idiomatic way"
@@ -9032,7 +9329,7 @@ msgstr ""
"Listado 6-8: Introducir `ArrayTrait` en el ámbito de forma\n"
"forma idiomática"
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:118
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:119
msgid ""
"There’s no strong reason behind this idiom: it’s just the convention that has\n"
"emerged in the Rust community, and folks have gotten used to reading and writing Rust code this way.\n"
@@ -9042,7 +9339,7 @@ msgstr ""
"surgido en la comunidad Rust y la gente se ha acostumbrado a leer y escribir código Rust de esta manera.\n"
"Como Cairo comparte muchos modismos con Rust, nosotros también seguimos esta convención."
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:122
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:123
msgid ""
"The exception to this idiom is if we’re bringing two items with the same name\n"
"into scope with `use` statements, because Cairo doesn’t allow that."
@@ -9050,11 +9347,11 @@ msgstr ""
"La excepción a este modismo es si estamos trayendo dos elementos con el mismo nombre\n"
"con sentencias `use`, porque Cairo no lo permite."
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:125
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:126
msgid "### Providing New Names with the `as` Keyword"
msgstr "### Proporcionar nuevos nombres con la Palabra Clave `as`"
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:127
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:128
msgid ""
"There’s another solution to the problem of bringing two types of the same name\n"
"into the same scope with `use`: after the path, we can specify `as` and a new\n"
@@ -9064,12 +9361,12 @@ msgstr ""
"en el mismo ámbito con `use`: después de la ruta, podemos especificar `as` y un nuevo\n"
"nombre local, o _alias_, para el tipo. El listado 6-9 muestra cómo puedes renombrar una importación con `as`:"
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:133
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:134
msgid ""
"```rust\n"
"use array::ArrayTrait as Arr;\n"
"\n"
-"fn main(){\n"
+"fn main() {\n"
" let mut arr = Arr::new(); // ArrayTrait was renamed to Arr\n"
" arr.append(1);\n"
"}\n"
@@ -9078,13 +9375,13 @@ msgstr ""
"```rust\n"
"use array::ArrayTrait as Arr;\n"
"\n"
-"fn main(){\n"
+"fn main() {\n"
" let mut arr = Arr::new(); // ArrayTrait was renamed to Arr\n"
" arr.append(1);\n"
"}\n"
"```"
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:142
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:143
msgid ""
"Listing 6-9: Renaming a trait when it’s brought into\n"
"scope with the `as` keyword"
@@ -9092,47 +9389,153 @@ msgstr ""
"Listado 6-9: Renombrar un trait cuando es traído a\n"
"scope con la palabra clave `as`"
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:145
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:146
msgid "Here, we brought `ArrayTrait` into scope with the alias `Arr`. We can now access the trait's methods with the `Arr` identifier."
msgstr "En este caso, hemos introducido `ArrayTrait` en el ámbito con el alias `Arr`. Ahora podemos acceder a los métodos del rasgo con el identificador `Arr`."
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:147
-msgid "## Re-exporting Names in Module Files"
-msgstr "## Re-exportación de Nombres en Archivos de Módulo"
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:148
+msgid "### Importing multiple items from the same module"
+msgstr "### Importar varios elementos desde el mismo módulo"
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:149
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:150
msgid ""
-"When we bring a name into scope with the `use` keyword, the name available in\n"
-"the new scope can be imported as if it had been defined in that code’s scope.\n"
-"This technique is called _re-exporting_ because we’re bringing an item into scope,\n"
-"but also making that item available for others to bring into their scope."
+"When you want to import multiple items (like functions, structs or enums)\n"
+"from the same module in Cairo, you can use curly braces `{}` to list all of\n"
+"the items that you want to import. This helps to keep your code clean and easy\n"
+"to read by avoiding a long list of individual use statements."
msgstr ""
-"Cuando traemos un nombre al ámbito con la palabra clave `use`, el nombre disponible en\n"
-"el nuevo ámbito puede ser importado como si hubiera sido definido en el ámbito de ese código.\n"
-"Esta técnica se llama _re-exporting_ porque estamos trayendo un elemento al ámbito,\n"
-"pero también haciendo que ese elemento esté disponible para que otros lo introduzcan en su ámbito."
+"Cuando quieras importar múltiples elementos (como funciones, structs o enums)\n"
+"del mismo módulo en Cairo, puede usar llaves `{}` para listar todos los\n"
+"los elementos que desea importar. Esto ayuda a mantener su código limpio y fácil\n"
+"de leer evitando una larga lista de sentencias use individuales."
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:154
-msgid "For example, let's re-export the `add_to_waitlist` function in the restaurant example:"
-msgstr "Por ejemplo, reexportemos la función `add_to_waitlist` del ejemplo del restaurante:"
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:155
+msgid "The general syntax for importing multiple items from the same module is:"
+msgstr "La sintaxis general para importar varios elementos del mismo módulo es:"
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:158
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:157
msgid ""
-"```rs\n"
-"mod front_of_house {\n"
-" mod hosting {\n"
-" fn add_to_waitlist() {}\n"
-" }\n"
-"}\n"
-"\n"
-"use restaurant::front_of_house::hosting;\n"
-"\n"
-"fn eat_at_restaurant() {\n"
-" hosting::add_to_waitlist();\n"
-"}\n"
+"```rust\n"
+"use module::{item1, item2, item3};\n"
"```"
msgstr ""
-"```rs\n"
+"```rust\n"
+"use module::{item1, item2, item3};\n"
+"```"
+
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:161
+msgid "Here is an example where we import three structures from the same module:"
+msgstr "He aquí un ejemplo en el que importamos tres estructuras del mismo módulo:"
+
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:163
+msgid ""
+"```rust\n"
+"// Assuming we have a module called `shapes` with the structures `Square`, `Circle`, and `Triangle`.\n"
+"mod shapes {\n"
+" #[derive(Drop)]\n"
+" struct Square {\n"
+" side: u32\n"
+" }\n"
+"\n"
+" #[derive(Drop)]\n"
+" struct Circle {\n"
+" radius: u32\n"
+" }\n"
+"\n"
+" #[derive(Drop)]\n"
+" struct Triangle {\n"
+" base: u32,\n"
+" height: u32,\n"
+" }\n"
+"}\n"
+"\n"
+"// We can import the structures `Square`, `Circle`, and `Triangle` from the `shapes` module like this:\n"
+"use shapes::{Square, Circle, Triangle};\n"
+"\n"
+"// Now we can directly use `Square`, `Circle`, and `Triangle` in our code.\n"
+"fn main() {\n"
+" let sq = Square { side: 5 };\n"
+" let cr = Circle { radius: 3 };\n"
+" let tr = Triangle { base: 5, height: 2 };\n"
+"// ...\n"
+"}\n"
+"```"
+msgstr ""
+"```rust\n"
+"// Assuming we have a module called `shapes` with the structures `Square`, `Circle`, and `Triangle`.\n"
+"mod shapes {\n"
+" #[derive(Drop)]\n"
+" struct Square {\n"
+" side: u32\n"
+" }\n"
+"\n"
+" #[derive(Drop)]\n"
+" struct Circle {\n"
+" radius: u32\n"
+" }\n"
+"\n"
+" #[derive(Drop)]\n"
+" struct Triangle {\n"
+" base: u32,\n"
+" height: u32,\n"
+" }\n"
+"}\n"
+"\n"
+"// We can import the structures `Square`, `Circle`, and `Triangle` from the `shapes` module like this:\n"
+"use shapes::{Square, Circle, Triangle};\n"
+"\n"
+"// Now we can directly use `Square`, `Circle`, and `Triangle` in our code.\n"
+"fn main() {\n"
+" let sq = Square { side: 5 };\n"
+" let cr = Circle { radius: 3 };\n"
+" let tr = Triangle { base: 5, height: 2 };\n"
+"// ...\n"
+"}\n"
+"```"
+
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:195
+msgid "Listing 6-10: Importing multiple items from the same module"
+msgstr "Listado 6-10 Importación de varios elementos del mismo módulo"
+
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:197
+msgid "## Re-exporting Names in Module Files"
+msgstr "## Re-exportación de Nombres en Archivos de Módulo"
+
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:199
+msgid ""
+"When we bring a name into scope with the `use` keyword, the name available in\n"
+"the new scope can be imported as if it had been defined in that code’s scope.\n"
+"This technique is called _re-exporting_ because we’re bringing an item into scope,\n"
+"but also making that item available for others to bring into their scope."
+msgstr ""
+"Cuando traemos un nombre al ámbito con la palabra clave `use`, el nombre disponible en\n"
+"el nuevo ámbito puede ser importado como si hubiera sido definido en el ámbito de ese código.\n"
+"Esta técnica se llama _re-exporting_ porque estamos trayendo un elemento al ámbito,\n"
+"pero también haciendo que ese elemento esté disponible para que otros lo introduzcan en su ámbito."
+
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:204
+msgid "For example, let's re-export the `add_to_waitlist` function in the restaurant example:"
+msgstr "Por ejemplo, reexportemos la función `add_to_waitlist` del ejemplo del restaurante:"
+
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:208
+msgid ""
+"```rust\n"
+"// does_not_compile\n"
+"mod front_of_house {\n"
+" mod hosting {\n"
+" fn add_to_waitlist() {}\n"
+" }\n"
+"}\n"
+"\n"
+"use restaurant::front_of_house::hosting;\n"
+"\n"
+"fn eat_at_restaurant() {\n"
+" hosting::add_to_waitlist();\n"
+"}\n"
+"```"
+msgstr ""
+"```rust\n"
+"// does_not_compile\n"
"mod front_of_house {\n"
" mod hosting {\n"
" fn add_to_waitlist() {}\n"
@@ -9146,15 +9549,15 @@ msgstr ""
"}\n"
"```"
-#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:172
+#: src/ch06-04-bringing-paths-into-scope-with-the-use-keyword.md:223
msgid ""
-"Listing 6-10: Making a name available for any code to use\n"
+"