diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml deleted file mode 100644 index c410027..0000000 --- a/.github/workflows/gh-pages.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: GitHub Pages - -on: - push: - branches: - - main - pull_request: - -jobs: - deploy: - runs-on: ubuntu-latest - steps: - - name: Clone repository - uses: actions/checkout@v3 - with: - fetch-depth: 0 - submodules: true - - - name: Setup Hugo - uses: peaceiris/actions-hugo@v2 - with: - hugo-version: 'latest' - extended: true - - - name: Build - run: hugo --minify - - - name: Deploy - uses: peaceiris/actions-gh-pages@v3 - if: ${{ github.ref == 'refs/heads/main' }} - with: - deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} - external_repository: learning-rust/learning-rust.github.io - publish_branch: main - publish_dir: ./public diff --git a/.gitignore b/.gitignore index a5e3ace..551225c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,11 @@ -/.idea -/.vscode -/public +.idea +.vscode +.zed .DS_Store -/resources/ -.hugo_build.lock \ No newline at end of file +hugo.yaml +.hugo_build.lock +.gitmodules +/docs +/data +/themes +/static \ No newline at end of file diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 57f8bf1..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "themes/docura"] - path = themes/docura - url = https://github.com/docura/docura.git diff --git a/LICENSE b/LICENSE index ca311f8..70f277a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2015-2022 Dumindu Madunuwan +Copyright (c) 2015-2024 Dumindu Madunuwan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 951f8ca..abb8126 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,9 @@ -# Learning Rust - -This website is built using [Hugo](https://gohugo.io/) and [Docura](https://docura.github.io/). +[![buymeacoffee](https://img.shields.io/badge/Buy%20me%20a%20coffee-dumindu-FFDD00?style=for-the-badge&logo=buymeacoffee&logoColor=ffffff&labelColor=333333)](https://www.buymeacoffee.com/dumindu) -## Local setup -- [Install the extended version of Hugo](https://gohugo.io/getting-started/installing/) -- Clone the repository and start Hugo server - ``` - $ git clone --depth 1 https://github.com/learning-rust/site.git - $ cd site - $ git submodule update --init --recursive - $ hugo server - ``` -## Content +# Learning Rust -### Basics +## Basics * [Why Rust](content/en/docs/a1.why-rust.md) * [Installation](content/en/docs/a2.installation.md) * [Hello World](content/en/docs/a3.hello-world.md) @@ -26,19 +15,19 @@ This website is built using [Hugo](https://gohugo.io/) and [Docura](https://docu * [Operators](content/en/docs/a9.operators.md) * [Control flows](content/en/docs/a10.control-flows.md) -### Beyond The Basics +## Beyond The Basics * [Vectors](content/en/docs/b1.vectors.md) * [Structs](content/en/docs/b2.structs.md) * [Enums](content/en/docs/b3.enums.md) * [Generics](content/en/docs/b4.generics.md) * [Impls and traits](content/en/docs/b5.impls-and-traits.md) -### The Tough Part +## The Tough Part * [Ownership](content/en/docs/c1.ownership.md) * [Borrowing](content/en/docs/c2.borrowing.md) * [Lifetimes](content/en/docs/c3.lifetimes.md) -### Lets Get It Started +## Lets Get It Started * [Code organization](content/en/docs/d1.code-organization.md) * [Functions](content/en/docs/d2.functions.md) * [Modules](content/en/docs/d3.modules.md) @@ -47,7 +36,7 @@ This website is built using [Hugo](https://gohugo.io/) and [Docura](https://docu * [use](content/en/docs/d6.use.md) * [std, primitives and preludes](content/en/docs/d7.std-primitives-and-preludes.md) -### Error Handling +## Error Handling * [Smart Compiler](content/en/docs/e1.smart-compiler.md) * [Panicking](content/en/docs/e2.panicking.md) * [Option and Result](content/en/docs/e3.option-and-result.md) @@ -55,9 +44,3 @@ This website is built using [Hugo](https://gohugo.io/) and [Docura](https://docu * [Error and None Propagation](content/en/docs/e5.error-and-none-propagation.md) * [Combinators](content/en/docs/e6.combinators.md) * [Custom Error Types](content/en/docs/e7.custom-error-types.md) - ---- -* Site : http://learning-rust.github.io -* Medium: https://medium.com/learning-rust - -> 🐣 I am a **Sri Lankan**πŸ‡±πŸ‡° Web Developer who lives in **Singapore**πŸ‡ΈπŸ‡¬. I am not a native English speaker and just practicing Rust in my leisure time, while working as a Golang/Devops developer. So, if you found any mistake or something I need to be changed, even a spelling/ grammar mistake, feel free to buzz me. diff --git a/assets/scss/icon/default.scss b/assets/scss/icon/default.scss deleted file mode 100644 index 82d9ec9..0000000 --- a/assets/scss/icon/default.scss +++ /dev/null @@ -1,89 +0,0 @@ -.icon { - display: block; - width: 18px; - height: 18px; -} - -/* -- social icons: add `.icon-colored` with `.icon` -- */ -.icon-github { - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 16 16' fill='%2324292f' %3E%3Cpath d='M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z'%3E%3C/path%3E%3C/svg%3E"); -} - -:root[data-color="dark"] .icon-github, :root[data-color="night"] .icon-github { - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 16 16' fill='%236e7681' %3E%3Cpath d='M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z'%3E%3C/path%3E%3C/svg%3E"); -} - - -/* -- template icons -- */ -.icon-menu { - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18px' height='18px' viewBox='0 0 24 24'%3E%3Cpath d='M0,0h24v24H0V0z' fill='none'/%3E%3Cpath d='M4,18h11c0.55,0,1-0.45,1-1v0c0-0.55-0.45-1-1-1H4c-0.55,0-1,0.45-1,1v0C3,17.55,3.45,18,4,18z M4,13h8c0.55,0,1-0.45,1-1v0 c0-0.55-0.45-1-1-1H4c-0.55,0-1,0.45-1,1v0C3,12.55,3.45,13,4,13z M3,7L3,7c0,0.55,0.45,1,1,1h11c0.55,0,1-0.45,1-1v0 c0-0.55-0.45-1-1-1H4C3.45,6,3,6.45,3,7z M20.3,14.88L17.42,12l2.88-2.88c0.39-0.39,0.39-1.02,0-1.41l0,0 c-0.39-0.39-1.02-0.39-1.41,0l-3.59,3.59c-0.39,0.39-0.39,1.02,0,1.41l3.59,3.59c0.39,0.39,1.02,0.39,1.41,0l0,0 C20.68,15.91,20.69,15.27,20.3,14.88z'/%3E%3Cpath d='M0,0h24v24H0V0z' fill='none'/%3E%3C/svg%3E"); -} - -.icon-toc { - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18px' height='18px' viewBox='0 0 24 24' fill='%23000000'%3E%3Cpath d='M0 0h24v24H0V0zm0 0h24v24H0V0z' fill='none'/%3E%3Cpath d='M3 9h14V7H3v2zm0 4h14v-2H3v2zm0 4h14v-2H3v2zm16 0h2v-2h-2v2zm0-10v2h2V7h-2zm0 6h2v-2h-2v2z'/%3E%3C/svg%3E"); -} - -.icon-close { - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18px' height='18px' viewBox='0 0 24 24'%3E%3Cpath d='M0 0h24v24H0V0z' fill='none'/%3E%3Cpath d='M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z'/%3E%3C/svg%3E"); -} - -.icon-home { - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18px' height='18px' viewBox='0 0 24 24'%3E%3Crect fill='none' height='24' width='24'/%3E%3Cpolygon opacity='.3' points='18,19 13,19 13,15 11,15 11,19 6,19 6,10.1 12,5.52 18,10.1'/%3E%3Cpath d='M12,3L6,7.58V6H4v3.11L1,11.4l1.21,1.59L4,11.62V21h16v-9.38l1.79,1.36L23,11.4L12,3z M18,19h-5v-4h-2v4H6v-8.9l6-4.58 l6,4.58V19z M10,1c0,1.66-1.34,3-3,3C6.45,4,6,4.45,6,5H4c0-1.66,1.34-3,3-3c0.55,0,1-0.45,1-1H10z'/%3E%3C/svg%3E"); -} - -.icon-book { - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18px' height='18px' viewBox='0 0 24 24'%3E%3Cg%3E%3Crect fill='none' height='24' width='24'/%3E%3C/g%3E%3Cg%3E%3Cg/%3E%3Cg%3E%3Cpath d='M21,5c-1.11-0.35-2.33-0.5-3.5-0.5c-1.95,0-4.05,0.4-5.5,1.5c-1.45-1.1-3.55-1.5-5.5-1.5S2.45,4.9,1,6v14.65 c0,0.25,0.25,0.5,0.5,0.5c0.1,0,0.15-0.05,0.25-0.05C3.1,20.45,5.05,20,6.5,20c1.95,0,4.05,0.4,5.5,1.5c1.35-0.85,3.8-1.5,5.5-1.5 c1.65,0,3.35,0.3,4.75,1.05c0.1,0.05,0.15,0.05,0.25,0.05c0.25,0,0.5-0.25,0.5-0.5V6C22.4,5.55,21.75,5.25,21,5z M3,18.5V7 c1.1-0.35,2.3-0.5,3.5-0.5c1.34,0,3.13,0.41,4.5,0.99v11.5C9.63,18.41,7.84,18,6.5,18C5.3,18,4.1,18.15,3,18.5z M21,18.5 c-1.1-0.35-2.3-0.5-3.5-0.5c-1.34,0-3.13,0.41-4.5,0.99V7.49c1.37-0.59,3.16-0.99,4.5-0.99c1.2,0,2.4,0.15,3.5,0.5V18.5z'/%3E%3Cpath d='M11,7.49C9.63,6.91,7.84,6.5,6.5,6.5C5.3,6.5,4.1,6.65,3,7v11.5C4.1,18.15,5.3,18,6.5,18 c1.34,0,3.13,0.41,4.5,0.99V7.49z' opacity='.3'/%3E%3C/g%3E%3Cg%3E%3Cpath d='M17.5,10.5c0.88,0,1.73,0.09,2.5,0.26V9.24C19.21,9.09,18.36,9,17.5,9c-1.28,0-2.46,0.16-3.5,0.47v1.57 C14.99,10.69,16.18,10.5,17.5,10.5z'/%3E%3Cpath d='M17.5,13.16c0.88,0,1.73,0.09,2.5,0.26V11.9c-0.79-0.15-1.64-0.24-2.5-0.24c-1.28,0-2.46,0.16-3.5,0.47v1.57 C14.99,13.36,16.18,13.16,17.5,13.16z'/%3E%3Cpath d='M17.5,15.83c0.88,0,1.73,0.09,2.5,0.26v-1.52c-0.79-0.15-1.64-0.24-2.5-0.24c-1.28,0-2.46,0.16-3.5,0.47v1.57 C14.99,16.02,16.18,15.83,17.5,15.83z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E"); -} - -.icon-theme { - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18px' height='18px' viewBox='0 0 24 24' %3E%3Cpath d='M0 0h24v24H0z' fill='none'/%3E%3Cpath d='M12 3c-4.97 0-9 4.03-9 9s4.03 9 9 9c.83 0 1.5-.67 1.5-1.5 0-.39-.15-.74-.39-1.01-.23-.26-.38-.61-.38-.99 0-.83.67-1.5 1.5-1.5H16c2.76 0 5-2.24 5-5 0-4.42-4.03-8-9-8zm-5.5 9c-.83 0-1.5-.67-1.5-1.5S5.67 9 6.5 9 8 9.67 8 10.5 7.33 12 6.5 12zm3-4C8.67 8 8 7.33 8 6.5S8.67 5 9.5 5s1.5.67 1.5 1.5S10.33 8 9.5 8zm5 0c-.83 0-1.5-.67-1.5-1.5S13.67 5 14.5 5s1.5.67 1.5 1.5S15.33 8 14.5 8zm3 4c-.83 0-1.5-.67-1.5-1.5S16.67 9 17.5 9s1.5.67 1.5 1.5-.67 1.5-1.5 1.5z'/%3E%3C/svg%3E"); -} - -.icon-brightness { - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18px' height='18px' viewBox='0 0 24 24' %3E%3Cpath d='M0 0h24v24H0V0z' fill='none'/%3E%3Cpath d='M18 9.52V6h-3.52L12 3.52 9.52 6H6v3.52L3.52 12 6 14.48V18h3.52L12 20.48 14.48 18H18v-3.52L20.48 12 18 9.52zm-6 7.98v-11c3.03 0 5.5 2.47 5.5 5.5s-2.47 5.5-5.5 5.5z' opacity='.3'/%3E%3Cpath d='M20 8.69V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12 20 8.69zm-2 5.79V18h-3.52L12 20.48 9.52 18H6v-3.52L3.52 12 6 9.52V6h3.52L12 3.52 14.48 6H18v3.52L20.48 12 18 14.48zM12 6.5v11c3.03 0 5.5-2.47 5.5-5.5S15.03 6.5 12 6.5z'/%3E%3C/svg%3E"); -} - -.icon-light-mode { - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18px' height='18px' viewBox='0 0 24 24' %3E%3Crect fill='none' height='24' width='24'/%3E%3Ccircle cx='12' cy='12' opacity='.3' r='3'/%3E%3Cpath d='M12,9c1.65,0,3,1.35,3,3s-1.35,3-3,3s-3-1.35-3-3S10.35,9,12,9 M12,7c-2.76,0-5,2.24-5,5s2.24,5,5,5s5-2.24,5-5 S14.76,7,12,7L12,7z M2,13l2,0c0.55,0,1-0.45,1-1s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S1.45,13,2,13z M20,13l2,0c0.55,0,1-0.45,1-1 s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S19.45,13,20,13z M11,2v2c0,0.55,0.45,1,1,1s1-0.45,1-1V2c0-0.55-0.45-1-1-1S11,1.45,11,2z M11,20v2c0,0.55,0.45,1,1,1s1-0.45,1-1v-2c0-0.55-0.45-1-1-1C11.45,19,11,19.45,11,20z M5.99,4.58c-0.39-0.39-1.03-0.39-1.41,0 c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0s0.39-1.03,0-1.41L5.99,4.58z M18.36,16.95 c-0.39-0.39-1.03-0.39-1.41,0c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0c0.39-0.39,0.39-1.03,0-1.41 L18.36,16.95z M19.42,5.99c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06c-0.39,0.39-0.39,1.03,0,1.41 s1.03,0.39,1.41,0L19.42,5.99z M7.05,18.36c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06 c-0.39,0.39-0.39,1.03,0,1.41s1.03,0.39,1.41,0L7.05,18.36z'/%3E%3C/svg%3E"); -} - -.icon-dark-mode { - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18px' height='18px' viewBox='0 0 24 24' %3E%3Crect fill='none' height='24' width='24'/%3E%3Cpath d='M9.37,5.51C9.19,6.15,9.1,6.82,9.1,7.5c0,4.08,3.32,7.4,7.4,7.4c0.68,0,1.35-0.09,1.99-0.27 C17.45,17.19,14.93,19,12,19c-3.86,0-7-3.14-7-7C5,9.07,6.81,6.55,9.37,5.51z' opacity='.3'/%3E%3Cpath d='M9.37,5.51C9.19,6.15,9.1,6.82,9.1,7.5c0,4.08,3.32,7.4,7.4,7.4c0.68,0,1.35-0.09,1.99-0.27C17.45,17.19,14.93,19,12,19 c-3.86,0-7-3.14-7-7C5,9.07,6.81,6.55,9.37,5.51z M12,3c-4.97,0-9,4.03-9,9s4.03,9,9,9s9-4.03,9-9c0-0.46-0.04-0.92-0.1-1.36 c-0.98,1.37-2.58,2.26-4.4,2.26c-2.98,0-5.4-2.42-5.4-5.4c0-1.81,0.89-3.42,2.26-4.4C12.92,3.04,12.46,3,12,3L12,3z'/%3E%3C/svg%3E"); -} - -.icon-night-mode { - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18px' height='18px' viewBox='0 0 24 24' %3E%3Cg%3E%3Crect fill='none' height='24' width='24'/%3E%3C/g%3E%3Cg%3E%3Cg%3E%3Cpath d='M8.1,14.15C9.77,14.63,11,16.17,11,18c0,0.68-0.19,1.31-0.48,1.87c0.48,0.09,0.97,0.14,1.48,0.14 c1.48,0,2.9-0.41,4.13-1.15c-2.62-0.92-5.23-2.82-6.8-5.86C7.74,9.94,7.78,7.09,8.29,4.9c-2.57,1.33-4.3,4.01-4.3,7.1c0,0,0,0,0,0 c0.01,0,0.01,0,0.02,0C5.66,12,7.18,12.83,8.1,14.15z' opacity='.3'/%3E%3Cpath d='M19.78,17.51c-2.47,0-6.57-1.33-8.68-5.43C8.77,7.57,10.6,3.6,11.63,2.01C6.27,2.2,1.98,6.59,1.98,12 c0,0.14,0.02,0.28,0.02,0.42C2.61,12.16,3.28,12,3.98,12c0,0,0,0,0,0c0-3.09,1.73-5.77,4.3-7.1C7.78,7.09,7.74,9.94,9.32,13 c1.57,3.04,4.18,4.95,6.8,5.86c-1.23,0.74-2.65,1.15-4.13,1.15c-0.5,0-1-0.05-1.48-0.14c-0.37,0.7-0.94,1.27-1.64,1.64 c0.98,0.32,2.03,0.5,3.11,0.5c3.5,0,6.58-1.8,8.37-4.52C20.18,17.5,19.98,17.51,19.78,17.51z'/%3E%3Cpath d='M7,16l-0.18,0C6.4,14.84,5.3,14,4,14c-1.66,0-3,1.34-3,3s1.34,3,3,3c0.62,0,2.49,0,3,0c1.1,0,2-0.9,2-2 C9,16.9,8.1,16,7,16z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E"); -} - -.icon-translate { - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18px' height='18px' viewBox='0 0 24 24' %3E%3Cpath d='M0 0h24v24H0V0z' fill='none'/%3E%3Cpath d='M12.65 15.67c.14-.36.05-.77-.23-1.05l-2.09-2.06.03-.03c1.74-1.94 2.98-4.17 3.71-6.53h1.94c.54 0 .99-.45.99-.99v-.02c0-.54-.45-.99-.99-.99H10V3c0-.55-.45-1-1-1s-1 .45-1 1v1H1.99c-.54 0-.99.45-.99.99 0 .55.45.99.99.99h10.18C11.5 7.92 10.44 9.75 9 11.35c-.81-.89-1.49-1.86-2.06-2.88-.16-.29-.45-.47-.78-.47-.69 0-1.13.75-.79 1.35.63 1.13 1.4 2.21 2.3 3.21L3.3 16.87c-.4.39-.4 1.03 0 1.42.39.39 1.02.39 1.42 0L9 14l2.02 2.02c.51.51 1.38.32 1.63-.35zM17.5 10c-.6 0-1.14.37-1.35.94l-3.67 9.8c-.24.61.22 1.26.87 1.26.39 0 .74-.24.88-.61l.89-2.39h4.75l.9 2.39c.14.36.49.61.88.61.65 0 1.11-.65.88-1.26l-3.67-9.8c-.22-.57-.76-.94-1.36-.94zm-1.62 7l1.62-4.33L19.12 17h-3.24z'/%3E%3C/svg%3E"); -} - -.icon-search { - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18px' height='18px' viewBox='0 0 24 24' %3E%3Cpath d='M0 0h24v24H0V0z' fill='none'/%3E%3Cpath d='M15.5 14h-.79l-.28-.27c1.2-1.4 1.82-3.31 1.48-5.34-.47-2.78-2.79-5-5.59-5.34-4.23-.52-7.79 3.04-7.27 7.27.34 2.8 2.56 5.12 5.34 5.59 2.03.34 3.94-.28 5.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z'/%3E%3C/svg%3E"); -} - -.icon-select { - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18px' height='18px' viewBox='0 0 24 24'%3E%3Cpath d='M0 0h24v24H0V0z' fill='none'/%3E%3Cpath d='M12 5.83L15.17 9l1.41-1.41L12 3 7.41 7.59 8.83 9 12 5.83zm0 12.34L8.83 15l-1.41 1.41L12 21l4.59-4.59L15.17 15 12 18.17z'/%3E%3C/svg%3E"); -} - -.icon-calendar { - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18px' height='18px' viewBox='0 0 24 24'%3E%3Cg%3E%3Crect fill='none' height='24' width='24'/%3E%3C/g%3E%3Cg%3E%3Crect height='2' opacity='.3' width='14' x='5' y='6'/%3E%3Cpath d='M19,4h-1V2h-2v2H8V2H6v2H5C3.89,4,3.01,4.9,3.01,6L3,20c0,1.1,0.89,2,2,2h14c1.1,0,2-0.9,2-2V6C21,4.9,20.1,4,19,4z M19,20 H5V10h14V20z M19,8H5V6h14V8z M9,14H7v-2h2V14z M13,14h-2v-2h2V14z M17,14h-2v-2h2V14z M9,18H7v-2h2V18z M13,18h-2v-2h2V18z M17,18 h-2v-2h2V18z'/%3E%3C/g%3E%3C/svg%3E"); -} - -.icon-next { - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18px' height='18px' viewBox='0 0 24 24' %3E%3Cpath d='M24 24H0V0h24v24z' fill='none' opacity='.87'/%3E%3Cpath d='M7.38 21.01c.49.49 1.28.49 1.77 0l8.31-8.31c.39-.39.39-1.02 0-1.41L9.15 2.98c-.49-.49-1.28-.49-1.77 0s-.49 1.28 0 1.77L14.62 12l-7.25 7.25c-.48.48-.48 1.28.01 1.76z' fill='%23328ac1'/%3E%3C/svg%3E"); -} - -.icon-prev { - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18px' height='18px' viewBox='0 0 24 24' %3E%3Crect fill='none' height='24' width='24'/%3E%3Cg%3E%3Cpath d='M16.88,2.88L16.88,2.88c-0.49-0.49-1.28-0.49-1.77,0l-8.41,8.41c-0.39,0.39-0.39,1.02,0,1.41l8.41,8.41 c0.49,0.49,1.28,0.49,1.77,0l0,0c0.49-0.49,0.49-1.28,0-1.77L9.54,12l7.35-7.35C17.37,4.16,17.37,3.37,16.88,2.88z' fill='%23328ac1'/%3E%3C/g%3E%3C/svg%3E"); -} - -.icon-copyright { - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18px' height='18px' viewBox='0 0 24 24' %3E%3Cpath d='M0 0h24v24H0V0z' fill='none'/%3E%3Cpath d='M10.08 10.86c.05-.33.16-.62.3-.87s.34-.46.59-.62c.24-.15.54-.22.91-.23.23.01.44.05.63.13.2.09.38.21.52.36s.25.33.34.53.13.42.14.64h1.79c-.02-.47-.11-.9-.28-1.29s-.4-.73-.7-1.01-.66-.5-1.08-.66-.88-.23-1.39-.23c-.65 0-1.22.11-1.7.34s-.88.53-1.2.92-.56.84-.71 1.36S8 11.29 8 11.87v.27c0 .58.08 1.12.23 1.64s.39.97.71 1.35.72.69 1.2.91c.48.22 1.05.34 1.7.34.47 0 .91-.08 1.32-.23s.77-.36 1.08-.63.56-.58.74-.94.29-.74.3-1.15h-1.79c-.01.21-.06.4-.15.58s-.21.33-.36.46-.32.23-.52.3c-.19.07-.39.09-.6.1-.36-.01-.66-.08-.89-.23-.25-.16-.45-.37-.59-.62s-.25-.55-.3-.88-.08-.67-.08-1v-.27c0-.35.03-.68.08-1.01zM12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z'/%3E%3C/svg%3E"); -} - -/* -- add `.icon-colored` -- */ -.icon-love { - background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18px' height='18px' viewBox='0 0 24 24' fill='%23ff4d4d' %3E%3Cpath d='M0 0h24v24H0V0z' fill='none'/%3E%3Cpath d='M13.35 20.13c-.76.69-1.93.69-2.69-.01l-.11-.1C5.3 15.27 1.87 12.16 2 8.28c.06-1.7.93-3.33 2.34-4.29 2.64-1.8 5.9-.96 7.66 1.1 1.76-2.06 5.02-2.91 7.66-1.1 1.41.96 2.28 2.59 2.34 4.29.14 3.88-3.3 6.99-8.55 11.76l-.1.09z'/%3E%3C/svg%3E"); -} diff --git a/config/_default/config.toml b/config/_default/config.toml deleted file mode 100644 index 38be1fa..0000000 --- a/config/_default/config.toml +++ /dev/null @@ -1,15 +0,0 @@ -title = 'Learning Rust' -baseURL = 'https://learning-rust.github.io/' - -defaultContentLanguage = 'en' -languageCode = 'en-us' - -enableGitInfo = true - -theme = 'docura' - -markup.highlight.noClasses = false - -[services] -[services.googleAnalytics] -ID = 'G-FZHQCXSZ89' \ No newline at end of file diff --git a/config/_default/languages.toml b/config/_default/languages.toml deleted file mode 100644 index 7f7ab21..0000000 --- a/config/_default/languages.toml +++ /dev/null @@ -1,4 +0,0 @@ -[en] -contentDir = 'content/en' -languageName = 'English' -weight = 1 \ No newline at end of file diff --git a/config/_default/menu.toml b/config/_default/menu.toml deleted file mode 100644 index 9b6a609..0000000 --- a/config/_default/menu.toml +++ /dev/null @@ -1,13 +0,0 @@ -[[main]] -identifier = 'home' -name = 'Home' -pre = "" -url = '/' -weight = 1 - -[[main]] -identifier = 'docs' -name = 'Documentation' -pre = "" -url = '/docs/' -weight = 2 diff --git a/config/_default/params.toml b/config/_default/params.toml deleted file mode 100644 index ac5939e..0000000 --- a/config/_default/params.toml +++ /dev/null @@ -1,25 +0,0 @@ -description = 'Rust Programming Language Tutorials' - -currentYear = 2023 -projectStartYear = 2016 - -facebookURL = '' -twitterURL = '' -githubURL = 'https://github.com/learning-rust' -youtubeURL = '' - -githubRepo = 'learning-rust/site' - -buyMeACoffee = 'dumindu' -githubSponsor = 'dumindu' - -[author] -name= 'Dumindu Madunuwan' -URL = 'https://github.com/dumindu' - -[algolia] -[algolia.en] -container = '#site-header-search' -appId = 'QEN78N5RTO' -indexName = 'learning_rust' -apiKey = '07315fdb3221618273bdaffb1ab6f388' diff --git a/content/en/docs/_overview.md b/content/en/docs/_overview.md index daba032..cd5d744 100644 --- a/content/en/docs/_overview.md +++ b/content/en/docs/_overview.md @@ -5,8 +5,18 @@ aliases: - "/docs" --- -This is based on the posts I wrote on **Medium**, https://medium.com/learning-rust +## About me -[![Rust Playground](/docs/learning_rust_medium.png)](https://medium.com/learning-rust) +> πŸ§‘β€πŸ’» I am an expat working in Singapore as a Go Backend and DevOps Engineer. Feel free to reach out if you find any mistakes or anything that needs to be changed, including spelling or grammar errors. Alternatively, you can create a pull request, open an issue, or [share your awesome ideas in this gist](https://gist.github.com/dumindu/00a0be2d175ed5ff3bc3c17bbf1ca5b6). Good luck with learning Rust! -> 🐣 I am a **Sri Lankan** πŸ‡±πŸ‡° Web Developer who lives in **Singapore** πŸ‡ΈπŸ‡¬. So I am not a native English speaker and just learning Rust, If you found any mistake or something need to be changed, even a spelling or a grammar mistake, feel free to create a pull request. Thanks. \ No newline at end of file +[![learning-rust.github.io](https://img.shields.io/github/stars/learning-rust/learning-rust.github.io?style=for-the-badge&logo=rust&label=learning-rust.github.io&logoColor=333333&labelColor=f9f9f9&color=F46623)](https://github.com/learning-rust/learning-rust.github.io) +[![learning-cloud-native-go.github.io](https://img.shields.io/github/stars/learning-cloud-native-go/learning-cloud-native-go.github.io?style=for-the-badge&logo=go&logoColor=333333&label=learning-cloud-native-go.github.io&labelColor=f9f9f9&color=00ADD8)](https://learning-cloud-native-go.github.io) + +[![github.com](https://img.shields.io/badge/dumindu-866ee7?style=for-the-badge&logo=GitHub&logoColor=333333&labelColor=f9f9f9)](https://github.com/dumindu) +[![buymeacoffee](https://img.shields.io/badge/Buy%20me%20a%20coffee-dumindu-FFDD00?style=for-the-badge&logo=buymeacoffee&logoColor=333333&labelColor=f9f9f9)](https://www.buymeacoffee.com/dumindu) + +## Overview + +This publication has its origins in the posts I authored on Medium at https://medium.com/learning-rust. However, please note that I have ceased updating the Medium posts. All current and future updates, new content, code, and grammar fixes will be exclusively maintained and released here, https://learning-rust.github.io. + +[![Learning Rust @Medium](/docs/learning_rust_medium.png)](https://medium.com/learning-rust) diff --git a/content/en/docs/a1.why-rust.md b/content/en/docs/a1.why-rust.md index 68ad75d..9d3f95c 100755 --- a/content/en/docs/a1.why-rust.md +++ b/content/en/docs/a1.why-rust.md @@ -4,45 +4,51 @@ slug: why-rust --- ## History of Rust -Rust was initially designed and developed by former Mozilla employee **[Graydon Hoare](https://github.com/graydon)** as a personal project. Mozilla began sponsoring the project in 2009 and announced it in 2010. But the first stable release, Rust 1.0 was released on May 15, 2015. + +Rust was initially designed and developed by former Mozilla employee **[Graydon Hoare](https://github.com/graydon)** as a personal project. Mozilla began sponsoring the project in 2009 and announced it in 2010. But the first stable release, Rust 1.0, was released on May 15, 2015. + +Since Rust 1.0, major updates have been released as [`Editions`](/docs/cargo-crates-and-basic-project-structure/#rust-editions) approximately every three years: Rust 2015 (with the release of Rust 1.0) , Rust 2018, Rust 2021, and Rust 2024, all maintaining backward compatibility. ## Initial Goals + The goal of Rust is to be a good programming language for creating highly concurrent, safe and performant systems. -> **"Rust is a systems programming language focused on three goals: safety, speed, and concurrency."** -> \_\_ Rust Documentation +> **"Rust is a systems programming language focused on three goals: safety, speed, and concurrency." +>
~ Rust Documentation** -Rust is very young and very modern language. It is a **[compiled programming language](https://en.wikipedia.org/wiki/Compiled_language)** and it uses [LLVM](https://en.wikipedia.org/wiki/LLVM) on the backend. Also, Rust is a **[multi-paradigm programming language](https://en.wikipedia.org/wiki/Comparison_of_multi-paradigm_programming_languages)**, which supports imperative procedural, concurrent actor, object-oriented and pure functional styles. It also supports generic programming and metaprogramming, in both static and dynamic styles. +Rust is a very young and very modern language. It's a **[compiled programming language](https://en.wikipedia.org/wiki/Compiled_language)** and it uses [LLVM](https://en.wikipedia.org/wiki/LLVM) on the backend. Also, Rust is a **[multi-paradigm programming language](https://en.wikipedia.org/wiki/Comparison_of_multi-paradigm_programming_languages)**, which supports imperative procedural, concurrent actor, object-oriented and pure functional styles. It also supports generic programming and metaprogramming, in both static and dynamic styles. -> πŸ”Ž One of Rust’s most unique and compelling features is [Ownership](c1.ownership.html), which is used to achieve memory safety. Rust creates memory pointers optimistically, checks memory pointers’ limited accesses at compile-time with the usage of [References and Borrowing](c2.borrowing.html). And it does automatic compile-time memory management by checking the [Lifetimes](c3.lifetimes.html). +> One of Rust’s most unique and compelling features is [Ownership](/docs/ownership), which is used to achieve memory safety. Rust creates memory pointers optimistically, checks memory pointers’ limited accesses at compile-time with the usage of [References and Borrowing](/docs/borrowing). And it does automatic compile-time memory management by checking the [Lifetimes](/docs/lifetimes). ## Influences + Its design elements came from a wide range of sources. -- Abstract Machine Model: **C** -- Data types: **C, SML, OCaml, Lisp, Limbo** -- Optional Bindings: **Swift** -- Hygienic Macros: **Scheme** -- Functional Programming: **Haskell, OCaml, F\#** -- Attributes: **ECMA**-335 -- Memory Model and Memory Management: **C++, ML Kit, Cyclone** -- Type Classes: **Haskell** -- Crate: Assembly in the **ECMA**-335 CLI model -- Channels and Concurrency: **Newsqueak, Alef, Limbo** -- Message passing and Thread failure: **Erlang** +- Abstract Machine Model: C +- Data types: C, SML, OCaml, Lisp, Limbo +- Optional Bindings: Swift +- Hygienic Macros: Scheme +- Functional Programming: Haskell, OCaml, F\# +- Attributes: ECMA-335 +- Memory Model and Memory Management: C++, ML Kit, Cyclone +- Type Classes: Haskell +- Crate: Assembly in the ECMA-335 CLI model +- Channels and Concurrency: Newsqueak, Alef, Limbo +- Message passing and Thread failure: Erlang and etc. +Rust **doesn't use a built-in runtime** or an automated garbage collection system \(GC\). -Rust **doesn't use an automated garbage collection** system\(GC\) by default. +> πŸ’‘ However, async Rust requires an async runtime, which is provided by community-maintained crates like [`tokio`](https://github.com/tokio-rs/tokio), [`async-std`](https://github.com/async-rs/async-std), [`soml`](https://github.com/smol-rs/smol) etc. The async runtime will be bundled into the final executable. -Rust compiler observes the code **at compile-time** and helps to [**prevent many types of errors**](https://doc.rust-lang.org/error-index.html) that are possible to write in C, C++ like programming languages. +Rust compiler **observes the code at compile-time** and helps to [prevent many types of errors](https://doc.rust-lang.org/error-index.html) that are possible to write in C, C++ like programming languages. ## πŸ‘¨β€πŸ« Before going to the next... - The following guides will be helpful for you to understand the maturity of the Rust ecosystem and the tools you need to choose, according to the area you want to master. + - [Are we async yet?](https://areweasyncyet.rs/) - [Are we web yet?](http://www.arewewebyet.org/) - [Are we game yet?](http://arewegameyet.com/) - - [Are we learning yet?](http://www.arewelearningyet.com/) - [Are we GUI yet?](https://areweguiyet.com/) - - [Are we audio yet?](https://areweaudioyet.com/) + - [Are we learning yet?](http://www.arewelearningyet.com/) diff --git a/content/en/docs/a10.control-flows.md b/content/en/docs/a10.control-flows.md index d54e5c9..dcfb98e 100755 --- a/content/en/docs/a10.control-flows.md +++ b/content/en/docs/a10.control-flows.md @@ -271,11 +271,15 @@ for b in 0..6 { // Working with arrays/vectors let group : [&str; 4] = ["Mark", "Larry", "Bill", "Steve"]; -for n in 0..group.len() { // group.len() = 4 -> 0..4 πŸ‘Ž check group.len()on each iteration +for n in 0..group.len() { // group.len() = 4 -> 0..4 πŸ‘Ž check group.len() on each iteration println!("Current Person : {}", group[n]); } for person in group.iter() { // πŸ‘ group.iter() turn the array into a simple iterator println!("Current Person : {}", person); } + +for (index, person) in group.iter().enumerate() { // πŸ’‘ group.iter().enumerate() helps to read both the current index (starting from zero) and the value + println!("Person {} : {}", index, person); +} ``` diff --git a/content/en/docs/a2.installation.md b/content/en/docs/a2.installation.md index c89034b..b0eaefe 100755 --- a/content/en/docs/a2.installation.md +++ b/content/en/docs/a2.installation.md @@ -6,7 +6,7 @@ slug: installation ## Rustup There are many ways to install Rust on your system. For the moment the official way to install Rust is using [Rustup](https://rustup.rs/). -[πŸ“–](https://rust-lang.github.io/rustup/index.html) Rustup installs The Rust Programming Language from the official release channels, enabling you to easily switch between **stable, beta, and nightly** compilers and keep them updated. It makes **cross-compiling** simpler with binary builds of the standard library for common platforms. +[πŸ“–](https://rust-lang.github.io/rustup/index.html) Rustup installs The Rust Programming Language from the official release channels, enabling you to easily switch between **stable, beta, and nightly** compilers and keep them updated. It also makes cross-compiling simpler with binary builds of the standard library for common platforms. [πŸ“–](https://rust-lang.github.io/rustup/installation/index.html) Rustup installs **`rustc`, `cargo`, `rustup`** and other standard tools to Cargo's `bin` directory. On Unix it is located at `$HOME/.cargo/bin` and on Windows at `%USERPROFILE%\.cargo\bin`. This is the same directory that `cargo install` will install Rust programs and Cargo plugins. @@ -18,8 +18,9 @@ There are many ways to install Rust on your system. For the moment the official > - `cargo-fmt`: Helps to run `rustfmt` on whole Rust projects, including multi-crate workspaces. > - `cargo-clippy`: A lint tool that provides extra checks for common mistakes and stylistic choices. > - `cargo-miri`:An experimental Rust interpreter, which can be used for checking for undefined-behavior. -> - `rls`: A language server that provides support for editors and IDEs. > - `rustdoc`: A local copy of the Rust documentation. +> - `rust-analyzer`: A language server that provides support for editors and IDEs. +> - `rust-gdb`: A debugger that wraps GNU Debugger(GDB). ## Installation @@ -31,10 +32,11 @@ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh ### For Windows Users Download **`rustup-init.exe`** from [www.rustup.rs](https://rustup.rs/) and run. -> ⭐ If you are on **Microsoft Windows**, you have to install **[Visual C++ Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/)** 2015 or higher, which requires an additional 3–4 GBs. +> πŸ’‘ You may need to install [Visual C++ Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/) 2015 or higher, which requires an additional 3–4 GBs. ## πŸ‘¨β€πŸ« Before going to the next... -- To verify the current Rust version, use the **`rustc --version`** or **`rustc -V`** command. -- Rust ships releases on **six week cycles**. When a new Rust version released, use the **`rustup update`** command to update the Rust ecosystem. -- To open the offline Rust documentation, use the **`rustup doc`** command. For more `rustup` commands, check the **`rustup --help`** command. +- To verify the current Rust version, use the **`rustc --version`** or shorter form`rustc -V` command. +- Rust follows **six week** release cycles. Use the **`rustup update`** command to update the Rust ecosystem. +- You can access Rust's offline documentation via the `rustup doc` command. +- For a full list of `rustup` commands, refer to the `rustup --help` command. diff --git a/content/en/docs/a3.hello-world.md b/content/en/docs/a3.hello-world.md index 57fba80..bab6b7d 100755 --- a/content/en/docs/a3.hello-world.md +++ b/content/en/docs/a3.hello-world.md @@ -61,4 +61,4 @@ fn main() { ``` - Check the [difference between macros and functions](https://doc.rust-lang.org/book/ch19-06-macros.html#the-difference-between-macros-and-functions). -- For more `rustc` commands, check the **`rustc --help`** command. +- For more `rustc` commands, check the `rustc --help` command. diff --git a/content/en/docs/a4.cargo-crates-and-basic-project-structure.md b/content/en/docs/a4.cargo-crates-and-basic-project-structure.md index bdb9aa0..c783f1c 100755 --- a/content/en/docs/a4.cargo-crates-and-basic-project-structure.md +++ b/content/en/docs/a4.cargo-crates-and-basic-project-structure.md @@ -5,34 +5,61 @@ slug: cargo-crates-and-basic-project-structure ## Cargo -Cargo is Rust’s built-in package manager and the build system. It can be used to, +Cargo is Rust’s built-in package manager and build system. It also supports the following actions, -- Create a new project: `cargo new` -- Create a new project in an existing directory: `cargo init` -- Build the project: `cargo build` -- Run the project: `cargo run` -- Update project dependencies: `cargo update` -- Run tests: `cargo test` -- Run benchmarks: `cargo bench` -- Generate the project documentation via [rustdoc](https://doc.rust-lang.org/stable/rustdoc/): `cargo doc` -- Analyze the project to see it has any errors, without building it: `cargo check` +| Command | Action | +| ------------- | --------------------------------------------- | +| `cargo new` | Create a new project | +| `cargo init` | Create a new project in an existing directory | +| `cargo check` | Verify the project compiles without errors | +| `cargo build` | Build the executable | +| `cargo run` | Build the executable and run | -In addition, there are `cargo` commands to publish the project as a crate/ package to **Rust's official crate registry, [crates.io](https://crates.io/)**. +> πŸ’‘ The `cargo check` command verifies that the project compiles without errors, without producing an executable. +> Thus, it is often faster than `cargo build`. -> πŸ’‘ We need to get an API token from [crates.io](https://crates.io/) to publish a crate to it. The API token can be found in the [Account Settings page](https://crates.io/me), after login to that site. We will discuss more about this under [code organization with crates](/docs/d4.crates.html#c-Using-crates-io). +> πŸ’‘ Cargo places executables compiled with `cargo build` or `cargo run` in the `target/debug/` directory. +> But, while those built with **`cargo build --release`** for release purposes are stored in `target/release/` directory. +> Release builds use more optimizations and remove some runtime safety checks to increase performance, although this comes at the cost of longer compile time. -- Login to [crates.io](https://crates.io/) with the API token: `cargo login` -- Make the local crate uploadable to [crates.io](https://crates.io/): `cargo package` -- Upload the crate to [crates.io](https://crates.io/): `cargo publish` -- Install a Rust binary: `cargo install` -- Uninstall a Rust binary: `cargo uninstall` +| Command | Action | +|----------------|---------------------------------------------------| +| `cargo add` | Add a dependency crate to the project | +| `cargo remove` | Remove a dependency crate from the project | +| `cargo fetch` | Download the dependencies specified in Cargo.lock | +| `cargo update` | Update project dependencies | + + +> πŸ’‘ A crate is a package that can be shared via [crates.io](https://crates.io), Rust community’s crate registry. +> `cargo add`, `cargo remove`, `cargo fetch`, and `cargo update` commands manage project dependencies through the crate hosted on crates.io. + +> πŸ’‘ The `cargo add` command includes a specified crate in the `[dependencies]` section of `Cargo.toml`, while `cargo add --dev` adds a crate to the `[dev-dependencies]` section. This indicates that the crate is only used for development purposes like testing and will not be included in the final compiled code. + +| Command | Action | +|---------------|---------------------------------------------------------------------------------------------| +| `cargo test` | Run tests | +| `cargo bench` | Run benchmarks | +| `cargo doc` | Generate the project documentation via [rustdoc](https://doc.rust-lang.org/stable/rustdoc/) | + +In addition, there are `cargo` commands to publish the project as a crate to [crates.io](https://crates.io/). + +| Command | Action | +| ----------------- |--------------------------------------------------------------------| +| `cargo login` | Login to [crates.io](https://crates.io/) with the API token | +| `cargo package` | Make the local crate uploadable to [crates.io](https://crates.io/) | +| `cargo publish` | Upload the crate to [crates.io](https://crates.io/) | +| `cargo install` | Install a Rust binary | +| `cargo uninstall` | Uninstall a Rust binary | + +> πŸ’‘ You need to get an API token from [crates.io](https://crates.io/) to publish a crate to it. The API token can be found in the [Account Settings page](https://crates.io/me), after login to that site. We will discuss more about this under [code organization with crates](/docs/crates#c-using-cratesio). ## Crate -A crate is a package, which can be shared via [crates.io](https://crates.io/). A crate can produce an executable or a library. In other words, it can be a **binary** crate or a **library** crate. +- A crate is a package, which can be shared via Rust community’s crate registry, [crates.io](https://crates.io/). -01. `cargo new crate_name --bin` or `cargo new crate_name`: Produces an executable -02. `cargo new crate_name --lib`: Produces a library +- A crate can produce an executable or a library. In other words, it can be a **binary** crate or a **library** crate. + 1. `cargo new crate_name --bin` or `cargo new crate_name`: Produces an executable + 2. `cargo new crate_name --lib`: Produces a library The first one generates, @@ -54,8 +81,6 @@ and the second one generates, - **src** folder is the place to store the source code. - Each crate has an implicit crate root/ entry point. **main.rs** is the crate root for a binary crate and **lib.rs** is the crate root for a library crate. -> πŸ’‘ When we build a binary crate via `cargo build` or `cargo run`, the executable file will be stored in the **target/debug/** folder. But when building it via **`cargo build --release`** for a release it will be stored in the **target/release/** folder. The release builds are applying more optimizations while compiling the code, to make the code run faster. But it takes more compile time. - ## Project Structure This is how [Cargo documentation describes](https://doc.rust-lang.org/cargo/guide/project-layout.html) about the recommended project layout, @@ -68,7 +93,10 @@ This is how [Cargo documentation describes](https://doc.rust-lang.org/cargo/guid β”‚ β”œβ”€β”€ main.rs β”‚ β”œβ”€β”€ lib.rs β”‚ └── bin -β”‚ └── another_executable.rs +β”‚ β”œβ”€β”€ another_executable.rs +β”‚ └── multi_file_executable +β”‚ β”œβ”€β”€ main.rs +β”‚ └── some_module.rs β”œβ”€β”€ tests β”‚ └── some_integration_tests.rs β”œβ”€β”€ benches @@ -80,23 +108,42 @@ This is how [Cargo documentation describes](https://doc.rust-lang.org/cargo/guid - The source code goes in the `src` directory. - The default executable file is `src/main.rs`. - The default library file is `src/lib.rs`. - - Other executables can be placed in `src/bin/*.rs`. + - Other executables can be placed in, + - `src/bin/*.rs` + - `src/bin/*/main.rs` - Integration tests go in the `tests` directory \(unit tests go in each file they're testing\). - Benchmarks go in the `benches` directory. - Examples go in the `examples` directory. ## Rust Editions -After the initial release in 2015, according to the feedback got from user communities, the Rust team was focusing to increase the **productivity** of the language and the ecosystem. After 3 years of hard work in 2018, a new Rust edition was released with new features, simplified syntax and better tooling. We call it **Rust 2018** edition. +Rust guarantees backward compatibility while introducing major updates to the language. To support this, the `edition` field was added to the `Cargo.toml` file in Rust 2018, marking the first major update to the language ecosystem three years after its initial release. Editions are opt-in, meaning existing crates will not experience these changes until they explicitly migrate to the new edition. -To keep the promise of supporting backward compatibility, the new `edition = "2018"` configuration was added to the `Cargo.toml` file. For new projects, the `cargo new` command adds this configuration by default. So, you don't need to care. But on legacy crates, if you can not see any `edition` configuration, Cargo will consider it as a Rust 2015 edition crate. +The major editions of Rust are: + +- **Rust 2015**: The initial edition, introduced with Rust 1.0. It established the core language features like ownership, borrowing, and lifetimes, laying the foundation for Rust’s safety and concurrency guarantees. + +- **Rust 2018**: The first major update, introduced the `edition` field in `Cargo.toml`, simplified the module system, stabilized `async`/`await`, improved error handling with the `?` operator, and made several syntactic changes. + +- **Rust 2021**: Focused on improving ergonomics and removing inconsistencies, such as disjoint closure capture, `IntoIterator` for arrays, and the introduction of or-patterns in macros. + +- **Rust 2024**: The latest edition, includes enhancements like refined `async` features, more `const` generics, better diagnostics, and improved Cargo features. + +For new projects created by `cargo new`, it will set `edition = "2024"` by default in the `Cargo.toml` file. For example, + +```toml +[package] +name = "hello_world" +version = "0.1.0" +edition = "2024" +``` ## πŸ‘¨β€πŸ« Before going to the next... -- The **`.cargo/bin` directory of your home directory** is the default location of Rust binaries. Not only the official binaries like `rustup`, `rustc`, `cargo`, `rustfmt`, `rustdoc`, `rls` and also the binaries you can install via `cargo install` command, will be stored in this directory. +- The `.cargo/bin` directory of your home directory is the default location of Rust binaries. Not only the official binaries like `rustc`, `cargo`, `rustup`, `rustfmt`, `rustdoc`, `rust-analyzer` and also the binaries you can install via `cargo install` command, will be stored in this directory. - Even though the initial convention for naming crates and file names is using the [`snake_case`](https://en.wikipedia.org/wiki/Snake_case), some crate developers are using `kebab-case` on both crates and file names. To make your code more consistent, use the initial convention `snake_case`; especially on file names. - Create an executable crate via `cargo new` command and run it via `cargo run`. -- Create a library crate via `cargo new` command and run `cargo test`. \ No newline at end of file +- Create a library crate via `cargo new` command and run `cargo test`. diff --git a/content/en/docs/a5.comments-and-documenting-the-code.md b/content/en/docs/a5.comments-and-documenting-the-code.md index 95837b9..f39205a 100755 --- a/content/en/docs/a5.comments-and-documenting-the-code.md +++ b/content/en/docs/a5.comments-and-documenting-the-code.md @@ -16,7 +16,7 @@ Nested block comments are supported. ## Doc Comments -[As we discussed](a4.cargo,crates_and_basic_project_structure.html#cargo), we can generate the project documentation via [rustdoc](https://doc.rust-lang.org/stable/rustdoc/) by running the **`cargo doc`** command. It uses the doc comments to generate the documentation. +[As we discussed](/docs/cargo-crates-and-basic-project-structure/#cargo), we can generate the project documentation via [rustdoc](https://doc.rust-lang.org/stable/rustdoc/) by running the **`cargo doc`** command. It uses the doc comments to generate the documentation. πŸ’‘ Usually we are adding doc comments on library crates. Also, we can use [Markdown notations](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) inside the doc comments. @@ -42,7 +42,7 @@ mod tests { } ``` -> πŸ’­ The `mod` keyword is used for [modules](d3.modules.html). Don't worry about this for now; it'll be discussed later. +> πŸ’­ The `mod` keyword is used for [modules](/docs/modules). Don't worry about this for now; it'll be discussed later. ## Doc Attributes [Doc attributes](https://doc.rust-lang.org/rustdoc/the-doc-attribute.html) are alternatives for doc comments. Especially, we use these doc attributes while we need to set controls on [rustdoc](https://doc.rust-lang.org/stable/rustdoc/). Refer [the doc attributes section of rustdoc documentation](https://doc.rust-lang.org/stable/rustdoc/the-doc-attribute.html) for more details. diff --git a/content/en/docs/a6.variable-bindings-constants-and-statics.md b/content/en/docs/a6.variable-bindings-constants-and-statics.md index 01787da..bd241a6 100755 --- a/content/en/docs/a6.variable-bindings-constants-and-statics.md +++ b/content/en/docs/a6.variable-bindings-constants-and-statics.md @@ -9,7 +9,7 @@ slug: variable-bindings-constants-and-statics ⭐️ Rust is a **statically typed** language; it checks data types at compile-time. But it **doesn’t require you to actually type it when declaring variable bindings**. In that case, the compiler checks the usage and sets a better data type for it. But for **constants and statics, you must annotate the type**. Types come after a colon(`:`). -> πŸ’­ In the following examples, we will use [data types](a8.primitive_data_types.html) like `bool`, `i32`, `i64` and `f64`. Don't worry about them for now; they'll be discussed later. +> πŸ’­ In the following examples, we will use [data types](/docs/primitive-data-types) like `bool`, `i32`, `i64` and `f64`. Don't worry about them for now; they'll be discussed later. - **Variable bindings** @@ -78,7 +78,7 @@ fn main() { - The naming convention for the variable bindings is using the [`snake_case`](https://en.wikipedia.org/wiki/Snake_case). But, for constants and statics, we should follow the [`SCREAMING_SNAKE_CASE`](https://en.wikipedia.org/wiki/Snake_case). -- Usually, constants and statics are placed at the top of the code file, outside the functions (after module imports/ [`use` declarations](/docs/d6.use.html)). +- Usually, constants and statics are placed at the top of the code file, outside the functions (after module imports/ [`use` declarations](/docs/use)). ```rust const PI: f64 = 3.14159265359; diff --git a/content/en/docs/a7.functions.md b/content/en/docs/a7.functions.md index 539cf4b..41f4149 100755 --- a/content/en/docs/a7.functions.md +++ b/content/en/docs/a7.functions.md @@ -7,7 +7,7 @@ slug: functions - Named functions are declared with the keyword **`fn`** - When using **arguments**, you **must declare the data types**. -- By default, functions **return an empty [tuple](/docs/a8.primitive_data_types.html#tuples)/ `()`**. If you want to return a value, the **return type must be specified** after **`->`** +- By default, functions **return an empty [tuple](/docs/primitive-data-types/#tuple)/ `()`**. If you want to return a value, the **return type must be specified** after **`->`** ### i. Hello world @@ -67,7 +67,7 @@ fn plus_one(a: i32) -> i32 { ## Closures - Also known as **anonymous functions** or **lambda functions**. -- The **data types of arguments and returns are optional [ ⃰ⁱᡛ](#iv-Without-optional-type-declarations-Creating-and-calling-together)**. +- The **data types of arguments and returns are optional [ ⃰ⁱᡛ](#iv-without-optional-type-declarations-creating-and-calling-together)**. Example with a named function, before using closures. ```rust diff --git a/content/en/docs/a8.primitive-data-types.md b/content/en/docs/a8.primitive-data-types.md index 0525815..befb350 100755 --- a/content/en/docs/a8.primitive-data-types.md +++ b/content/en/docs/a8.primitive-data-types.md @@ -108,7 +108,7 @@ let e = ["x"; 5]; // ["x", "x", "x", "x", "x"] ⭐️ Arrays are **immutable** by default and **even with `mut`, its element count cannot be changed**. -> πŸ”Ž If you are looking for a dynamic/ growable array, you can use [vectors](b1.vectors.html). Vectors can contain any type of elements but all elements must be in the same data type. +> πŸ”Ž If you are looking for a dynamic/ growable array, you can use [vectors](/docs/vectors). Vectors can contain any type of elements but all elements must be in the same data type. - ## Tuple @@ -169,7 +169,7 @@ let b: &str = "こんにけは, δΈ–η•Œ!"; - ## Function -[As we discussed in the functions section as well](a7.functions.html#iv-Function-pointers-Usage-as-a-Data-Type), `p1` is a function pointer to `plus_one()` in the following code. +[As we discussed in the functions section as well](/docs/functions/#iv-function-pointers-usage-as-a-data-type), `p1` is a function pointer to `plus_one()` in the following code. ```rust fn main() { diff --git a/content/en/docs/a9.operators.md b/content/en/docs/a9.operators.md index d7f12de..1954cac 100755 --- a/content/en/docs/a9.operators.md +++ b/content/en/docs/a9.operators.md @@ -108,7 +108,7 @@ let b = (a as f64) / 2.0; //7.5 - ## Borrowing and Dereference Operators `& &mut *` -πŸ”Ž The `&` or `&mut` operators are used for **borrowing** and `*` operator for **dereferencing**. For more information, refer [Ownership](c1.ownership.html), [Borrowing](c2.borrowing.html) & [Lifetimes](c3.lifetimes.html) sections. +πŸ”Ž The `&` or `&mut` operators are used for **borrowing** and `*` operator for **dereferencing**. For more information, refer [Ownership](/docs/ownership), [Borrowing](/docs/borrowing) & [Lifetimes](/docs/lifetimes) sections. ## πŸ‘¨β€πŸ« Before going to the next... diff --git a/content/en/docs/b2.structs.md b/content/en/docs/b2.structs.md index 26800c4..1577de6 100755 --- a/content/en/docs/b2.structs.md +++ b/content/en/docs/b2.structs.md @@ -26,7 +26,7 @@ There are 3 variants of structs, ⭐️ When regarding OOP in Rust, attributes and methods are placed separately on **structs** and **traits**. Structs contain only attributes, traits contain only methods. They are getting connected via **impls**. ->πŸ’‘More complex examples can be found on [impls & traits](b5.impls_and_traits.html), [lifetimes](c3.lifetimes.html) and [modules](d3.modules.html) sections. +>πŸ’‘More complex examples can be found on [impls & traits](/docs/impls-and-traits), [lifetimes](/docs/lifetimes) and [modules](/docs/modules) sections. ## C-like structs diff --git a/content/en/docs/b5.impls-and-traits.md b/content/en/docs/b5.impls-and-traits.md index 85bafaa..c1baa36 100755 --- a/content/en/docs/b5.impls-and-traits.md +++ b/content/en/docs/b5.impls-and-traits.md @@ -33,10 +33,6 @@ fn main() { } // ⭐️ Implementation must appear in the same crate as the self type - -// πŸ’‘ And also in Rust, new traits can be implemented for existing types even for types like i8, f64 and etc. -// Same way existing traits can be implemented for new types you are creating. -// But we can not implement existing traits into existing types. ``` ## Impls & traits, without default methods @@ -67,6 +63,9 @@ fn main() { } // πŸ”Ž Other than functions, traits can contain constants and types. + +// πŸ’‘ And also in Rust, new traits can be implemented for existing types even for types like i8, f64 and etc. +// Same way existing traits can be implemented for new types you are creating. ``` ## Impls, traits & default methods @@ -122,13 +121,13 @@ fn main() { trait From { fn from(T) -> Self; } - impl From for u16 { - //... - } - impl From for u32{ - //... - } - + +impl From for u16 { + //... +} +impl From for u32{ + //... +} // Should specify after the trait name like generic functions ``` @@ -139,13 +138,13 @@ trait Person { fn full_name(&self) -> String; } - trait Employee : Person { // Employee inherits from person trait - fn job_title(&self) -> String; - } +trait Employee : Person { // Employee inherits from person trait + fn job_title(&self) -> String; +} - trait ExpatEmployee : Employee + Expat { // ExpatEmployee inherits from Employee and Expat traits - fn additional_tax(&self) -> f64; - } +trait ExpatEmployee : Employee + Expat { // ExpatEmployee inherits from Employee and Expat traits + fn additional_tax(&self) -> f64; +} ``` ## Trait objects @@ -163,20 +162,22 @@ trait GetSound { struct Cat { sound: String, } - impl GetSound for Cat { - fn get_sound(&self) -> String { - self.sound.clone() - } + +impl GetSound for Cat { + fn get_sound(&self) -> String { + self.sound.clone() } +} struct Bell { sound: String, } - impl GetSound for Bell { - fn get_sound(&self) -> String { - self.sound.clone() - } + +impl GetSound for Bell { + fn get_sound(&self) -> String { + self.sound.clone() } +} fn make_sound(t: &T) { diff --git a/content/en/docs/e1.smart-compiler.md b/content/en/docs/e1.smart-compiler.md index 1c1a75a..493f320 100644 --- a/content/en/docs/e1.smart-compiler.md +++ b/content/en/docs/e1.smart-compiler.md @@ -37,7 +37,7 @@ For more information about this error, try `rustc --explain E0382`. // Also you can use "let _ =" to completely ignore return values ``` -> πŸ’­ In the previous sections, we have discussed memory management concepts like [ownership](c1.ownership.html), [borrowing](c2.borrowing.html), [lifetimes](c3.lifetimes.md) and etc. +> πŸ’­ In the previous sections, we have discussed memory management concepts like [ownership](/docs/ownership), [borrowing](/docs/borrowing), [lifetimes](/docs/lifetimes) and etc. Rust compiler checks not only issues related with lifetimes or memory management and also common coding mistakes, like the following code. @@ -104,4 +104,4 @@ let result = loop { // ok! ο½€ο½€ο½€ ``` -πŸ’‘ Also you can read the same explanations via [Rust Compiler Error Index](https://medium.com/r/?url=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Fdoc.rust-lang.org%2Ferror-index.html). For example to check the explanation of `E0571` error, you can use https://doc.rust-lang.org/error-index.html#E0571. +πŸ’‘ Also you can read the same explanations via [Rust Compiler Error Index](https://doc.rust-lang.org/error_codes/error-index.html). For example to check the explanation of `E0571` error, you can use https://doc.rust-lang.org/error-index.html#E0571. diff --git a/content/en/docs/e2.panicking.md b/content/en/docs/e2.panicking.md index 1c89d19..e8b7c6c 100644 --- a/content/en/docs/e2.panicking.md +++ b/content/en/docs/e2.panicking.md @@ -72,7 +72,7 @@ fn main() { thread 'main' panicked at 'Color { r: 255, g: 255, b: 0 }', src/main.rs:16:5 ``` -As you can see in the above examples `panic!()` supports [`println!()` type style arguments](a3.hello_world.html#Usages-of-println). By default, it prints the **error message, file path and line & column numbers** where the error happens. +As you can see in the above examples `panic!()` supports [`println!()` type style arguments](/docs/hello-world/#-before-going-to-the-next). By default, it prints the **error message, file path and line & column numbers** where the error happens. ## unimplemented!() diff --git a/content/en/docs/e3.option-and-result.md b/content/en/docs/e3.option-and-result.md index b909851..8d8e183 100644 --- a/content/en/docs/e3.option-and-result.md +++ b/content/en/docs/e3.option-and-result.md @@ -5,9 +5,9 @@ slug: option-and-result ## Why Option and Result? -Many languages use **`null`\ `nil`\ `undefined` types** to represent empty outputs, and **`Exceptions`** to handle errors. Rust skips using both, especially to prevent issues like **null pointer exceptions, sensitive data leakages through exceptions** and etc. Instead, Rust provides two special **generic enums**;`Option` and `Result` to deal with above cases. +Many languages use **`null`\ `nil`\ `undefined` types** to represent empty outputs, and **`Exceptions`** to handle errors. Rust skips using both, especially to prevent issues like **null pointer exceptions, sensitive data leakages through exceptions**, etc. Instead, Rust provides two special **generic enums**;`Option` and `Result` to deal with above cases. -> πŸ’­ In the previous sections, we have discussed about the basics of [enums](b3.enums.html), [generics](b4.generics.html) and [`Result` & `Option` types](b4.generics.html#Generalizing-enums). +> πŸ’­ In the previous sections, we have discussed about the basics of [enums](/docs/enums), [generics](/docs/generics) and [`Result` & `Option` types](/docs/generics/#generalizing-enums). As you know, - An **optional value** can have either **Some** value or no value/ **None**. @@ -27,17 +27,19 @@ enum Result { // T and E are generics. T can contain any type of value, E } ``` -πŸ’­ Also as we discussed in [preludes](d7.std_primitives_and_preludes.html#Preludes), not only `Option` and `Result`, and also their variants are in preludes. So, we can use them directly without using namespaces in the code. +πŸ’­ Also as we discussed in [preludes](/docs/std-primitives-and-preludes/#preludes), not only `Option` and `Result`, and also their variants are in preludes. So, we can use them directly without using namespaces in the code. ## Basic usages of Option When writing a function or data type, + - if an **argument** of the function is optional, -- If the function is non-void and if the output it **returns** can be empty, -- If the value, of a **property of the data type** can be empty, -We have to use their data type as an `Option` type +- if the function is non-void and if the output it **returns** can be empty, +- if the value of a **property of the data type** can be empty, + +we have to use their data type as an `Option` type. -For example, if the function outputs a `&str` value and the output can be empty, the return type of the function should set as `Option<&str>`. +For example, if the function outputs a `&str` value and the output can be empty, the return type of the function should be set as `Option<&str>`. ```rust fn get_an_optional_value() -> Option<&str> { @@ -50,7 +52,7 @@ fn get_an_optional_value() -> Option<&str> { } ``` -Same way, if the value of a property of a data type can be empty or optional like the `middle_name` of `Name` data type in the following example, we should set its data type as an `Option` type. +In the same way, if the value of a property of a data type can be empty or optional like the `middle_name` of the `Name` data type in the following example, we should set its data type as an `Option` type. ```rust struct Name { @@ -60,7 +62,7 @@ struct Name { } ``` -πŸ’­ As you know, we can use pattern matching to catch the relevant return type (`Some`/ `None`) via `match`. There is a function to get the current user’s home directory in **`std::env`** as **[`home_dir()`](https://doc.rust-lang.org/std/env/fn.home_dir.html)**. Because of all users doesn’t have a home directory in the systems like Linux, home directory of the user can be optional. So it returns an `Option` type; [`Option`](https://doc.rust-lang.org/std/path/struct.PathBuf.html). +πŸ’­ As you know, we can use pattern matching to catch the relevant return type (`Some`/ `None`) via `match`. There is a function in **`std::env`** called **[`home_dir()`](https://doc.rust-lang.org/std/env/fn.home_dir.html)** to get the current user's home directory. However, not all users have a home directory in systems like Linux, so the home directory of a user can be optional. So it returns an `Option` type; [`Option`](https://doc.rust-lang.org/std/path/struct.PathBuf.html). ```rust use std::env; @@ -96,7 +98,7 @@ fn main() { ## Basic usages of Result -If a function can produce an error, we have to use a `Result` type by **combining the data type of the valid output and the data type of the error**. For example, if the data type of the valid output is `u64` and error type is `String`, return type should be `Result`. +If a function can produce an error, we have to use a `Result` type by **combining the data type of the valid output and the data type of the error**. For example, if the data type of the valid output is `u64` and error type is `String`, the return type should be `Result`. ```rust fn function_with_error() -> Result { @@ -109,7 +111,7 @@ fn function_with_error() -> Result { } ``` -πŸ’­ As you know, we can use the pattern matching to catch the relevant return types (`Ok`/`Err`) via `match`. There is a function to fetch the value of any environment variable in **`std::env`** as **[`var()`](https://doc.rust-lang.org/std/env/fn.var.html)** . Its input is the environment variable name. This can produce an error, if we passes a wrong environment variable or the program can not extract the value of the environment variable while running. So, its return type is a `Result` type; [`Result`](https://doc.rust-lang.org/std/env/enum.VarError.html). +πŸ’­ As you know, we can use the pattern matching to catch the relevant return types (`Ok`/`Err`) via `match`. There is a function to fetch the value of any environment variable in **`std::env`** called **[`var()`](https://doc.rust-lang.org/std/env/fn.var.html)**. Its input is the environment variable name. This can produce an error if we pass a wrong environment variable or the program cannot extract the value of the environment variable while running. So, its return type is a `Result` type; [`Result`](https://doc.rust-lang.org/std/env/enum.VarError.html). ```rust use std::env; @@ -141,7 +143,7 @@ fn main() { ## ok(), err() for Result types -In addition to that Rust provides `ok()` and `err()` for `Result` types. They convert the `Ok` and `Err` values of a **`Result` type to `Option` types**. +In addition to that, Rust provides `ok()` and `err()` for `Result` types. They convert the `Ok` and `Err` values of a **`Result` type to `Option` types**. ```rust fn main() { diff --git a/content/en/docs/e4.unwrap-and-expect.md b/content/en/docs/e4.unwrap-and-expect.md index 812e8c1..40eb0e0 100644 --- a/content/en/docs/e4.unwrap-and-expect.md +++ b/content/en/docs/e4.unwrap-and-expect.md @@ -197,7 +197,7 @@ fn main() { } ``` -- `unwrap_or_else()`Β : Similar to `unwrap_or()`. The only difference is, instead of passing a value, you have to pass a **[closure](a7.functions.html#Closures)** which returns a value with the same data type of the relevant `Some` or `Ok`. +- `unwrap_or_else()`Β : Similar to `unwrap_or()`. The only difference is, instead of passing a value, you have to pass a **[closure](/docs/functions/#closures)** which returns a value with the same data type of the relevant `Some` or `Ok`. ```rust fn main() { diff --git a/content/en/docs/e5.error-and-none-propagation.md b/content/en/docs/e5.error-and-none-propagation.md index 349eba4..2f65010 100644 --- a/content/en/docs/e5.error-and-none-propagation.md +++ b/content/en/docs/e5.error-and-none-propagation.md @@ -93,7 +93,7 @@ let x = try!(function_with_error()); Before Rust version 1.26, we couldn't propagate `Result` and `Option` types from the `main()` function. But now, we **can propagate `Result` types** from the `main()` function and it prints the **`Debug` representation of the `Err`**. -πŸ’‘ We are going to discuss about `Debug` representations under [Error trait section](e7.custom_error_types.html#Error-trait). +πŸ’‘ We are going to discuss about `Debug` representations under [Error trait section](/docs/custom-error-types/#error-trait). ```rust use std::fs::File; diff --git a/content/en/docs/e6.combinators.md b/content/en/docs/e6.combinators.md index f77d18a..4cbba4f 100644 --- a/content/en/docs/e6.combinators.md +++ b/content/en/docs/e6.combinators.md @@ -78,7 +78,7 @@ fn main() { ## or_else() -Similar to `or()`. The only difference is, the second expression should be a **[closure](a7.functions.html#Closures)** which returns same type T. +Similar to `or()`. The only difference is, the second expression should be a **[closure](/docs/functions/#closures)** which returns same type T. ```rust fn main() { @@ -113,7 +113,7 @@ fn main() { ## and_then() -Similar to `and()`. The only difference is, the second expression should be a **[closure](a7.functions.html#Closures)** which returns same type T. +Similar to `and()`. The only difference is, the second expression should be a **[closure](/docs/functions/#closures)** which returns same type T. ```rust fn main() { @@ -219,7 +219,7 @@ fn main() { ## map_or() and map_or_else() -Hope you remember the functionality of [`unwrap_or()` and `unwrap_or_else()`](e4.unwrap_and_expect.html#unwrap-or-unwrap-or-default-and-unwrap-or-else) functions. These functions also bit similar to them. But `map_or()` and `map_or_else()` apply a closure on `Some` and `Ok` values and **return the value inside type T**. +Hope you remember the functionality of [`unwrap_or()` and `unwrap_or_else()`](/docs/unwrap-and-expect/#unwrap_or-unwrap_or_default-and-unwrap_or_else) functions. These functions also bit similar to them. But `map_or()` and `map_or_else()` apply a closure on `Some` and `Ok` values and **return the value inside type T**. - `map_or()` : Support only for `Option` types (not supporting `Result`). Apply the closure to the value inside `Some` and return the output according to the closure. The given default value is returned for `None` types. diff --git a/content/en/docs/e7.custom-error-types.md b/content/en/docs/e7.custom-error-types.md index d150833..d0842a4 100644 --- a/content/en/docs/e7.custom-error-types.md +++ b/content/en/docs/e7.custom-error-types.md @@ -17,7 +17,7 @@ pub trait Error: Debug + Display { } ``` -> As we discussed under [traits inheritance](b5.impls_and_traits.html#Traits-inheritance), a trait can be inherited from another traits. `trait Error: Debug + Display` means `Error` trait inherits from `fmt::Debug` and `fmt::Display` traits. +> As we discussed under [traits inheritance](/docs/impls-and-traits/#traits-inheritance), a trait can be inherited from another traits. `trait Error: Debug + Display` means `Error` trait inherits from `fmt::Debug` and `fmt::Display` traits. ```rust // traits inside Rust standard library core fmt module/ std::fmt diff --git a/content/en/docs/learning_rust_medium.png b/content/en/docs/learning_rust_medium.png index cf7a659..f2e7a46 100644 Binary files a/content/en/docs/learning_rust_medium.png and b/content/en/docs/learning_rust_medium.png differ diff --git a/content/en/docs/rust_playground.png b/content/en/docs/rust_playground.png index 5833453..580f004 100644 Binary files a/content/en/docs/rust_playground.png and b/content/en/docs/rust_playground.png differ diff --git a/data/en/docs/sidebar.yml b/data/en/docs/sidebar.yml deleted file mode 100644 index 69b966e..0000000 --- a/data/en/docs/sidebar.yml +++ /dev/null @@ -1,50 +0,0 @@ -- title: Documentation - pages: - - title: Overview - -- title: Basics - pages: - - title: Why Rust? - - title: Installation - - title: Hello World - - title: Cargo, Crates and Basic Project Structure - - title: Comments and Documenting the code - - title: Variable bindings, Constants and Statics - - title: Functions - - title: Primitive Data Types - - title: Operators - - title: Control Flows - -- title: Beyond The Basics - pages: - - title: Vectors - - title: Structs - - title: Enums - - title: Generics - - title: Impls and Traits - -- title: The Tough Part - pages: - - title: Ownership - - title: Borrowing - - title: Lifetimes - -- title: Let's Get It Started - pages: - - title: Code Organization - - title: Functions (02) - - title: Modules - - title: Crates - - title: Workspaces - - title: Use - - title: STD, Primitives and Preludes - -- title: Error Handling - pages: - - title: Smart Compiler - - title: Panicking - - title: Option and Result - - title: Unwrap and Expect - - title: Error and None Propagation - - title: Combinators - - title: Custom Error Types diff --git a/static/manifest.json b/static/manifest.json deleted file mode 100644 index 5710e32..0000000 --- a/static/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "short_name": "Learning Rust", - "name": "Learning Rust", - "description": "Rust Programming Language Tutorials", - "start_url": "/?source=pwa", - "display": "standalone", - "icons": [ - { - "src": "/img/icon/icon-192.png", - "type": "image/png", - "sizes": "192x192" - }, - { - "src": "/img/icon/icon-512.png", - "type": "image/png", - "sizes": "512x512" - }, - { - "src": "/img/icon/maskable-icon-192.png", - "type": "image/png", - "sizes": "192x192", - "purpose": "maskable" - }, - { - "src": "/img/icon/maskable-icon-512.png", - "type": "image/png", - "sizes": "512x512", - "purpose": "maskable" - }, - { - "src": "/img/icon/icon-vector.svg", - "type": "image/svg+xml", - "sizes": "512x512" - } - ], - "background_color": "#ffffff", - "theme_color": "#ffffff" -} \ No newline at end of file diff --git a/static/sw.js b/static/sw.js deleted file mode 100644 index 990c71d..0000000 --- a/static/sw.js +++ /dev/null @@ -1,61 +0,0 @@ -const cacheName = 'learning-rust-{{ now.Format "2006-01-02" }}'; -const staticAssets = [ - './', - './index.html', - './manifest.json', - './docs/**/*', - './font/*', - './img/icon/favicon.ico', - './img/icon/icon-16.png', - './img/icon/icon-32.png', - './img/icon/icon-180.png', - './img/icon/icon-192.png', - './img/icon/icon-512.png', - './img/icon/icon-vector.svg', - './img/icon/maskable-icon-192.png', - './img/icon/maskable-icon-512.png', - './js/base.min.js', - './js/component/docsearch.min.js', - './scss/base.css', - './scss/component/docsearch.css', - './scss/home.css', -]; - -self.addEventListener('install', async e => { - const cache = await caches.open(cacheName); - await cache.addAll(staticAssets); - return self.skipWaiting(); -}); - -self.addEventListener('activate', e => { - self.clients.claim(); -}); - -self.addEventListener('fetch', async e => { - const req = e.request; - const url = new URL(req.url); - - if (url.origin === location.origin) { - e.respondWith(cacheFirst(req)); - } else { - e.respondWith(networkFirst(req)); - } -}); - -async function cacheFirst(req) { - const cache = await caches.open(cacheName); - const cached = await cache.match(req); - return cached || fetch(req); -} - -async function networkFirst(req) { - const cache = await caches.open(cacheName); - try { - const fresh = await fetch(req); - cache.put(req, fresh.clone()); - return fresh; - } catch (e) { - const cached = await cache.match(req); - return cached; - } -} \ No newline at end of file diff --git a/themes/docura b/themes/docura deleted file mode 160000 index c5a4114..0000000 --- a/themes/docura +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c5a411485eac5a72f1f4ae86c930354f0d9e20f1