├── docs ├── editors │ ├── vscode.md │ ├── rustrover.md │ ├── index.md │ ├── emacs.md │ └── neovim.md ├── reference │ ├── index.md │ └── books.md ├── introduction │ ├── memory-management.md │ ├── funtional-concepts.md │ ├── rust-workflow.md │ ├── features.md │ └── rust-in-15-minutes.md ├── assets │ ├── favicon.ico │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ ├── apple-touch-icon.png │ ├── android-chrome-192x192.png │ ├── android-chrome-512x512.png │ ├── images │ │ ├── practicalli-logo.png │ │ └── social │ │ │ └── README.md │ ├── stylesheets │ │ ├── extra.css │ │ └── practicalli-light.css │ ├── favicon.svg │ └── practicalli-logo.svg ├── projects │ ├── guides │ │ ├── index.md │ │ └── rest-api.md │ └── index.md ├── index.md ├── learn │ └── index.md └── install │ └── index.md ├── .github ├── CODEOWNERS ├── config │ ├── secretlintrc.json │ ├── markdown-link-check.json │ ├── gitleaks.toml │ ├── lychee.toml │ ├── megalinter.yaml │ └── markdown-lint.jsonc ├── pull_request_template.md └── workflows │ ├── changelog-check.yaml │ ├── scheduled-version-check.yaml │ ├── publish-book.yaml │ ├── scheduled-stale-check.yaml │ └── megalinter.yaml ├── CHANGELOG.md ├── overrides ├── main.html ├── partials │ ├── source.html │ ├── palette.html │ └── header.html └── 404.html ├── .gitattributes ├── .gitignore ├── Makefile ├── mkdocs.yml ├── README.md └── LICENSE /docs/editors/vscode.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/reference/index.md: -------------------------------------------------------------------------------- 1 | # Reference 2 | -------------------------------------------------------------------------------- /docs/introduction/memory-management.md: -------------------------------------------------------------------------------- 1 | # Memory Management 2 | -------------------------------------------------------------------------------- /docs/introduction/funtional-concepts.md: -------------------------------------------------------------------------------- 1 | # Functional Concepts 2 | -------------------------------------------------------------------------------- /docs/assets/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/practicalli/rust/main/docs/assets/favicon.ico -------------------------------------------------------------------------------- /docs/assets/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/practicalli/rust/main/docs/assets/favicon-16x16.png -------------------------------------------------------------------------------- /docs/assets/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/practicalli/rust/main/docs/assets/favicon-32x32.png -------------------------------------------------------------------------------- /docs/assets/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/practicalli/rust/main/docs/assets/apple-touch-icon.png -------------------------------------------------------------------------------- /docs/editors/rustrover.md: -------------------------------------------------------------------------------- 1 | # RustRover 2 | 3 | [RustRover](https://www.jetbrains.com/rust/){target=_blank .md-button} 4 | -------------------------------------------------------------------------------- /docs/assets/android-chrome-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/practicalli/rust/main/docs/assets/android-chrome-192x192.png -------------------------------------------------------------------------------- /docs/assets/android-chrome-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/practicalli/rust/main/docs/assets/android-chrome-512x512.png -------------------------------------------------------------------------------- /docs/assets/images/practicalli-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/practicalli/rust/main/docs/assets/images/practicalli-logo.png -------------------------------------------------------------------------------- /docs/projects/guides/index.md: -------------------------------------------------------------------------------- 1 | # Guides 2 | 3 | Step by step practical guide to building applications and services with Rust. 4 | 5 | 6 | - [Rest API with Axum and OpenAPI](rest-api/index.md) 7 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Codeowners 2 | 3 | # Default owner accounts for the current repository 4 | # Automatically added as a reviewr to all pull requests (not including drafts) 5 | 6 | * @practicalli-johnny 7 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | # Unreleased 4 | 5 | ## Added 6 | - reference: books videos and courses 7 | - editor: neovim details and supporting tools 8 | - dev: dependencies-outdates & dependencies-update make tasks 9 | 10 | ## Changed 11 | - dev: update github actions to latest versions 12 | -------------------------------------------------------------------------------- /overrides/main.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | {% extends "base.html" %} 10 | 11 | 12 | {% block announce %} 13 | 14 | Practicalli Rust is a work in progress 15 | 16 | {% endblock %} 17 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Configure Languages for GitHub repository using Linguist 2 | 3 | # Markdown & Make detection, 4 | # exclude HTML, CSS & JavaScript 5 | docs/** linguist-detectable 6 | *.md linguist-detectable=true 7 | make linguist-detectable=true 8 | *.css linguist-detectable=false 9 | *.js linguist-detectable=false 10 | *.html linguist-detectable=false 11 | -------------------------------------------------------------------------------- /.github/config/secretlintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": [ 3 | { 4 | "id": "@secretlint/secretlint-rule-basicauth", 5 | "options": { 6 | "allows": [ 7 | "hostname.domain.com", 8 | "jdbc:postgresql://:port/?user=&password=", 9 | "postgres://postgres://username:password@hostname.domain.com:1234/database-name" 10 | ] 11 | } 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /docs/assets/images/social/README.md: -------------------------------------------------------------------------------- 1 | # Social Cards 2 | 3 | Social Cards are visual previews of the website that are included when sending links via social media platforms. 4 | 5 | Material for MkDocs is [configured to generate beautiful social cards automatically](https://squidfunk.github.io/mkdocs-material/setup/setting-up-social-cards/), using the colors, fonts and logos defined in `mkdocs.yml` 6 | 7 | Generated images are stored in this directory. 8 | -------------------------------------------------------------------------------- /overrides/partials/source.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | {% set icon = config.theme.icon.repo or "fontawesome/brands/git-alt" %} 4 | {% include ".icons/" ~ icon ~ ".svg" %} 5 |
6 |
7 | {{ config.repo_name }} 8 |
9 |
10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Exclude all files from root directory 2 | /* 3 | 4 | # ------------------------ 5 | # Common project files 6 | !CHANGELOG.md 7 | !README.md 8 | !LICENSE 9 | 10 | # ------------------------ 11 | # Include MkDocs files 12 | !docs/ 13 | !includes/ 14 | !overrides/ 15 | !mkdocs.yml 16 | 17 | # ------------------------ 18 | # Project automation 19 | !Makefile 20 | 21 | # ------------------------ 22 | # Version Control 23 | !.gitignore 24 | !.gitattributes 25 | !.github/ 26 | 27 | -------------------------------------------------------------------------------- /overrides/404.html: -------------------------------------------------------------------------------- 1 | 4 | 5 | {% extends "main.html" %} 6 | 7 | 8 | {% block content %} 9 |

This is not the page you are looking for

10 | 11 |

12 | Sorry we have arrived at a page that does not exist... 13 |

14 | 15 |

16 | Practicalli website are published using Material for MkDocs 17 |

18 | 19 |

20 | Use the Search bar at the top of the page or left navigation to find the relevant content. 21 |

22 | 23 | {% endblock %} 24 | -------------------------------------------------------------------------------- /.github/config/markdown-link-check.json: -------------------------------------------------------------------------------- 1 | { 2 | "ignorePatterns": [ 3 | { 4 | "pattern": "^http://localhost" 5 | }, 6 | { 7 | "pattern": "^mailto:*" 8 | }, 9 | { 10 | "pattern": "^#*" 11 | }, 12 | { 13 | "pattern": "^https://127.0.0.0/" 14 | } 15 | ], 16 | "timeout": "20s", 17 | "retryOn429": true, 18 | "retryCount": 5, 19 | "fallbackRetryDelay": "30s", 20 | "aliveStatusCodes": [ 21 | 200, 22 | 206 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /.github/config/gitleaks.toml: -------------------------------------------------------------------------------- 1 | title = "gitleaks config" 2 | 3 | [allowlist] 4 | description = "global allow lists" 5 | paths = [ 6 | '''gitleaks.toml''', 7 | '''(.*?)(jpg|gif|doc|docx|zip|xls|pdf|bin|svg|socket)$''', 8 | '''(go.mod|go.sum)$''', 9 | '''gradle.lockfile''', 10 | '''node_modules''', 11 | '''package-lock.json''', 12 | '''pnpm-lock.yaml''', 13 | '''Database.refactorlog''', 14 | '''vendor''', 15 | ] 16 | 17 | [[rules]] 18 | description = "AWS Example API Key" 19 | id = "aws-example-api-key" 20 | regex = '''AKIAIOSFODNN7EXAMPLE''' 21 | keywords = [ 22 | "awstoken", 23 | ] 24 | -------------------------------------------------------------------------------- /docs/editors/index.md: -------------------------------------------------------------------------------- 1 | # Editors for Rust 2 | 3 | 4 | 5 | 6 | - [Neovim](neovim.md) - Treesitter Rust parser, rusacea.nvim 7 | - [Emacs](emacs.md) 8 | - [VS Code](vscode.md) 9 | - [RustRover](rustrover.md) 10 | 11 | 12 | 13 | ## Rust LSP server 14 | 15 | Editors with Rust support benefits from the [rust-analyser](), a Language Server Protocol (LSP) implementation for the Rust language. 16 | 17 | The rust-analyser server runs a static analysis of the code in a project, returning data about syntax errors and language idioms. 18 | 19 | Data is used by LSP clients which are found in the majority of editors (or editor extensions) to display diagnostics in the user interface. 20 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # Practicalli Rust 2 | 3 | Practicalli Rust is a hands-on guide to using the Rust programming language throughout all the software development stages. 4 | 5 | Live coding videos demonstrate the Rust workflow in action, showing how to get the most out of the unique approach the language provides. 6 | 7 | Practical code examples are supported by discussions of the concepts behind Rust, including functional programming and effective tooling. 8 | 9 | 10 | [Rust Language Homepage](https://www.rust-lang.org/){target=_blank} 11 | 12 | 13 | ## Rust community 14 | 15 | [The Rust Book](https://doc.rust-lang.org/stable/book/index.html) 16 | 17 | [Rust API](https://doc.rust-lang.org/stable/std/index.html) 18 | 19 | [:fontawesome-solid-book-open: Rust blog](https://blog.rust-lang.org/){target=_blank} 20 | 21 | [Rust online playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024){target=_blank .md-button} 22 | -------------------------------------------------------------------------------- /docs/introduction/rust-workflow.md: -------------------------------------------------------------------------------- 1 | # Rust Workflow 2 | 3 | - Create project 4 | - Open in Editor 5 | - Define dependencies 6 | - build, run, code 7 | 8 | 9 | ## Evaluation 10 | 11 | Rust does not provide a REPL however it could be possible to create one. 12 | 13 | ... is a very basic script that evaluates code agains the Rust Playground API. 14 | 15 | > NOTE: Is should be possible to send Rust forms to the compiler and get a result. Perhaps an implementation of nREPL protocol or similar would be valuable? 16 | 17 | 18 | ## Testing 19 | 20 | 21 | ### Nextest 22 | 23 | [Nextest](https://github.com/nextest-rs/nextest) is a Next-gen test runner for Rust. 24 | 25 | Up to 3 times faster than `cargo test` 26 | 27 | - nextest-runner: core logic for cargo-nextest 28 | - nextest-metadata: library for calling cargo-nextest over the command line 29 | - nextest-filtering: parser and evaluator for [filtersets](https://nexte.st/docs/filtersets) 30 | -------------------------------------------------------------------------------- /.github/config/lychee.toml: -------------------------------------------------------------------------------- 1 | 2 | # ---------------------------------------- 3 | # Base URL or website root directory to check relative URLs. 4 | base = "https://practical.li/rust/" 5 | 6 | # Only test links with the given schemes (e.g. https). 7 | # Omit to check links with any other scheme. 8 | # At the moment, we support http, https, file, and mailto. 9 | scheme = ["https"] 10 | 11 | # ---------------------------------------- 12 | # Exclusions 13 | 14 | # Exclude URLs and mail addresses from checking (supports regex). 15 | exclude = ['^https://127.0.0.0', '^https://www\.linkedin\.com', '^https://web\.archive\.org/web/'] 16 | 17 | # Exclude these filesystem paths from getting checked. 18 | exclude_path = ["mkdocs.yml", "overrides", "includes", ".github", ".git"] 19 | 20 | # Exclude all private IPs from checking. 21 | # Equivalent to setting `exclude_private`, `exclude_link_local`, and 22 | # `exclude_loopback` to true. 23 | exclude_all_private = true 24 | 25 | # Check mail addresses 26 | include_mail = false 27 | # ---------------------------------------- 28 | -------------------------------------------------------------------------------- /docs/editors/emacs.md: -------------------------------------------------------------------------------- 1 | # Emacs 2 | 3 | Rust-mode provides core workflow support. [rustic](#rustic-mode) 4 | 5 | 6 | ## Rust-mode 7 | `rust-mode` makes editing [Rust](http://rust-lang.org) code with Emacs enjoyable. It requires Emacs 25 or later, and is included in both [Emacs Prelude](https://github.com/bbatsov/prelude) and [Spacemacs](https://github.com/syl20bnr/spacemacs) by default. 8 | 9 | rust-mode provides: 10 | 11 | - Syntax highlighting (for Font Lock Mode) 12 | - Indentation 13 | - Integration with Cargo, clippy and rustfmt 14 | 15 | This mode does _not_ provide auto completion, or jumping to function / trait definitions. 16 | 17 | 18 | ## rustic mode 19 | 20 | Rustic is based on [rust-mode](https://github.com/rust-lang/rust-mode) and provides additional features: 21 | 22 | - cargo popup 23 | - multiline error parsing 24 | - translation of ANSI control sequences through 25 | [xterm-color](https://github.com/atomontage/xterm-color) 26 | - async org babel 27 | - automatic LSP configuration with 28 | [eglot](https://github.com/joaotavora/eglot) or 29 | [lsp-mode](https://github.com/emacs-lsp/lsp-mode) 30 | - [eask][] for testing 31 | 32 | rustic only shares the rust-mode code from rust-mode.el and rust-utils.el. 33 | 34 | 35 | ## LSP client 36 | -------------------------------------------------------------------------------- /overrides/partials/palette.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | {% for option in config.theme.palette %} 7 | {% set scheme = option.scheme | d("default", true) %} 8 | {% set primary = option.primary | d("indigo", true) %} 9 | {% set accent = option.accent | d("indigo", true) %} 10 | 25 | {% if option.toggle %} 26 | 34 | {% endif %} 35 | {% endfor %} 36 |
37 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | :memo: Description 2 | 3 | 4 | :white_check_mark: Checklist 5 | 6 | - [ ] Commits should be cryptographically signed (SSH or GPG) 7 | 8 | 9 | ## Practicalli Guidelines 10 | 11 | Please follow these guidelines when submitting a pull request 12 | 13 | - refer to all relevant issues, using `#` followed by the issue number (or paste full link to the issue) 14 | - PR should contain the smallest possible change 15 | - PR should contain a very specific change 16 | - PR should contain only a single commit (squash your commits locally if required) 17 | - Avoid multiple changes across multiple files (raise an issue so we can discuss) 18 | - Avoid a long list of spelling or grammar corrections. These take too long to review and cherry pick. 19 | 20 | ## Submitting articles 21 | 22 | [Create an issue using the article template](https://github.com/practicalli/rust/issues/new?assignees=&labels=article&template=article.md&title=Suggested+article+title), 23 | providing as much detail as possible. 24 | 25 | ## Website design 26 | 27 | Suggestions about website design changes are most welcome, especially in terms of usability and accessibility. 28 | 29 | Please raise an issue so we can discuss changes first, especially changes related to aesthetics. 30 | 31 | ## Review process 32 | 33 | All pull requests are reviewed by @practicalli-johnny and feedback provided, usually the same day but please be patient. 34 | -------------------------------------------------------------------------------- /.github/workflows/changelog-check.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | # Check CHANGELOG.md file updated for every pull request 3 | 4 | name: Changelog Check 5 | on: 6 | pull_request: 7 | paths-ignore: 8 | - "README.md" 9 | types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled] 10 | 11 | jobs: 12 | changelog: 13 | name: Changelog Update Check 14 | runs-on: ubuntu-latest 15 | steps: 16 | - run: echo "🚀 Job automatically triggered by ${{ github.event_name }}" 17 | - run: echo "🐧 Job running on ${{ runner.os }} server" 18 | - run: echo "🐙 Using ${{ github.ref }} branch from ${{ github.repository }} repository" 19 | 20 | # Git Checkout 21 | - name: Checkout Code 22 | uses: actions/checkout@v5 23 | with: 24 | fetch-depth: 0 25 | sparse-checkout: | 26 | docs 27 | overrides 28 | .github 29 | CHANGELOG.md 30 | - run: echo "🐙 Sparse Checkout of ${{ github.repository }} repository to the CI runner." 31 | 32 | # Changelog Enforcer 33 | - name: Changelog Enforcer 34 | uses: dangoslen/changelog-enforcer@v3 35 | with: 36 | changeLogPath: "CHANGELOG.md" 37 | skipLabels: "skip-changelog-check" 38 | 39 | # Summary and status 40 | - run: echo "🎨 Changelog Enforcer quality checks completed" 41 | - run: echo "🍏 Job status is ${{ job.status }}." 42 | -------------------------------------------------------------------------------- /docs/editors/neovim.md: -------------------------------------------------------------------------------- 1 | # Neovim for Rust 2 | 3 | Neovim provides excellent syntax support via the Treesiter parser for rust. 4 | 5 | [rust-analyzer](){target=_blank} provides an LSP server that returns diagnostics to the Neovim LSP Client and/or rustaceanvim 6 | 7 | [rustaceanvim](https://github.com/mrcjkb/rustaceanvim){target=_blank} provides [extensive features for rust development](https://github.com/mrcjkb/rustaceanvim?tab=readme-ov-file#books-usage--features) and integrates with LSP clients. 8 | 9 | 10 | === "Practicalli Astro" 11 | 12 | !!! NOTE "Add Astrocommunity Rust Pack" 13 | ```lua 14 | { import = "astrocommunity.pack.rust" }, 15 | ``` 16 | 17 | Rust support provided via the [Astrocommunity Rust pack](https://github.com/AstroNvim/astrocommunity/tree/main/lua/astrocommunity/pack/rust) 18 | 19 | - rust Treesitter parser 20 | - LSP support via rust-analyzer & cargo clippy 21 | - DAP (debug) via codelldb (mason installl) 22 | - rustaceanvim for rust specific tooling via rust-analyzer 23 | - crates.nvim for crate management and completion 24 | - TOML language support 25 | - [neotest](https://github.com/nvim-neotest/neotest) is a Neovim framework for test runners, i.e. rustaceanvim.neotest 26 | 27 | `rust-analyzer` shold be added via the `rustup` tool 28 | 29 | !!! NOTE "Install rust-analyzer via rustup" 30 | ```shell 31 | rustup component add rust-analyzer 32 | ``` 33 | 34 | ```shell-output 35 | ❯ rustup component add rust-analyzer 36 | info: downloading component 'rust-analyzer' 37 | info: installing component 'rust-analyzer' 38 | ``` 39 | -------------------------------------------------------------------------------- /docs/learn/index.md: -------------------------------------------------------------------------------- 1 | # Learn Rust 2 | 3 | Learning any programming language involves (in no specific order) 4 | 5 | - understanding the syntax 6 | - absorbing the concepts the language is built upon 7 | - establishing an effective development workflow 8 | - discovering idioms and patterns 9 | - practice, practice, practice 10 | 11 | 12 | ## Syntax 13 | 14 | [The Rust Book]() 15 | 16 | 17 | ## Practice Practice Practice 18 | 19 | [Rustlings](https://github.com/rust-lang/rustlings) small exercises to support reading and writing Rust (use in parallel with the Rust book). 20 | 21 | [Exercism - Rust track](https://exercism.org/tracks/rust){target=_blank} challenges to practice rust (includes on-line mentor support) 22 | 23 | [Rust Tutorial video series](https://www.youtube.com/playlist?list=PLLqEtX6ql2EyPAZ1M2_C0GgVd4A-_L4_5){target=_blank} for an in-depth introduction to the language 24 | 25 | [Rust online playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024){target=_blank .md-button} 26 | 27 | 28 | [Rust local playground](https://github.com/menard-codes/rust_playground_locally) calls the Rust Playground API from your terminal (not the same as a Clojure REPL). 29 | 30 | 31 | ## Additional Resources 32 | 33 | 34 | TODO: review resources for learning rust 35 | 36 | [How to learn Rust in 2025 - Jetbrains](https://blog.jetbrains.com/rust/2024/09/20/how-to-learn-rust/){target=_blank} 37 | 38 | [Rust Primer - Code Crafters](https://app.codecrafters.io/collections/rust-primer){target=_blank .md-button} 39 | 40 | [Gentle intro to Rust](https://stevedonovan.github.io/rust-gentle-intro/){target=_blank .md-button} 41 | 42 | [Rust Primer for writing CLIs](https://github.com/kyclark/command-line-rust) 43 | -------------------------------------------------------------------------------- /.github/workflows/scheduled-version-check.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | # ------------------------------------------ 3 | # Scheduled check of versions 4 | # - use as non-urgent report on versions 5 | # - Uses POSIX Cron syntax 6 | # - Minute [0,59] 7 | # - Hour [0,23] 8 | # - Day of the month [1,31] 9 | # - Month of the year [1,12] 10 | # - Day of the week ([0,6] with 0=Sunday) 11 | # 12 | # Using liquidz/anta to check: 13 | # - GitHub workflows 14 | # - deps.edn 15 | # ------------------------------------------ 16 | 17 | name: "Scheduled Version Check" 18 | on: 19 | schedule: 20 | # - cron: "0 4 * * *" # at 04:04:04 ever day 21 | # - cron: "0 4 * * 5" # at 04:04:04 ever Friday 22 | - cron: "0 4 1 * *" # at 04:04:04 on first day of month 23 | workflow_dispatch: # Run manually via GitHub Actions Workflow page 24 | 25 | jobs: 26 | scheduled-version-check: 27 | name: "Scheduled Version Check" 28 | runs-on: ubuntu-latest 29 | steps: 30 | - run: echo "🚀 Job automatically triggered by ${{ github.event_name }}" 31 | - run: echo "🐧 Job running on ${{ runner.os }} server" 32 | - run: echo "🐙 Using ${{ github.ref }} branch from ${{ github.repository }} repository" 33 | 34 | - name: Checkout Code 35 | uses: actions/checkout@v5 36 | with: 37 | fetch-depth: 0 38 | sparse-checkout: | 39 | .github 40 | - run: echo "🐙 ${{ github.repository }} repository sparse-checkout to the CI runner." 41 | - name: "Antq Check versions" 42 | uses: liquidz/antq-action@main 43 | with: 44 | excludes: "" 45 | skips: "boot clojure-cli pom shadow-cljs leiningen" 46 | 47 | # Summary 48 | - run: echo "🎨 library versions checked with liquidz/antq" 49 | - run: echo "🍏 Job status is ${{ job.status }}." 50 | -------------------------------------------------------------------------------- /.github/workflows/publish-book.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Publish Book 3 | on: 4 | # Manually trigger workflow 5 | workflow_dispatch: 6 | 7 | # Run work flow conditional on linter workflow success 8 | workflow_run: 9 | workflows: 10 | - "MegaLinter" 11 | paths: 12 | - "docs/**" 13 | - "includes/**" 14 | - "overrides/**" 15 | - "mkdocs.yaml" 16 | branches: 17 | - main 18 | types: 19 | - completed 20 | 21 | permissions: 22 | contents: write 23 | 24 | jobs: 25 | publish-book: 26 | name: MkDocs Publish 27 | runs-on: ubuntu-latest 28 | steps: 29 | - run: echo "🚀 Job automatically triggered by ${{ github.event_name }}" 30 | - run: echo "🐧 Job running on ${{ runner.os }} server" 31 | - run: echo "🐙 Using ${{ github.ref }} branch from ${{ github.repository }} repository" 32 | 33 | - name: Checkout Code 34 | uses: actions/checkout@v5 35 | with: 36 | fetch-depth: 0 37 | sparse-checkout: | 38 | docs 39 | includes 40 | overrides 41 | - run: echo "🐙 ${{ github.repository }} repository sparse-checkout to the CI runner." 42 | 43 | - name: Setup Python 44 | uses: actions/setup-python@v6 45 | with: 46 | python-version: 3.x 47 | 48 | - name: Cache 49 | uses: actions/cache@v4 50 | with: 51 | key: ${{ github.ref }} 52 | path: .cache 53 | 54 | - run: pip install mkdocs-material mkdocs-callouts mkdocs-glightbox mkdocs-git-revision-date-localized-plugin mkdocs-redirects pillow cairosvg 55 | - run: mkdocs gh-deploy --force 56 | - run: echo "🐙 ." 57 | 58 | # Summary and status 59 | - run: echo "🎨 MkDocs Publish Book workflow completed" 60 | - run: echo "🍏 Job status is ${{ job.status }}." 61 | -------------------------------------------------------------------------------- /docs/projects/index.md: -------------------------------------------------------------------------------- 1 | # Projects 2 | 3 | Cargo package manager is use to create and work with Rust projects. 4 | 5 | Templates can be used to bootstrap new rust projects. 6 | 7 | 8 | ## Command reference 9 | 10 | | Command | Description | 11 | | --- | --- | 12 | | `cargo new project-name` | Create a new rust project with given name | 13 | | `cargo build` | Build rust project, resolving library dependencies | 14 | | `cargo run` | Run Rust project | 15 | | `cargo test` | Run test runner for Rust project | 16 | | `cargo doc` | Generate Project documentation | 17 | | `cargo publish` | Publish library to crates.io | 18 | 19 | 20 | ## Create a new rust project 21 | 22 | !!! NOTE "" 23 | ```shell 24 | cargo new project-name 25 | ``` 26 | 27 | ```shell-ouptput 28 | ❯ cargo new playground 29 | Creating binary (application) `playground` package 30 | note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 31 | ``` 32 | 33 | Project structure 34 | 35 | ```shell-output 36 | ❯ tree playground 37 | playground 38 | ├── Cargo.toml 39 | └── src 40 | └── main.rs 41 | 42 | 2 directories, 2 files 43 | ``` 44 | 45 | 46 | ## Library Dependencies 47 | 48 | `Cargo.toml` file in the root of a project is used to define library dependencies for the project. 49 | 50 | Define a dependency with its name and version. 51 | 52 | ```rust 53 | [dependencies] 54 | ferris-says = "0.3.2" 55 | ``` 56 | 57 | `Cargo.lock` contains a log of the specific versions of dependencies for the project, created and updated by the `cargo build` command. 58 | 59 | 60 | Make the library available with the `use` directive 61 | 62 | ```rust 63 | use ferris_says::say; 64 | use std::io::{stdout, BufWriter}; 65 | 66 | fn main() { 67 | let out = "Hello fellow Rustaceans!"; 68 | let width = 24; 69 | 70 | let mut writer = BufWriter::new(stdout()); 71 | say(out, width, &mut writer).unwrap(); 72 | } 73 | ``` 74 | 75 | 76 | `cargo run` will execute the `main` function and return the result (if there is one). 77 | -------------------------------------------------------------------------------- /.github/workflows/scheduled-stale-check.yaml: -------------------------------------------------------------------------------- 1 | # ---------------------------------------- 2 | # Scheduled stale issue & pull request check 3 | # 4 | # Adds 'stale' label after a set piece of time, 5 | # then closes stale issues & pull requests a short period after 6 | # 7 | # Using "Close Stale Issues" action 8 | # https://github.com/marketplace/actions/close-stale-issues 9 | # ---------------------------------------- 10 | 11 | name: 'Scheduled stale check' 12 | on: 13 | workflow_dispatch: 14 | schedule: 15 | - cron: "0 1 1 * *" # at 01:00 on first day of month 16 | 17 | jobs: 18 | stale: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - run: echo "🚀 Job automatically triggered by ${{ github.event_name }}" 22 | - run: echo "🐧 Job running on ${{ runner.os }} server" 23 | - run: echo "🐙 Using ${{ github.ref }} branch from ${{ github.repository }} repository" 24 | 25 | - uses: actions/stale@v10 26 | with: 27 | stale-issue-message: 'After 30 days with no activity, the issue was automatically marked stale. Remove stale label or add a comment to prevent the issue being closed in 5 days.' 28 | stale-pr-message: 'After 45 days with no activity, the Pull Request was automatically marked stale. Remove stale label or comment to prevent the PR being closed in 10 days.' 29 | close-issue-message: 'This issue was closed because it has been stalled for 5 days with no activity.' 30 | close-pr-message: 'This PR was closed because it has been stalled for 10 days with no activity.' 31 | days-before-issue-stale: 30 32 | days-before-pr-stale: 45 33 | days-before-issue-close: 5 34 | days-before-pr-close: 10 35 | start-date: '2025-04-05T00:00:00Z' # only affect issues/PRs from date created (ISO 8601 or RFC 2822 format) 36 | any-of-labels: 'future,keep' # labels to keep 37 | exempt-issue-assignees: 'practicalli-johnny' 38 | exempt-pr-assignees: 'practicalli-johnny' 39 | 40 | # Summary 41 | - run: echo "🎨 Issues & Pull Request checked with actions/stale" 42 | - run: echo "🍏 Job status is ${{ job.status }}." 43 | -------------------------------------------------------------------------------- /docs/introduction/features.md: -------------------------------------------------------------------------------- 1 | # Rust Features 2 | 3 | Rust is a programming language built to be fast, secure and reliable. 4 | 5 | Rust is a statically and strongly typed systems programming language. 6 | 7 | Statically typed means all types are known at compile-time. Strongly typed means types are designed to make it harder to write incorrect programs. 8 | 9 | A successful compilation provides a high guarantee of correctness. 10 | 11 | Rust is safe by default; all memory accesses are checked. It is not possible to corrupt memory by accident. 12 | 13 | The unifying principles behind Rust are: 14 | 15 | - strictly enforcing safe borrowing of data 16 | - functions, methods and closures to operate on data 17 | - tuples, structs and enums to aggregate data 18 | - pattern matching to select and destructure data 19 | - traits to define behaviour on data 20 | 21 | There is a fast-growing ecosystem of available libraries through Cargo to complement the standard library. 22 | 23 | 24 | ## Run without Crash 25 | 26 | Code should run without crashing, from the very first time it is run 27 | 28 | Rust is a statically typed language and leaves almost no room for errors that would cause a program to crash. 29 | 30 | ## Fast runtime execution 31 | 32 | Rust is extremely fast when it comes to execution time. 33 | 34 | 35 | 36 | Zero-cost abstractions — 37 | 38 | Rust code is compiled into Assembly using the LLVM back-end (also used by C). 39 | 40 | Programming features like Generics and Collections do not come with runtime cost; it will only be slower to compile. (Source: stackoverflow). 41 | 42 | 43 | Builds optimized code for Generics 44 | 45 | Rust’s compiler can smartly identify the generic code and optimize for each specific type 46 | 47 | 48 | ## Compilation Errors 49 | 50 | Rust’s compiler gives excellent feedback in its error messages. 51 | 52 | The compiler may offer example code that can be used to resolve an error. 53 | 54 | 55 | ## Documentation 56 | 57 | Rust has an amazing documentation and a tutorial guide called The Rust Book. 58 | 59 | 60 | ## Areas of use 61 | 62 | - Server-side and other backend applications 63 | - Cloud computing applications, services, and infrastructure 64 | - Distributed systems 65 | - Computer networking 66 | - Computer security 67 | - Embedded development 68 | - Game development 69 | - Web frontends (including WebAssembly) 70 | -------------------------------------------------------------------------------- /.github/workflows/megalinter.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | # MegaLinter GitHub Action configuration file 3 | # More info at https://megalinter.io 4 | # All variables described in https://megalinter.io/latest/configuration/ 5 | 6 | name: MegaLinter 7 | on: 8 | workflow_dispatch: 9 | pull_request: 10 | branches: [main] 11 | push: 12 | branches: [main] 13 | 14 | # Run Linters in parallel 15 | # Cancel running job if new job is triggered 16 | concurrency: 17 | group: "${{ github.ref }}-${{ github.workflow }}" 18 | cancel-in-progress: true 19 | 20 | jobs: 21 | megalinter: 22 | name: MegaLinter 23 | runs-on: ubuntu-latest 24 | steps: 25 | - run: echo "🚀 Job automatically triggered by ${{ github.event_name }}" 26 | - run: echo "🐧 Job running on ${{ runner.os }} server" 27 | - run: echo "🐙 Using ${{ github.ref }} branch from ${{ github.repository }} repository" 28 | 29 | # Git Checkout 30 | - name: Checkout Code 31 | uses: actions/checkout@v5 32 | with: 33 | fetch-depth: 0 34 | sparse-checkout: | 35 | docs 36 | overrides 37 | .github 38 | - run: echo "🐙 Sparse Checkout of ${{ github.repository }} repository to the CI runner." 39 | 40 | # MegaLinter Configuration 41 | - name: MegaLinter Run 42 | id: ml 43 | ## latest release of major version 44 | uses: oxsecurity/megalinter/flavors/documentation@v9 45 | env: 46 | # ADD CUSTOM ENV VARIABLES OR DEFINE IN MEGALINTER_CONFIG file 47 | MEGALINTER_CONFIG: .github/config/megalinter.yaml 48 | 49 | GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" # report individual linter status 50 | # Validate all source when push on main, else just the git diff with live. 51 | VALIDATE_ALL_CODEBASE: >- 52 | ${{ github.event_name == 'push' && github.ref == 'refs/heads/main'}} 53 | 54 | # Upload MegaLinter artifacts 55 | - name: Archive production artifacts 56 | if: ${{ success() }} || ${{ failure() }} 57 | uses: actions/upload-artifact@v4 58 | with: 59 | name: MegaLinter reports 60 | path: | 61 | megalinter-reports 62 | mega-linter.log 63 | 64 | # Summary and status 65 | - run: echo "🎨 MegaLinter quality checks completed" 66 | - run: echo "🍏 Job status is ${{ job.status }}." 67 | -------------------------------------------------------------------------------- /overrides/partials/header.html: -------------------------------------------------------------------------------- 1 | 2 | {% set class = "md-header" %} {% if "navigation.tabs.sticky" in features %} {% 3 | set class = class ~ " md-header--shadow md-header--lifted" %} {% elif 4 | "navigation.tabs" not in features %} {% set class = class ~ " md-header--shadow" 5 | %} {% endif %} 6 | 7 | 8 |
9 | 74 | 75 | 76 | {% if "navigation.tabs.sticky" in features %} {% if "navigation.tabs" in 77 | features %} {% include "partials/tabs.html" %} {% endif %} {% endif %} 78 |
79 | -------------------------------------------------------------------------------- /docs/reference/books.md: -------------------------------------------------------------------------------- 1 | # Rust Books 2 | 3 | [Learn Rust](https://www.rust-lang.org/learn) aka 'The Rust Book'. 4 | 5 | 6 | [Idioomatic Rust](https://learning.oreilly.com/library/view/idiomatic-rust/9781633437463/) covers design patterns for using rust effectively (video edition - author reading book) 7 | 8 | 9 | 34 | 35 | 36 | ## Video 37 | 38 | 56 | -------------------------------------------------------------------------------- /docs/projects/guides/rest-api.md: -------------------------------------------------------------------------------- 1 | # Rest API with Swagger UI 2 | 3 | Create an API service that provides a documented and interactive API using Open API. 4 | 5 | [Axum]() is the web framework, supported by [Tokio]() async runtime and [Serde]() for JSON serialisation. 6 | 7 | ??? INFO "Background references" 8 | [What is a runtime in Rust](https://kerkour.com/rust-async-await-what-is-a-runtime) 9 | 10 | [How to implement an async main function](https://users.rust-lang.org/t/how-to-implement-async-await-in-main/38007) 11 | 12 | > NOTE: other web frameworks include [Rocket](), [Warp](), [Actix]() 13 | 14 | 15 | ## Create project 16 | 17 | Create a basic project using the Cargo tool. 18 | 19 | !!! NOTE "" 20 | ```shell 21 | cargo new hello-world --bin 22 | ``` 23 | 24 | 25 | 26 | ??? EXAMPLE "Project configuration file" 27 | ```toml 28 | [package] 29 | name = "hello-world" 30 | version = "0.1.0" 31 | edition = "2024" 32 | 33 | [dependencies] 34 | ``` 35 | 36 | 37 | 38 | 39 | ## Dependencies 40 | 41 | 42 | !!! NOTE "" 43 | Add library dependencies for Axium and other useful libraries 44 | ```toml title="Cargo.toml" 45 | [dependencies] 46 | axum = "0.8" 47 | tokio = { version = "1.22.0", features = ["full"] } 48 | serde = { version = "1.0.149", features = ["derive"] } 49 | ``` 50 | 51 | 52 | 53 | 54 | !!! INFO "Updating Crates" 55 | LSP / Rustaceannvim will automatically detect newer versions of creates available. 56 | 57 | `SPC l a` to select the "Update creates" code action. Or select "Update all creates" action if there are multiple creates with newer versions. 58 | 59 | 60 | ## Create a web server 61 | 62 | Use the Rust standard library to define IP address for the web server and manage errors. 63 | 64 | Use axum to define a router and routes to handle requests. 65 | 66 | 67 | !!! NOTE "" 68 | Edit the `src/main.rs` and replace the existing code 69 | 70 | ```rust 71 | use std::{error::Error, net::SocketAddr}; 72 | 73 | use axum::{ 74 | routing::get, 75 | Router, 76 | }; 77 | 78 | #[tokio::main] 79 | async fn main() -> Result<(), Box> { 80 | let addr = SocketAddr::from(([127, 0, 0, 1], 8000)); 81 | 82 | let app = Router::new().route("/", get(|| async { "Hello, Axum" })); 83 | 84 | println!("listening on {}", addr); 85 | 86 | axum::Server::bind(&addr) 87 | .serve(app.into_make_service()) 88 | .await 89 | .unwrap(); 90 | 91 | Ok(()) 92 | } 93 | ``` 94 | 95 | ## Run and test web server 96 | 97 | Start the Rust project in watch mode, so changes are automatically updated on save. 98 | 99 | !!! NOTE "Install Bacon" 100 | ```shell 101 | cargo install --locked bacon 102 | ``` 103 | 104 | > NOTE: bacon has a long list of crate library dependencies... downloading the internet! 105 | 106 | 107 | !!! NOTE "" 108 | ```shell 109 | cargo run 110 | ``` 111 | 112 | 113 | ??? INFO "Bacon is the new cargo watch" 114 | [Cargo-watch is no longer maintained](https://crates.io/crates/cargo-watch), recommends [bacon](https://dystroy.org/bacon/) the background code checker instead. 115 | -------------------------------------------------------------------------------- /.github/config/megalinter.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | # Configuration file for MegaLinter 3 | # 4 | # General configuration: 5 | # https://megalinter.io/latest/configuration/ 6 | # 7 | # Specific Linters: 8 | # https://megalinter.io/latest/supported-linters/ 9 | 10 | # ------------------------ 11 | # Validate all files if true 12 | # or new / edited files if false 13 | VALIDATE_ALL_CODEBASE: false 14 | 15 | # ------------------------ 16 | # Linters 17 | 18 | # Run linters in parallel 19 | PARALLEL: true 20 | 21 | # ENABLE specific linters, all other linters automatically disabled 22 | ENABLE: 23 | # - CLOJURE 24 | - CREDENTIALS 25 | - DOCKERFILE 26 | - MAKEFILE 27 | - MARKDOWN 28 | - GIT 29 | - SPELL 30 | - YAML 31 | - REPOSITORY 32 | 33 | # Linter specific configuration 34 | 35 | # CLOJURE_CLJ_KONDO_CONFIG_FILE: ".github/config/clj-kondo-ci-config.edn" 36 | # CLOJURE_CLJ_KONDO_ARGUMENTS: "--lint deps.edn" 37 | # CLOJURE_CLJ_KONDO_FILTER_REGEX_EXCLUDE: "dev|develop" 38 | # CLOJURE_CLJ_KONDO_FILTER_REGEX_EXCLUDE: "resources" 39 | 40 | # CREDENTIALS_SECRETLINT_DISABLE_ERRORS: true 41 | CREDENTIALS_SECRETLINT_CONFIG_FILE: ".github/config/secretlintrc.json" 42 | 43 | MARKDOWN_MARKDOWNLINT_CONFIG_FILE: ".github/config/markdown-lint.jsonc" 44 | MARKDOWN_MARKDOWNLINT_FILTER_REGEX_EXCLUDE: ".github/pull_request_template.md|CHANGELOG.md|README.md|GLOSSARY.md|java-17-flags.md|abbreviations.md" 45 | # MARKDOWN_MARKDOWNLINT_DISABLE_ERRORS: true 46 | MARKDOWN_MARKDOWN_LINK_CHECK_CONFIG_FILE: ".github/config/markdown-link-check.json" 47 | # MARKDOWN_MARKDOWN_LINK_CHECK_CLI_LINT_MODE: "project" 48 | # MARKDOWN_MARKDOWN_LINK_CHECK_DISABLE_ERRORS: false 49 | MARKDOWN_REMARK_LINT_DISABLE_ERRORS: true 50 | # MARKDOWN_MARKDOWN_TABLE_FORMATTER_DISABLE_ERRORS: false 51 | 52 | REPOSITORY_GITLEAKS_CONFIG_FILE: ".github/config/gitleaks.toml" 53 | REPOSITORY_TRUFFLEHOG_DISABLE_ERRORS: true # Errors only as warnings 54 | 55 | # SPELL_CSPELL_DISABLE_ERRORS: true 56 | SPELL_MISSPELL_DISABLE_ERRORS: true 57 | SPELL_LYCHEE_CONFIG_FILE: ".github/config/lychee.toml" 58 | SPELL_LYCHEE_DISABLE_ERRORS: true # Errors are only warnings 59 | 60 | # YAML_PRETTIER_FILTER_REGEX_EXCLUDE: (docs/) 61 | # YAML_YAMLLINT_FILTER_REGEX_EXCLUDE: (docs/) 62 | 63 | # Explicitly disable linters to ensure they are never run 64 | # DISABLE: 65 | # - COPYPASTE # checks for excessive copy-pastes 66 | # - SPELL # spell checking - often creates many false positives 67 | # - CSS # 68 | 69 | # Disable linter features 70 | DISABLE_LINTERS: 71 | - YAML_PRETTIER # draconian format rules 72 | - SPELL_CSPELL # many clojure references causing false positives 73 | - YAML_YAMLLINT # vague error mesages, investigation required 74 | - REPOSITORY_GIT_DIFF # warnings about LF to CRLF 75 | - REPOSITORY_SECRETLINT # reporting errors in its own config file 76 | # - REPOSITORY_DEVSKIM # unnecessary URL TLS checks 77 | - REPOSITORY_CHECKOV # fails on root user in Dockerfile 78 | - REPOSITORY_SECRETLINT 79 | 80 | # Ignore all errors and return without error status 81 | # DISABLE_ERRORS: true 82 | 83 | # ------------------------ 84 | 85 | # ------------------------ 86 | # Reporting 87 | 88 | # Activate sources reporter 89 | UPDATED_SOURCES_REPORTER: false 90 | 91 | # Show Linter timings in summary table at end of run 92 | SHOW_ELAPSED_TIME: true 93 | 94 | # Upload reports to file.io 95 | FILEIO_REPORTER: false 96 | # ------------------------ 97 | 98 | # ------------------------ 99 | # Over-ride errors 100 | 101 | # detect errors but do not block CI passing 102 | # DISABLE_ERRORS: true 103 | # ------------------------ 104 | -------------------------------------------------------------------------------- /docs/assets/stylesheets/extra.css: -------------------------------------------------------------------------------- 1 | [data-md-color-scheme="default"] { 2 | --md-default-bg-color: hsla(208, 100%, 96%, 0.94); 3 | --md-code-bg-color: hsla(208, 80%, 88%, 0.64); 4 | --md-code-hl-color: hsla(208, 88%, 80%, 0.92); 5 | --md-admonition-bg-color: hsla(208, 80%, 92%, 0.92); 6 | --md-typeset-kbd-color: hsla(208, 100%, 98%, 0.98); 7 | } 8 | 9 | /* Custom Admonitions */ 10 | 11 | 12 | :root { 13 | /* Clojure Idiom*/ 14 | --md-admonition-icon--clojure-idiom: url(https://raw.githubusercontent.com/practicalli/graphic-design/c40cc063cc5bb07525b524d8a3d638e2f42bc38a/logos/clojure-logo-bullet.svg); 15 | 16 | /* Round corners */ 17 | --base-border-radius: 0.5rem; 18 | } 19 | 20 | /*Admonitions colors*/ 21 | .md-typeset .admonition.clojure-idiom, 22 | .md-typeset details.clojure-idiom { 23 | border-color: rgb(43, 155, 70); 24 | } 25 | .md-typeset .clojure-idiom > .admonition-title, 26 | .md-typeset .clojure-idiom > summary { 27 | background-color: rgba(43, 155, 70, 0.1); 28 | } 29 | .md-typeset .clojure-idiom > .admonition-title::before, 30 | .md-typeset .clojure-idiom > summary::before { 31 | background-color: rgb(250, 250, 250); 32 | background-image: var(--md-admonition-icon--clojure-idiom); 33 | -webkit-mask-image: var(--md-admonition-icon--clojure-idiom); 34 | mask-image: var(--md-admonition-icon--clojure-idiom); 35 | } 36 | 37 | 38 | /* Change font family of filename present on top of code block. */ 39 | .highlight span.filename { 40 | border-bottom: none; 41 | border-radius: var(--base-border-radius); 42 | display: inline; 43 | font-family: var(--md-code-font-family); 44 | border-bottom-left-radius: 0; 45 | border-bottom-right-radius: 0; 46 | margin-bottom: 5px; 47 | text-align: center; 48 | } 49 | .highlight span.filename + pre > code { 50 | border-radius: var(--base-border-radius); 51 | border-top-left-radius: 0; 52 | } 53 | .md-typeset pre > code { 54 | border-radius: var(--base-border-radius); 55 | } 56 | 57 | /* Grid Cards */ 58 | .md-typeset .grid.cards > ul > li { 59 | border-radius: var(--base-border-radius); 60 | } 61 | .md-typeset .grid.cards > ul > li:hover { 62 | box-shadow: 0 0 0.2rem #ffffff40; 63 | } 64 | 65 | /* Markdown Button */ 66 | .md-typeset .md-button { 67 | border-radius: var(--base-border-radius); 68 | } 69 | 70 | /* Critic, Mark */ 71 | ins.critic, 72 | del.critic { 73 | text-decoration: none; 74 | } 75 | 76 | .md-typeset .critic, 77 | .md-typeset mark { 78 | border-radius: 0.2rem; 79 | padding: 0 0.2rem; 80 | } 81 | 82 | .md-typeset mark { 83 | box-shadow: 0 0 0 0.1rem var(--md-typeset-mark-color); 84 | } 85 | 86 | .md-typeset ins.critic { 87 | box-shadow: 0 0 0 0.1rem var(--md-typeset-ins-color); 88 | } 89 | 90 | .md-typeset del.critic { 91 | box-shadow: 0 0 0 0.1rem var(--md-typeset-del-color); 92 | } 93 | 94 | /* Forms */ 95 | .md-search__form { 96 | border-radius: var(--base-border-radius); 97 | } 98 | 99 | [data-md-toggle="search"]:checked ~ .md-header .md-search__form { 100 | border-top-right-radius: var(--base-border-radius); 101 | border-top-left-radius: var(--base-border-radius); 102 | } 103 | 104 | [dir="ltr"] .md-search__output { 105 | border-bottom-right-radius: var(--base-border-radius); 106 | border-bottom-left-radius: var(--base-border-radius); 107 | } 108 | 109 | /* Blog - index.md */ 110 | .md-post--excerpt { 111 | background-color: var(--md-accent-fg-color--transparent); 112 | box-shadow: 0 0 0 1rem var(--md-accent-fg-color--transparent); 113 | border-radius: var(--base-border-radius); 114 | } 115 | 116 | /* Table */ 117 | .md-typeset table:not([class]) { 118 | border-radius: var(--base-border-radius); 119 | } 120 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # -------------------------------------- # 2 | # Practicalli Makefile 3 | # 4 | # Consistent set of targets to support local book development 5 | # -------------------------------------- # 6 | 7 | # -- Makefile task config -------------- # 8 | # .PHONY: ensures target used rather than matching file name 9 | # https://makefiletutorial.com/#phony 10 | .PHONY: all clean docs lint pre-commit-check test 11 | # -------------------------------------- # 12 | 13 | # -- Makefile Variables ---------------- # 14 | # run help if no target specified 15 | .DEFAULT_GOAL := help 16 | # Column the target description is printed from 17 | HELP-DESCRIPTION-SPACING := 24 18 | 19 | SHELL := /usr/bin/zsh 20 | 21 | # Tool Commands 22 | MEGALINTER_RUNNER := npx mega-linter-runner --flavor documentation --env "'MEGALINTER_CONFIG=.github/config/megalinter.yaml'" --env "'VALIDATE_ALL_CODEBASE=true'" --remove-container 23 | MKDOCS_SERVER := mkdocs serve --dev-addr localhost:7777 24 | OUTDATED_FILE := outdated-$(shell date +%y-%m-%d-%T).md 25 | # -------------------------------------- # 26 | 27 | # -- Quality Checks ------------------ # 28 | pre-commit-check: lint 29 | 30 | lint: ## Run MegaLinter with custom configuration (node.js required) 31 | $(info -- MegaLinter Runner ---------------------) 32 | $(MEGALINTER_RUNNER) 33 | 34 | lint-fix: ## Run MegaLinter with applied fixes and custom configuration (node.js required) 35 | $(info -- MegaLinter Runner fix errors ----------) 36 | $(MEGALINTER_RUNNER) --fix 37 | 38 | lint-clean: ## Clean MegaLinter report information 39 | $(info -- MegaLinter Clean Reports --------------) 40 | - rm -rf ./megalinter-reports 41 | 42 | megalinter-upgrade: ## Upgrade MegaLinter config to latest version 43 | $(info -- MegaLinter Upgrade Config -------------) 44 | npx mega-linter-runner@latest --upgrade 45 | 46 | dependencies-outdated: ## Report new versions of library dependencies and GitHub action 47 | $(info -- Search for outdated libraries ---------) 48 | - clojure -T:search/outdated > $(OUTDATED_FILE) 49 | 50 | dependencies-update: ## Update all library dependencies and GitHub action 51 | $(info -- Search for outdated libraries ---------) 52 | - clojure -T:update/dependency-versions > $(OUTDATED_FILE) 53 | # -------------------------------------- # 54 | 55 | # --- Documentation Generation -------- # 56 | python-venv: ## Create Python Virtual Environment 57 | $(info -- Create Python Virtual Environment -----) 58 | python3 -m venv ~/.local/venv 59 | 60 | python-activate: ## Activate Python Virtual Environment for MkDocs 61 | $(info -- Mkdocs Local Server -------------------) 62 | source ~/.local/venv/bin/activate 63 | 64 | mkdocs-install: 65 | $(info -- Install Material for MkDocs -----------) 66 | source ~/.local/venv/bin/activate && pip install mkdocs-material mkdocs-callouts mkdocs-glightbox mkdocs-git-revision-date-localized-plugin mkdocs-redirects mkdocs-rss-plugin pillow cairosvg --upgrade 67 | 68 | docs: ## Build and run mkdocs in local server (python venv) 69 | $(info -- MkDocs Local Server -------------------) 70 | source ~/.local/venv/bin/activate && $(MKDOCS_SERVER) 71 | 72 | docs-changed: ## Build only changed files and run mkdocs in local server (python venv) 73 | $(info -- Mkdocs Local Server -------------------) 74 | source ~/.local/venv/bin/activate && $(MKDOCS_SERVER) --dirtyreload 75 | 76 | docs-build: ## Build mkdocs (python venv) 77 | $(info -- Mkdocs Build Website ------------------) 78 | source ~/.local/venv/bin/activate && mkdocs build 79 | 80 | docs-debug: ## Run mkdocs local server in debug mode (python venv) 81 | $(info -- Mkdocs Local Server Debug -------------) 82 | . ~/.local/venv/bin/activate; $(MKDOCS_SERVER) -v 83 | 84 | docs-staging: ## Deploy to staging repository 85 | $(info -- Mkdocs Staging Deploy -----------------) 86 | source ~/.local/venv/bin/activate && mkdocs gh-deploy --force --no-history --config-file mkdocs-staging.yml 87 | # -------------------------------------- # 88 | 89 | # ------- Version Control -------------- # 90 | git-sr: ## status list of git repos under current directory 91 | $(info -- Multiple Git Repo Status --------------) 92 | mgitstatus -e --flatten 93 | 94 | git-status: ## status details of git repos under current directory 95 | $(info -- Multiple Git Status -------------------) 96 | mgitstatus 97 | # -------------------------------------- # 98 | 99 | # ------------ Help -------------------- # 100 | # Source: https://nedbatchelder.com/blog/201804/makefile_help_target.html 101 | 102 | help: ## Describe available tasks in Makefile 103 | @grep '^[a-zA-Z]' $(MAKEFILE_LIST) | \ 104 | sort | \ 105 | awk -F ':.*?## ' 'NF==2 {printf "\033[36m %-$(HELP-DESCRIPTION-SPACING)s\033[0m %s\n", $$1, $$2}' 106 | # -------------------------------------- # 107 | 108 | dist: deps-build ## Build mkdocs website 109 | -------------------------------------------------------------------------------- /docs/assets/favicon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | image/svg+xml 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | I 19 | P 20 | 9 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /docs/assets/stylesheets/practicalli-light.css: -------------------------------------------------------------------------------- 1 | // ---------------------------------------------------------------------------- 2 | // Rules 3 | // ---------------------------------------------------------------------------- 4 | 5 | // Color variables 6 | :root { 7 | @extend %root; 8 | 9 | // Primary color shades 10 | --md-primary-fg-color: hsla(#{hex2hsl($clr-indigo-500)}, 1); 11 | --md-primary-fg-color--light: hsla(#{hex2hsl($clr-indigo-400)}, 1); 12 | --md-primary-fg-color--dark: hsla(#{hex2hsl($clr-indigo-700)}, 1); 13 | --md-primary-bg-color: hsla(0, 0%, 100%, 1); 14 | --md-primary-bg-color--light: hsla(0, 0%, 100%, 0.7); 15 | 16 | // Accent color shades 17 | --md-accent-fg-color: hsla(#{hex2hsl($clr-indigo-a200)}, 1); 18 | --md-accent-fg-color--transparent: hsla(#{hex2hsl($clr-indigo-a200)}, 0.1); 19 | --md-accent-bg-color: hsla(0, 0%, 100%, 1); 20 | --md-accent-bg-color--light: hsla(0, 0%, 100%, 0.7); 21 | } 22 | 23 | // ---------------------------------------------------------------------------- 24 | 25 | // Allow to explicitly use color schemes in nested content 26 | [data-md-color-scheme="practicalli"] { 27 | @extend %root; 28 | } 29 | 30 | // ---------------------------------------------------------------------------- 31 | // Placeholders 32 | // ---------------------------------------------------------------------------- 33 | 34 | // Default theme, i.e. light mode 35 | %root { 36 | 37 | // Default color shades 38 | --md-default-fg-color: hsla(0, 0%, 0%, 0.87); 39 | --md-default-fg-color--light: hsla(0, 0%, 0%, 0.54); 40 | --md-default-fg-color--lighter: hsla(0, 0%, 0%, 0.32); 41 | --md-default-fg-color--lightest: hsla(0, 0%, 0%, 0.07); 42 | --md-default-bg-color: hsla(53, 90%, 90%, 1); 43 | --md-default-bg-color--light: hsla(53, 90%, 90%, 0.7); 44 | --md-default-bg-color--lighter: hsla(53, 90%, 90%, 0.3); 45 | --md-default-bg-color--lightest: hsla(53, 90%, 90%, 0.12); 46 | 47 | // Code color shades 48 | --md-code-fg-color: hsla(200, 18%, 26%, 1); 49 | --md-code-bg-color: hsla(0, 0%, 96%, 1); 50 | 51 | // Code highlighting color shades 52 | --md-code-hl-color: hsla(#{hex2hsl($clr-yellow-a200)}, 0.5); 53 | --md-code-hl-number-color: hsla(0, 67%, 50%, 1); 54 | --md-code-hl-special-color: hsla(340, 83%, 47%, 1); 55 | --md-code-hl-function-color: hsla(291, 45%, 50%, 1); 56 | --md-code-hl-constant-color: hsla(250, 63%, 60%, 1); 57 | --md-code-hl-keyword-color: hsla(219, 54%, 51%, 1); 58 | --md-code-hl-string-color: hsla(150, 63%, 30%, 1); 59 | --md-code-hl-name-color: var(--md-code-fg-color); 60 | --md-code-hl-operator-color: var(--md-default-fg-color--light); 61 | --md-code-hl-punctuation-color: var(--md-default-fg-color--light); 62 | --md-code-hl-comment-color: var(--md-default-fg-color--light); 63 | --md-code-hl-generic-color: var(--md-default-fg-color--light); 64 | --md-code-hl-variable-color: var(--md-default-fg-color--light); 65 | 66 | // Typeset color shades 67 | --md-typeset-color: var(--md-default-fg-color); 68 | 69 | // Typeset `a` color shades 70 | --md-typeset-a-color: var(--md-primary-fg-color); 71 | 72 | // Typeset `mark` color shades 73 | --md-typeset-mark-color: hsla(#{hex2hsl($clr-yellow-a200)}, 0.5); 74 | 75 | // Typeset `del` and `ins` color shades 76 | --md-typeset-del-color: hsla(6, 90%, 60%, 0.15); 77 | --md-typeset-ins-color: hsla(150, 90%, 44%, 0.15); 78 | 79 | // Typeset `kbd` color shades 80 | --md-typeset-kbd-color: hsla(0, 0%, 98%, 1); 81 | --md-typeset-kbd-accent-color: hsla(0, 100%, 100%, 1); 82 | --md-typeset-kbd-border-color: hsla(0, 0%, 72%, 1); 83 | 84 | // Typeset `table` color shades 85 | --md-typeset-table-color: hsla(0, 0%, 0%, 0.12); 86 | 87 | // Admonition color shades 88 | --md-admonition-fg-color: var(--md-default-fg-color); 89 | --md-admonition-bg-color: var(--md-default-bg-color); 90 | 91 | // Footer color shades 92 | --md-footer-fg-color: hsla(0, 0%, 100%, 1); 93 | --md-footer-fg-color--light: hsla(0, 0%, 100%, 0.7); 94 | --md-footer-fg-color--lighter: hsla(0, 0%, 100%, 0.3); 95 | --md-footer-bg-color: hsla(0, 0%, 0%, 0.87); 96 | --md-footer-bg-color--dark: hsla(0, 0%, 0%, 0.32); 97 | 98 | // Shadow depth 1 99 | --md-shadow-z1: 100 | 0 #{px2rem(4px)} #{px2rem(10px)} hsla(0, 0%, 0%, 0.05), 101 | 0 0 #{px2rem(1px)} hsla(0, 0%, 0%, 0.1); 102 | 103 | // Shadow depth 2 104 | --md-shadow-z2: 105 | 0 #{px2rem(4px)} #{px2rem(10px)} hsla(0, 0%, 0%, 0.1), 106 | 0 0 #{px2rem(1px)} hsla(0, 0%, 0%, 0.25); 107 | 108 | // Shadow depth 3 109 | --md-shadow-z3: 110 | 0 #{px2rem(4px)} #{px2rem(10px)} hsla(0, 0%, 0%, 0.2), 111 | 0 0 #{px2rem(1px)} hsla(0, 0%, 0%, 0.35); 112 | } 113 | -------------------------------------------------------------------------------- /docs/assets/practicalli-logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | image/svg+xml 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | I 31 | P 32 | 9 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /mkdocs.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # yaml-language-server: $schema=https://squidfunk.github.io/mkdocs-material/schema.json 3 | # Practicalli Rust 4 | site_name: Practicalli Rust 5 | site_url: https://practical.li/rust 6 | site_description: Practical guide to Rust programming language 7 | site_author: Practicalli 8 | site_org: https://practical.li/ 9 | copyright: Copyright © 2023 Practicali CC BY-SA 4.0 10 | repo_url: https://github.com/practicalli/rust/ 11 | edit_uri: https://github.com/practicalli/rust/edit/main/docs/ 12 | 13 | # Deployment 14 | # remote_name: origin 15 | remote_branch: gh-pages # deployment branch 16 | 17 | # Theme and styling 18 | theme: 19 | name: material 20 | logo: assets/images/practicalli-logo.png 21 | favicon: assets/favicon.svg 22 | features: 23 | - announce.dismiss 24 | - content.action.edit 25 | - content.action.view 26 | - content.code.annotate 27 | - content.code.copy 28 | - content.tabs.link 29 | - navigation.footer 30 | - navigation.indexes # Nav sections can have files 31 | - navigation.instant # Avoid page reloading for internal links 32 | - navigation.top 33 | - navigation.tracking # Update URL with sub-heading anchor names 34 | palette: 35 | # Palette toggle for automatic mode 36 | - media: "(prefers-color-scheme)" 37 | toggle: 38 | icon: material/brightness-auto 39 | name: Switch to light mode 40 | # Palette toggle for light mode 41 | - media: "(prefers-color-scheme: light)" 42 | scheme: default 43 | primary: deep-purple 44 | accent: purple 45 | toggle: 46 | icon: material/weather-sunny 47 | name: Switch to dark mode 48 | # Palette toggle for dark mode 49 | - media: "(prefers-color-scheme: dark)" 50 | scheme: slate 51 | primary: deep-purple 52 | accent: indigo 53 | toggle: 54 | icon: material/weather-night 55 | name: Switch to light mode 56 | # Override theme 57 | custom_dir: overrides 58 | 59 | extra_css: 60 | - assets/stylesheets/extra.css 61 | 62 | ## Additional styling 63 | markdown_extensions: 64 | - admonition 65 | - pymdownx.details 66 | - pymdownx.superfences 67 | - attr_list 68 | - md_in_html # Grids 69 | - footnotes # footnotes and abbreviations 70 | - pymdownx.emoji: 71 | emoji_index: !!python/name:material.extensions.emoji.twemoji 72 | emoji_generator: !!python/name:material.extensions.emoji.to_svg 73 | - pymdownx.highlight: 74 | anchor_linenums: true 75 | - pymdownx.inlinehilite 76 | - pymdownx.snippets: 77 | url_download: true 78 | - pymdownx.superfences: 79 | custom_fences: 80 | - name: mermaid 81 | class: mermaid 82 | format: !!python/name:pymdownx.superfences.fence_code_format 83 | - pymdownx.tabbed: 84 | alternate_style: true 85 | - pymdownx.keys # keyboard keys 86 | - pymdownx.magiclink 87 | - def_list # lists 88 | - pymdownx.tasklist: 89 | custom_checkbox: true # checkboxes 90 | - toc: 91 | permalink: λ︎ 92 | 93 | ## Plugins 94 | plugins: 95 | # Explicitly add search plugin when defining plugins in this configuration file 96 | - search 97 | - callouts 98 | - glightbox # Image aligning 99 | - git-revision-date-localized: # Update and Creation date of each page 100 | # enable_creation_date: true 101 | fallback_to_build_date: true 102 | 103 | # Generate Social Cards via CI only 104 | # in assets/images/social 105 | - social: 106 | cards: !ENV [MKDOCS_SOCIAL_CARDS_GENERATE, true] 107 | 108 | # Redirect pages when moved or changed 109 | # - redirects: 110 | # redirect_maps: 111 | # repl-driven-development.md: introduction/repl-workflow.md 112 | 113 | # Footer / Social Media 114 | extra: 115 | analytics: 116 | provider: google 117 | property: G-QZ22Z9DH4T 118 | social: 119 | - icon: material/web 120 | link: https://practical.li/ 121 | - icon: fontawesome/brands/linkedin 122 | link: https://www.linkedin.com/in/jr0cket/ 123 | - icon: fontawesome/brands/slack 124 | link: https://clojurians.slack.com/messages/practicalli 125 | - icon: fontawesome/brands/twitter 126 | link: https://twitter.com/practical_li 127 | - icon: fontawesome/brands/github 128 | link: https://github.com/practicalli 129 | - icon: fontawesome/brands/docker 130 | link: https://hub.docker.com/u/practicalli 131 | 132 | # Navigation 133 | nav: 134 | - Introduction: 135 | - index.md 136 | - Rust in Fifteen Mins: introduction/rust-in-15-minutes.md 137 | - Rust Workflow: introduction/rust-workflow.md 138 | - Functional Concepts: introduction/functional-concepts.md 139 | - Contributing: https://practical.li/contributing/ 140 | - Writing Tips: https://practical.li/writing-tips/ 141 | - Install: 142 | - install/index.md 143 | - Editors: 144 | - editors/index.md 145 | - editors/neovim.md 146 | - Rust Projects: 147 | - projects/index.md 148 | - Guides: 149 | - projects/guides/index.md 150 | - Rest API: projects/guides/rest-api.md 151 | - Code Challenges: 152 | - coding-challenges/index.md 153 | - Exercism: 154 | - coding-challenges/exercism/index.md 155 | - RNA Transcription: coding-challenges/exercism/rna-transcription.md 156 | - Nucleotide Count: coding-challenges/exercism/nucleotide-count.md 157 | - coding-challenges/exercism/hamming.md 158 | - coding-challenges/exercism/space-age.md 159 | - TDD Kata: 160 | - simple-projects/tdd-kata/index.md 161 | - Recent Song list: simple-projects/tdd-kata/recent-song-list.md 162 | - Salary Slip Generator: simple-projects/tdd-kata/salary-slip-generator.md 163 | # - simple-projects/split-the-bill.md 164 | - Games: 165 | - games/index.md 166 | - TicTacToe: 167 | - games/tictactoe-cli/index.md 168 | 169 | - Testing: 170 | - testing/index.md 171 | - Unit Testing: 172 | - testing/unit-testing/index.md 173 | - Writing Tests: testing/unit-testing/writing-unit-tests.md 174 | - Fixtures: testing/unit-testing/fixtures.md 175 | - Test Selectors: testing/unit-testing/test-selectors.md 176 | - Test runners: 177 | - testing/test-runners/index.md 178 | - Continuous Integration: 179 | - continuous-integration/index.md 180 | - GitHub Workflow: 181 | - continuous-integration/github-workflow/index.md 182 | 183 | - Reference: 184 | - reference/index.md 185 | - Books: reference/books.md 186 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Practicalli Rust 2 | 3 | ```none 4 | ██████╗ ██████╗ █████╗ ██████╗████████╗██╗ ██████╗ █████╗ ██╗ ██╗ ██╗ 5 | ██╔══██╗██╔══██╗██╔══██╗██╔════╝╚══██╔══╝██║██╔════╝██╔══██╗██║ ██║ ██║ 6 | ██████╔╝██████╔╝███████║██║ ██║ ██║██║ ███████║██║ ██║ ██║ 7 | ██╔═══╝ ██╔══██╗██╔══██║██║ ██║ ██║██║ ██╔══██║██║ ██║ ██║ 8 | ██║ ██║ ██║██║ ██║╚██████╗ ██║ ██║╚██████╗██║ ██║███████╗███████╗██║ 9 | ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ 10 | 11 | ██████╗ ██╗ ██╗███████╗████████╗ 12 | ██╔══██╗██║ ██║██╔════╝╚══██╔══╝ 13 | ██████╔╝██║ ██║███████╗ ██║ 14 | ██╔══██╗██║ ██║╚════██║ ██║ 15 | ██║ ██║╚██████╔╝███████║ ██║ 16 | ╚═╝ ╚═╝ ╚═════╝ ╚══════╝ ╚═╝ 17 | ``` 18 | 19 | > NOTE: Ascii Art Generator: https://patorjk.com/software/taag/#p=display&f=ANSI%20Shadow&t=Astro%205 20 | 21 | ## Book Overview 22 | 23 | A guide to software development with the Rust programming language and community tools to support an effective workflow. 24 | 25 | Learning Rust syntax and how to think in a functional design is also covered with code examples and challenge that help embed these concepts. 26 | 27 | 28 | ## Book status 29 | 30 | [![MegaLinter](https://github.com/practicalli/rust/actions/workflows/megalinter.yaml/badge.svg)](https://github.com/practicalli/rust/actions/workflows/megalinter.yaml)[![Publish Book](https://github.com/practicalli/rust/actions/workflows/publish-book.yaml/badge.svg)](https://github.com/practicalli/rust/actions/workflows/publish-book.yaml) 31 | [![Publish Book](https://github.com/practicalli/rust/actions/workflows/publish-book.yaml/badge.svg)](https://github.com/practicalli/rust/actions/workflows/publish-book.yaml) 32 | [![pages-build-deployment](https://github.com/practicalli/rust/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/practicalli/rust/actions/workflows/pages/pages-build-deployment) 33 | 34 | [![Ideas & Issues](https://img.shields.io/github/issues/practicalli/rust?label=content%20ideas%20and%20issues&logoColor=green&style=for-the-badge)](https://github.com/practicalli/rust/issues) 35 | [![Pull requests](https://img.shields.io/github/issues-pr/practicalli/rust?style=for-the-badge)](https://github.com/practicalli/rust/pulls) 36 | 37 | ![GitHub commit activity](https://img.shields.io/github/commit-activity/m/practicalli/rust?style=for-the-badge) 38 | ![GitHub contributors](https://img.shields.io/github/contributors/practicalli/rust?style=for-the-badge&label=github%20contributors) 39 | 40 | ## Creative commons license 41 | 42 |
43 | Creative Commons License 44 | This work is licensed under a Creative Commons Attribution 4.0 ShareAlike License (including images & stylesheets). 45 |
46 | 47 | ## Contributing 48 | 49 | Issues and pull requests are most welcome although it is the maintainers discression as to if they are applicable. Please detail issues as much as you can. Pull requests are simpler to work with when they are specific to a page or at most a section. The smaller the change the quicker it is to review and merge. 50 | 51 | Please read the [detailed Practicalli contributing page](https://practical.li/contributing/) before raising an issue or pull request to avoid disappointment. 52 | 53 | * [Current Issues](https://github.com/practicalli/rust/issues) 54 | * [Current pull requests](https://github.com/practicalli/rust/pulls) 55 | 56 | [Practicalli Clojure CLI Config](clojure/clojure-cli/practicalli-config.md) provides a user level configuration providing aliases for community tools used throughout this guide. Issues and pull requests can also be made via its GitHub repository. 57 | 58 | By submitting content ideas and corrections you are agreeing they can be used in any work by Practicalli under the [Creative Commons Attribution ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/). Attribution will be detailed via [GitHub contributors](https://github.com/practicalli/rust/graphs/contributors). 59 | 60 | ## Sponsor Practicalli 61 | 62 | [![Sponsor Practicalli via GitHub](https://raw.githubusercontent.com/practicalli/graphic-design/live/buttons/practicalli-github-sponsors-button.png)](https://github.com/sponsors/practicalli-johnny/) 63 | 64 | All sponsorship funds are used to support the continued development of [Practicalli series of books and videos](https://practical.li/), although most work is done at personal cost and time. 65 | 66 | Thanks to [Cognitect](https://www.cognitect.com/), [Nubank](https://nubank.com.br/) and a wide range of other [sponsors](https://github.com/sponsors/practicalli-johnny#sponsors) for your continued support 67 | 68 | 69 | ## Star History 70 | 71 | [![Star History Chart](https://api.star-history.com/svg?repos=practicalli/rust&type=Date)](https://star-history.com/#practicalli/rust&Date) 72 | 73 | 74 | ## GitHub Actions 75 | 76 | The megalinter GitHub actions will run when a pull request is created,checking basic markdown syntax. 77 | 78 | A review of the change will be carried out by the Practicalli team and the PR merged if the change is acceptable. 79 | 80 | The Publish Book GitHub action will run when PR's are merged into main (or the Practicalli team pushes changes to the default branch). 81 | 82 | Publish book workflow installs Material for MkDocs version 9 83 | 84 | 85 | ## Local development 86 | 87 | Install mkdocs version 9 using the Python pip package manager 88 | 89 | ```shell 90 | pip install mkdocs-material=="9.5" 91 | ``` 92 | 93 | Install the plugins used by the Practicalli site using Pip (these are also installed in the GitHub Action workflow) 94 | 95 | ```shell 96 | pip3 install mkdocs-material mkdocs-callouts mkdocs-glightbox mkdocs-git-revision-date-localized-plugin mkdocs-redirects pillow cairosvg 97 | ``` 98 | 99 | > pillow and cairosvg python packages are required for [Social Cards](https://squidfunk.github.io/mkdocs-material/setup/setting-up-social-cards/) 100 | 101 | Fork the GitHub repository and clone that fork to your computer, 102 | 103 | ```shell 104 | git clone https://github.com//.git 105 | ``` 106 | 107 | Run a local server from the root of the cloned project 108 | 109 | ```shell 110 | make docs 111 | ``` 112 | 113 | The website will open at 114 | 115 | If making smaller changes, then only rebuild the content that changes, speeding up the local development process 116 | 117 | ```shell 118 | make docs-changed 119 | ``` 120 | 121 | > NOTE: navigation changes may not be correctly reflected without reloading the page in the web browser or carrying out a full `make docs` build 122 | -------------------------------------------------------------------------------- /.github/config/markdown-lint.jsonc: -------------------------------------------------------------------------------- 1 | // Example markdownlint configuration with all properties set to their default value 2 | { 3 | 4 | // Default state for all rules 5 | "default": true, 6 | 7 | // Path to configuration file to extend 8 | "extends": null, 9 | 10 | // MD001/heading-increment/header-increment - Heading levels should only increment by one level at a time 11 | "MD001": true, 12 | 13 | // MD002/first-heading-h1/first-header-h1 - First heading should be a top-level heading 14 | "MD002": { 15 | // Heading level 16 | "level": 1 17 | }, 18 | 19 | // MD003/heading-style/header-style - Heading style 20 | "MD003": { 21 | // Heading style 22 | "style": "consistent" 23 | }, 24 | 25 | // MD004/ul-style - Unordered list style 26 | "MD004": { 27 | // List style 28 | "style": "consistent" 29 | }, 30 | 31 | // MD005/list-indent - Inconsistent indentation for list items at the same level 32 | "MD005": true, 33 | 34 | // MD006/ul-start-left - Consider starting bulleted lists at the beginning of the line 35 | "MD006": true, 36 | 37 | // MD007/ul-indent - Unordered list indentation 38 | "MD007": { 39 | // Spaces for indent 40 | "indent": 2, 41 | // Whether to indent the first level of the list 42 | "start_indented": false, 43 | // Spaces for first level indent (when start_indented is set) 44 | "start_indent": 2 45 | }, 46 | 47 | // MD009/no-trailing-spaces - Trailing spaces 48 | "MD009": { 49 | // Spaces for line break 50 | "br_spaces": 2, 51 | // Allow spaces for empty lines in list items 52 | "list_item_empty_lines": false, 53 | // Include unnecessary breaks 54 | "strict": true 55 | }, 56 | 57 | // MD010/no-hard-tabs - Hard tabs 58 | "MD010": { 59 | // Include code blocks 60 | "code_blocks": true, 61 | // Fenced code languages to ignore 62 | "ignore_code_languages": [], 63 | // Number of spaces for each hard tab 64 | "spaces_per_tab": 1 65 | }, 66 | 67 | // MD011/no-reversed-links - Reversed link syntax 68 | "MD011": true, 69 | 70 | // MD012/no-multiple-blanks - Multiple consecutive blank lines 71 | "MD012": { 72 | // Consecutive blank lines 73 | "maximum": 2 74 | }, 75 | 76 | // MD013/line-length - Line length 77 | "MD013": { 78 | // Number of characters 79 | "line_length": 420, 80 | // Number of characters for headings 81 | "heading_line_length": 90, 82 | // Number of characters for code blocks 83 | "code_block_line_length": 420, 84 | // Include code blocks 85 | "code_blocks": true, 86 | // Include tables 87 | "tables": true, 88 | // Include headings 89 | "headings": true, 90 | // Include headings 91 | "headers": true, 92 | // Strict length checking 93 | "strict": false, 94 | // Stern length checking 95 | "stern": true 96 | }, 97 | 98 | // MD014/commands-show-output - Dollar signs used before commands without showing output 99 | "MD014": true, 100 | 101 | // MD018/no-missing-space-atx - No space after hash on atx style heading 102 | "MD018": true, 103 | 104 | // MD019/no-multiple-space-atx - Multiple spaces after hash on atx style heading 105 | "MD019": true, 106 | 107 | // MD020/no-missing-space-closed-atx - No space inside hashes on closed atx style heading 108 | "MD020": true, 109 | 110 | // MD021/no-multiple-space-closed-atx - Multiple spaces inside hashes on closed atx style heading 111 | "MD021": true, 112 | 113 | // MD022/blanks-around-headings/blanks-around-headers - Headings should be surrounded by blank lines 114 | "MD022": { 115 | // Blank lines above heading 116 | "lines_above": 1, 117 | // Blank lines below heading 118 | "lines_below": 1 119 | }, 120 | 121 | // MD023/heading-start-left/header-start-left - Headings must start at the beginning of the line 122 | "MD023": true, 123 | 124 | // MD024/no-duplicate-heading/no-duplicate-header - Multiple headings with the same content 125 | "MD024": { 126 | // Only check sibling headings 127 | "allow_different_nesting": false, 128 | // Only check sibling headings 129 | "siblings_only": false 130 | }, 131 | 132 | // MD025/single-title/single-h1 - Multiple top-level headings in the same document 133 | "MD025": { 134 | // Heading level 135 | "level": 1, 136 | // RegExp for matching title in front matter 137 | "front_matter_title": "^\\s*title\\s*[:=]" 138 | }, 139 | 140 | // MD026/no-trailing-punctuation - Trailing punctuation in heading 141 | "MD026": { 142 | // Punctuation characters not allowed at end of headings 143 | "punctuation": ".,;:!。,;:!" 144 | }, 145 | 146 | // MD027/no-multiple-space-blockquote - Multiple spaces after blockquote symbol 147 | "MD027": true, 148 | 149 | // MD028/no-blanks-blockquote - Blank line inside blockquote 150 | "MD028": true, 151 | 152 | // MD029/ol-prefix - Ordered list item prefix 153 | "MD029": { 154 | // List style 155 | "style": "one_or_ordered" 156 | }, 157 | 158 | // MD030/list-marker-space - Spaces after list markers 159 | "MD030": { 160 | // Spaces for single-line unordered list items 161 | "ul_single": 1, 162 | // Spaces for single-line ordered list items 163 | "ol_single": 1, 164 | // Spaces for multi-line unordered list items 165 | "ul_multi": 1, 166 | // Spaces for multi-line ordered list items 167 | "ol_multi": 1 168 | }, 169 | 170 | // MD031/blanks-around-fences - Fenced code blocks should be surrounded by blank lines 171 | "MD031": { 172 | // Include list items 173 | "list_items": true 174 | }, 175 | 176 | // MD032/blanks-around-lists - Lists should be surrounded by blank lines 177 | "MD032": true, 178 | 179 | // MD033/no-inline-html - Inline HTML 180 | "MD033": { 181 | // Allowed elements 182 | "allowed_elements": ["a", "iframe", "img", "p", "div"] 183 | }, 184 | 185 | // MD034/no-bare-urls - Bare URL used 186 | "MD034": true, 187 | 188 | // MD035/hr-style - Horizontal rule style 189 | "MD035": { 190 | // Horizontal rule style 191 | "style": "consistent" 192 | }, 193 | 194 | // MD036/no-emphasis-as-heading/no-emphasis-as-header - Emphasis used instead of a heading 195 | "MD036": { 196 | // Punctuation characters 197 | "punctuation": ".,;:!?。,;:!?" 198 | }, 199 | 200 | // MD037/no-space-in-emphasis - Spaces inside emphasis markers 201 | "MD037": true, 202 | 203 | // MD038/no-space-in-code - Spaces inside code span elements 204 | "MD038": true, 205 | 206 | // MD039/no-space-in-links - Spaces inside link text 207 | "MD039": true, 208 | 209 | // MD040/fenced-code-language - Fenced code blocks should have a language specified 210 | "MD040": { 211 | // List of languages 212 | "allowed_languages": [], 213 | // Require language only 214 | "language_only": false 215 | }, 216 | 217 | // MD041/first-line-heading/first-line-h1 - First line in a file should be a top-level heading 218 | "MD041": { 219 | // Heading level 220 | "level": 1, 221 | // RegExp for matching title in front matter 222 | "front_matter_title": "^\\s*title\\s*[:=]" 223 | }, 224 | 225 | // MD042/no-empty-links - No empty links 226 | "MD042": true, 227 | 228 | // MD043/required-headings/required-headers - Required heading structure 229 | "MD043": {}, 230 | 231 | // MD044/proper-names - Proper names should have the correct capitalization 232 | "MD044": { 233 | // List of proper names 234 | "names": [], 235 | // Include code blocks 236 | "code_blocks": true, 237 | // Include HTML elements 238 | "html_elements": true 239 | }, 240 | 241 | // MD045/no-alt-text - Images should have alternate text (alt text) 242 | "MD045": true, 243 | 244 | // MD046/code-block-style - Code block style 245 | "MD046": { 246 | // Block style 247 | "style": "consistent" 248 | }, 249 | 250 | // MD047/single-trailing-newline - Files should end with a single newline character 251 | "MD047": true, 252 | 253 | // MD048/code-fence-style - Code fence style 254 | "MD048": { 255 | // Code fence style 256 | "style": "consistent" 257 | }, 258 | 259 | // MD049/emphasis-style - Emphasis style should be consistent 260 | "MD049": { 261 | // Emphasis style should be consistent 262 | "style": "consistent" 263 | }, 264 | 265 | // MD050/strong-style - Strong style should be consistent 266 | "MD050": { 267 | // Strong style should be consistent 268 | "style": "consistent" 269 | }, 270 | 271 | // MD051/link-fragments - Link fragments should be valid 272 | "MD051": true, 273 | 274 | // MD052/reference-links-images - Reference links and images should use a label that is defined 275 | "MD052": true, 276 | 277 | // MD053/link-image-reference-definitions - Link and image reference definitions should be needed 278 | "MD053": { 279 | // Ignored definitions 280 | "ignored_definitions": ["//"] 281 | } 282 | } 283 | -------------------------------------------------------------------------------- /docs/install/index.md: -------------------------------------------------------------------------------- 1 | # Install Rust 2 | 3 | [rustup]() is the defacto installer and version management tool for Rust. 4 | 5 | 6 | === "Rustup Install Script" 7 | 8 | !!! NOTE "" 9 | ```shell 10 | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh 11 | ``` 12 | 13 | ??? EXAMPLE "Install output" 14 | ```shell-output 15 | ❯ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh 16 | info: downloading installer 17 | 18 | Welcome to Rust! 19 | 20 | This will download and install the official compiler for the Rust 21 | programming language, and its package manager, Cargo. 22 | 23 | Rustup metadata and toolchains will be installed into the Rustup 24 | home directory, located at: 25 | 26 | /home/practicalli/.rustup 27 | 28 | This can be modified with the RUSTUP_HOME environment variable. 29 | 30 | The Cargo home directory is located at: 31 | 32 | /home/practicalli/.cargo 33 | 34 | This can be modified with the CARGO_HOME environment variable. 35 | 36 | The cargo, rustc, rustup and other commands will be added to 37 | Cargo's bin directory, located at: 38 | 39 | /home/practicalli/.cargo/bin 40 | 41 | This path will then be added to your PATH environment variable by 42 | modifying the profile files located at: 43 | 44 | /home/practicalli/.profile 45 | /home/practicalli/.bashrc 46 | /home/practicalli/.config/zsh/.zshenv 47 | 48 | You can uninstall at any time with rustup self uninstall and 49 | these changes will be reverted. 50 | 51 | Current installation options: 52 | 53 | 54 | default host triple: x86_64-unknown-linux-gnu 55 | default toolchain: stable (default) 56 | profile: default 57 | modify PATH variable: yes 58 | 59 | 1) Proceed with standard installation (default - just press enter) 60 | 2) Customize installation 61 | 3) Cancel installation 62 | 63 | info: profile set to 'default' 64 | info: default host triple is x86_64-unknown-linux-gnu 65 | info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu' 66 | info: latest update on 2025-05-15, rust version 1.87.0 (17067e9ac 2025-05-09) 67 | info: downloading component 'cargo' 68 | info: downloading component 'clippy' 69 | info: downloading component 'rust-docs' 70 | 19.9 MiB / 19.9 MiB (100 %) 13.6 MiB/s in 1s 71 | info: downloading component 'rust-std' 72 | 29.4 MiB / 29.4 MiB (100 %) 15.2 MiB/s in 2s 73 | info: downloading component 'rustc' 74 | 76.3 MiB / 76.3 MiB (100 %) 14.1 MiB/s in 5s 75 | info: downloading component 'rustfmt' 76 | info: installing component 'cargo' 77 | info: installing component 'clippy' 78 | info: installing component 'rust-docs' 79 | 19.9 MiB / 19.9 MiB (100 %) 5.9 MiB/s in 2s 80 | info: installing component 'rust-std' 81 | 29.4 MiB / 29.4 MiB (100 %) 9.4 MiB/s in 3s 82 | info: installing component 'rustc' 83 | 76.3 MiB / 76.3 MiB (100 %) 10.9 MiB/s in 7s 84 | info: installing component 'rustfmt' 85 | info: default toolchain set to 'stable-x86_64-unknown-linux-gnu' 86 | 87 | stable-x86_64-unknown-linux-gnu installed - rustc 1.87.0 (17067e9ac 2025-05-09) 88 | 89 | 90 | Rust is installed now. Great! 91 | 92 | To get started you may need to restart your current shell. 93 | This would reload your PATH environment variable to include 94 | Cargo's bin directory (/home/practicalli/.rust/cargo/bin). 95 | 96 | To configure your current shell, you need to source 97 | the corresponding env file under /home/practicalli/.rust/cargo/. 98 | 99 | This is usually done by running one of the following (note the leading DOT): 100 | . "/home/practicalli/.rust/cargo/env" # For sh/bash/zsh/ash/dash/pdksh 101 | source "/home/practicalli/.rust/cargo/env.fish" # For fish 102 | source $"/home/practicalli/.rust/cargo/env.nu" # For nushell 103 | ``` 104 | 105 | 106 | 107 | ??? EXAMPLE "Custom install locations" 108 | Set `RUSTUP_HOME` and `CARGO_HOME` environment variables to use a custom location. 109 | 110 | ```config title="~/.zshrc" 111 | # Rust Lang Development tools 112 | export RUSTUP_HOME="${RUSTUP_HOME:=$HOME/.config/rust/rustup}" 113 | export CARGO_HOME="${CARGO_HOME:=$HOME/.config/rust/cargo}" 114 | ``` 115 | 116 | 117 | ```shell-output 118 | ❯ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh 119 | info: downloading installer 120 | 121 | Welcome to Rust! 122 | 123 | This will download and install the official compiler for the Rust 124 | programming language, and its package manager, Cargo. 125 | 126 | Rustup metadata and toolchains will be installed into the Rustup 127 | home directory, located at: 128 | 129 | /home/practicalli/.config/rust/rustup/ 130 | 131 | This can be modified with the RUSTUP_HOME environment variable. 132 | 133 | The Cargo home directory is located at: 134 | 135 | /home/practicalli/.config/rust/cargo/ 136 | 137 | This can be modified with the CARGO_HOME environment variable. 138 | 139 | The cargo, rustc, rustup and other commands will be added to 140 | Cargo's bin directory, located at: 141 | 142 | /home/practicalli/.config/rust/cargo/bin 143 | 144 | This path will then be added to your PATH environment variable by 145 | modifying the profile files located at: 146 | 147 | /home/practicalli/.profile 148 | /home/practicalli/.bashrc 149 | /home/practicalli/.config/zsh/.zshenv 150 | 151 | You can uninstall at any time with rustup self uninstall and 152 | these changes will be reverted. 153 | 154 | Current installation options: 155 | 156 | 157 | default host triple: x86_64-unknown-linux-gnu 158 | default toolchain: stable (default) 159 | profile: default 160 | modify PATH variable: yes 161 | 162 | 1) Proceed with standard installation (default - just press enter) 163 | 2) Customize installation 164 | 3) Cancel installation 165 | 166 | 167 | info: profile set to 'default' 168 | info: default host triple is x86_64-unknown-linux-gnu 169 | info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu' 170 | info: latest update on 2025-05-15, rust version 1.87.0 (17067e9ac 2025-05-09) 171 | info: downloading component 'cargo' 172 | info: downloading component 'clippy' 173 | info: downloading component 'rust-docs' 174 | 19.9 MiB / 19.9 MiB (100 %) 13.6 MiB/s in 1s 175 | info: downloading component 'rust-std' 176 | 29.4 MiB / 29.4 MiB (100 %) 15.2 MiB/s in 2s 177 | info: downloading component 'rustc' 178 | 76.3 MiB / 76.3 MiB (100 %) 14.1 MiB/s in 5s 179 | info: downloading component 'rustfmt' 180 | info: installing component 'cargo' 181 | info: installing component 'clippy' 182 | info: installing component 'rust-docs' 183 | 19.9 MiB / 19.9 MiB (100 %) 5.9 MiB/s in 2s 184 | info: installing component 'rust-std' 185 | 29.4 MiB / 29.4 MiB (100 %) 9.4 MiB/s in 3s 186 | info: installing component 'rustc' 187 | 76.3 MiB / 76.3 MiB (100 %) 10.9 MiB/s in 7s 188 | info: installing component 'rustfmt' 189 | info: default toolchain set to 'stable-x86_64-unknown-linux-gnu' 190 | 191 | stable-x86_64-unknown-linux-gnu installed - rustc 1.87.0 (17067e9ac 2025-05-09) 192 | 193 | 194 | Rust is installed now. Great! 195 | 196 | To get started you may need to restart your current shell. 197 | This would reload your PATH environment variable to include 198 | Cargo's bin directory (/home/practicalli/.config/rust/cargo/bin). 199 | 200 | To configure your current shell, you need to source 201 | the corresponding env file under /home/practicalli/.config/rust/cargo. 202 | 203 | This is usually done by running one of the following (note the leading DOT): 204 | . "/home/practicalli/.config/rust/cargo/env" # For sh/bash/zsh/ash/dash/pdksh 205 | source "/home/practicalli/.config/rust/cargo/env.fish" # For fish 206 | source $"/home/practicalli/.config/rust/cargo/env.nu" # For nushell 207 | ``` 208 | 209 | 210 | ## Confirm Install 211 | 212 | `cargo --version` command in a terminal to test Rust and Cargo installed 213 | 214 | 215 | ## Tools 216 | 217 | The Rustup script installs several tools 218 | 219 | 220 | - rust : version 1.87.0 (17067e9ac 2025-05-09) 221 | - rustc : 222 | - rustfmt : 223 | - rust-std : 224 | - rust-docs : 225 | - cargo : 226 | - clippy : 227 | 228 | 229 | ## Update 230 | 231 | !!! NOTE "" 232 | ```shell 233 | rustup update 234 | ``` 235 | 236 | 237 | 238 | 239 | !!! TIP "clangd for faster compilation speed ?" 240 | -------------------------------------------------------------------------------- /docs/introduction/rust-in-15-minutes.md: -------------------------------------------------------------------------------- 1 | # Rust In 15 Minutes 2 | 3 | Examples showing the syntax and basic concepts of the Rust programming language. Consider this a sneak peak for the rest of the book. 4 | 5 | > NOTE: [Rust Tutorial video series](https://youtube.com/playlist?list=PLLqEtX6ql2EyPAZ1M2_C0GgVd4A-_L4_5&si=xK0jSgNZgZAyitOy) provides an in-depth introduction to Rust (or read the rest of this book) 6 | 7 | 8 | ## Local variables 9 | 10 | Assign a value to a local variable using `let` inside a function or procedure 11 | 12 | 13 | ```rust 14 | fn main() { 15 | let myName = "Nishant"; // Rust infers type to be String 16 | let coins: u32 = 4; // explicit type, unsigned 32-bit integer 17 | 18 | let age = 19; // number defaults to i32 type, signed 32-bit integer 19 | } 20 | ``` 21 | 22 | Variables are immutable unless the `mut` type is explicitly included 23 | 24 | 25 | ```rust 26 | fn main() { 27 | let mut age = 21; 28 | } 29 | ``` 30 | 31 | > NOTE: rust compiler will warn if a variable doesnt need to be mutable or if it is unused. 32 | 33 | > NOTE: use `const` for a 'shared' variable 34 | 35 | If we declare a variable, and we try to use it without initializing, the Rust compiler will complain. 36 | 37 | ```rust 38 | // * WILL NOT COMPILE 39 | fn main() { 40 | let coins: u32; 41 | foobar(coins); 42 | } 43 | 44 | fn foobar(num: u32) { 45 | println!("The number sent was {}", num); 46 | } 47 | ``` 48 | 49 | ```shell-output 50 | Compiling hello_cargo v0.1.0 (/home/nishant/Programming/Rust/hello_cargo) 51 | error[E0381]: used binding `coins` isn't initialized 52 | --> src/main.rs:3:9 53 | | 54 | 2 | let coins: u32; 55 | | ----- binding declared here but left uninitialized 56 | 3 | foobar(coins); 57 | | ^^^^^ `coins` used here but it isn't initialized 58 | | 59 | help: consider assigning a value 60 | | 61 | 2 | let coins: u32 = 0; 62 | | +++ 63 | 64 | For more information about this error, try `rustc --explain E0381`. 65 | error: could not compile `hello_cargo` due to previous error 66 | ``` 67 | 68 | As Rust programmers, we must read all error messages fully. The error message here tells us that we have used coins but we haven’t initialized it. The message goes on to say that in line 2, we should append = 0 in order for the code to work! 69 | 70 | There are many data types used in Rust. We have come across String, i32 and u32. We also have, 71 | 72 | ```rust 73 | fn main() { 74 | let temperature: f32 = 6.4; 75 | let circumference: f64 = 23053.7106; 76 | 77 | let grade: char = 'A'; 78 | let pass: bool = true; 79 | } 80 | ``` 81 | 82 | ### Mutation 83 | 84 | All symbols are immutable unless marked with `mut` for mutation. 85 | 86 | When a symbol is declared mutable, care should be taken to assign it of the same type. 87 | 88 | 89 | ### Constants 90 | 91 | ```rust 92 | const welcome_message = "Welcome to the wonderful world of Rust"; 93 | ``` 94 | 95 | [Constant items - Rust-Lang](https://doc.rust-lang.org/reference/items/constant-items.html){target=_blank .md-button} 96 | 97 | 98 | ## Compound data types 99 | 100 | Those above were some more primitive data types. Rust has support for compound data types as well! 101 | 102 | ```rust 103 | fn main() { 104 | let pair = ('A', 65); 105 | 106 | println!(pair.0) // Accessing first element 107 | println!(pair.1) // Accessing second element 108 | 109 | // Destructuring a pair. 110 | let (letter, number) = pair 111 | } 112 | ``` 113 | 114 | The implicit type for pair is (char, i32). Tuples are heterogeneous and can support nested tuples as well. 115 | 116 | Additionally, we can work with Arrays as well, 117 | 118 | ```rust 119 | fn main() { 120 | let a = [1, 2, 3, 4, 5]; 121 | // a has a type [i32; 5] - an array of five signed 32-bit integers. 122 | } 123 | ``` 124 | 125 | A data type declaration can hint towards a quick way to initialize arrays. 126 | 127 | ```rust 128 | fn main() { 129 | let a = [3; 5]; 130 | 131 | for i in a { 132 | println!("{i}"); 133 | } 134 | } 135 | 136 | // This program will print 3 on five lines. 137 | ``` 138 | 139 | 140 | ## Functions 141 | 142 | We have seen we have been using the main function to denote the starting point in our program. The syntax of defining functions is 143 | 144 | ```rust 145 | fn (: ) -> { 146 | body 147 | } 148 | 149 | An example function can be like: 150 | 151 | fn is_divisible(num: i32, dividend: i32) -> bool { 152 | num % dividend == 0 153 | } 154 | ``` 155 | 156 | Notice I do not have a semicolon at the end of that statement. This signifies that the expression will return a particular value. If I add a semicolon, Rust will treat the expression as a statement and will complain I am not returning a boolean value. 157 | 158 | ### Procedures 159 | 160 | Procedures are functions that do not return a value 161 | 162 | 163 | 164 | ```rust 165 | fn (: ) { 166 | body 167 | } 168 | 169 | An example function can be like: 170 | 171 | fn output_results(num: i32, dividend: i32) { 172 | println!(num % dividend == 0); 173 | } 174 | ``` 175 | 176 | 177 | ## Let Expressions 178 | 179 | Combining the knowledge of variables and functions, we can assign values like this: 180 | 181 | ```rust 182 | let x = { 183 | let y = 1; 184 | let z = 2; 185 | 186 | y + z // Note the lack of semicolon to indicate return value 187 | } 188 | ``` 189 | 190 | Hence, we can conclude that: 191 | 192 | ```rust 193 | fn main() { 194 | let x = 0; 195 | let x = { 0 }; // these two are the same! 196 | } 197 | ``` 198 | 199 | ## Variable Shadowing and Scopes 200 | 201 | Notice how I didn’t prefix the previous code block with // * WILL NOT COMPILE. However, I do have two declarations of the same variable. This is called variable shadowing. 202 | 203 | ```rust 204 | fn main() { 205 | let x = 0; 206 | let x = { 10 }; // shadowed the previous value of x 207 | } 208 | ``` 209 | 210 | First we initialize x to be 0, and then I am re-initializing it to be 10. This is a valid program and useful in many ways when we couple it with scopes! 211 | 212 | Scopes are just a block of code where shadowed variables do not affect the value of the variable outside the scope. 213 | 214 | ```rust 215 | fn main () { 216 | let x = 4; 217 | 218 | { 219 | let x = "shadowing x"; 220 | println!("{}", x); // pfints "shadowing x" 221 | } 222 | 223 | println!("{}", x); // prints "4" 224 | } 225 | ``` 226 | 227 | ## Namespaces 228 | 229 | If we wish to use functions from other libraries, we can use namespaces. 230 | 231 | ```rust 232 | fn main() { 233 | let least = std::cmp::min(3, 8); 234 | 235 | println!("{}", least); 236 | } 237 | ``` 238 | 239 | We can also bring the function into scope by using the use keyword. 240 | 241 | ```rust 242 | use std::cmp::min; 243 | 244 | fn main() { 245 | let least = min(3, 8); 246 | 247 | println!("{}", least); 248 | } 249 | ``` 250 | 251 | Use `std::cmp::*` to bring every function inside `std::cmp` into scope. 252 | 253 | 254 | ## Structs 255 | 256 | Define a struct Coordinate and initialize a variable of that type. 257 | 258 | ```rust 259 | struct Coordinate { 260 | x: f64, 261 | y: f64 262 | } 263 | 264 | fn main() { 265 | let somewhere = Coordinate { x: 23, y: 3.5 }; 266 | 267 | // Spreading the values of somewhere and updating x to 5.4 268 | // make sure that ..somewhere is at the end. 269 | let elsewhere = Coordinate { x: 5.4, ..somwhere }; 270 | 271 | // Destructuring Coordinate. 272 | let Coordinate { 273 | x, 274 | y 275 | } = elsewhere; 276 | } 277 | ``` 278 | 279 | Implement a functions for the struct 280 | 281 | ```rust 282 | impl Coordinate { 283 | fn add(self, coord: Coordinate) -> Coordinate { 284 | let newX = self.x + coord.x; 285 | let newY = self.y + coord.y; 286 | 287 | Coordinate { x: newX, y: newY } 288 | } 289 | } 290 | ``` 291 | 292 | 293 | ## Pattern Matching 294 | 295 | Pattern Matching is like a conditional structure. 296 | 297 | ```rust 298 | fn main() { 299 | let coordinate = Coordinate { x: 3.0, y: 5.0 } 300 | 301 | if let Coordinate { x: 3.0, y } = coordinate { 302 | println!("(3, {})", y); 303 | } else { 304 | println!("x != three"); 305 | } 306 | } 307 | ``` 308 | 309 | We can also perform pattern matching using the match construct. 310 | 311 | ```rust 312 | fn main() { 313 | let coordinate = Coordinate { x: 3.0, y: 5.0 } 314 | 315 | match coordinate { 316 | Coordinate { x: 3.0, y } => println!("(3, {})", y); 317 | _ => println!("x != three"); 318 | } 319 | } 320 | ``` 321 | 322 | Alternatively, this code also compiles: 323 | 324 | ```rust 325 | fn main() { 326 | let coordinate = Coordinate { x: 3.0, y: 5.0 } 327 | 328 | match coordinate { 329 | Coordinate { x: 3.0, y } => println!("(3, {})", y); 330 | Coordinate { .. } => println!("x != three"); 331 | } 332 | } 333 | ``` 334 | 335 | `..` means ignore the (remaining) properties inside the Coordinate struct. 336 | 337 | 338 | ## Traits 339 | 340 | Traits are like type classes in Haskell, or interfaces in Java. Say that we have a struct, Number which looks like this: 341 | 342 | ```rust 343 | struct Number { 344 | value: isize, 345 | prime: bool 346 | } 347 | ``` 348 | 349 | We could define a trait Parity that contains a function is_even. If we implement Parity for Number, we need to define the trait’s functions. 350 | 351 | ```rust 352 | trait Parity { 353 | fn is_even(self) -> bool 354 | } 355 | 356 | impl Parity for Number { 357 | fn is_even(self) -> bool { 358 | self.value % 2 == 0 359 | } 360 | } 361 | ``` 362 | 363 | We can also implement traits for foreign types as well! 364 | 365 | ```rust 366 | // Using our struct for foreign type 367 | impl Parity for i32 { 368 | fn is_even(self) -> bool { 369 | self % 2 == 0 370 | } 371 | } 372 | 373 | // Using foriegn trait for our struct 374 | impl std::ops:Neg for Number { 375 | type Output = Number; 376 | 377 | fn neg(self) -> Self::Output { 378 | Number { 379 | value: -self.value 380 | ..self 381 | } 382 | } 383 | } 384 | ``` 385 | 386 | Foreign traits cannot be defined for foreign structs 387 | 388 | ```rust 389 | // * WILL NOT COMPILE 390 | impl std::ops::Neg for Vec { 391 | type Output = isize; 392 | 393 | fn neg(self) -> Self::Output { 394 | -self.len() 395 | } 396 | } 397 | ``` 398 | 399 | 400 | ## Macros 401 | 402 | Macros are a part of meta-programming. Marcos can be considered as little programs that other programs can use. All macros end with ! and can be defined as either of the following: 403 | 404 | ```rust 405 | macro_name!() 406 | macro_name!{} 407 | macro_name![] 408 | ``` 409 | 410 | `println!` is a macro that uses `std::io` to write to the console. 411 | 412 | `vec![]` defines a vector, an array like structure 413 | 414 | 415 | ```rust 416 | fn main() { 417 | let vec1 = vec![1,2,3]; 418 | 419 | for number in vec1 { 420 | println!("{number}"); 421 | } 422 | } 423 | ``` 424 | 425 | `panic!` is a macro that terminates a program Thread with an error message. `panic!` is one of the only places code can crash. 426 | 427 | 428 | ## Enums 429 | 430 | Enums are types that are defined in an enclosure. The following example is coupled with Generics. Option is also defined in the standard library. 431 | 432 | ```rust 433 | enum Option { 434 | None, 435 | Some(T) 436 | } 437 | 438 | impl Option { 439 | unwrap() -> T { 440 | match self { 441 | Self::None -> panic!("unwrap called on an Option None"), 442 | Self::Some -> T, 443 | } 444 | } 445 | } 446 | ``` 447 | 448 | 449 | ## The Result enum 450 | 451 | Rust provides the enum `Result`. 452 | 453 | ```rust 454 | enum Result { 455 | Ok(T), 456 | Err(E) 457 | } 458 | ``` 459 | 460 | When a function returns a result, we can safely handle it. 461 | 462 | ```rust 463 | fn main() { 464 | { 465 | let result = do_something(); // returns result 466 | 467 | match result { 468 | Ok(data) => proceed(data), 469 | Err(error) => panic!("There has been an error!"), 470 | } 471 | 472 | // continue program execution 473 | } 474 | } 475 | ``` 476 | 477 | The reason I have used this code within a scope block is if we wish to propagate the error up somewhere, we could replace the code with: 478 | 479 | ```rust 480 | fn main() { 481 | { 482 | let result = do_something(); // returns result 483 | 484 | match result { 485 | Ok(data) => proceed(data), 486 | Err(error) => return error, 487 | } 488 | 489 | // continue program execution 490 | } 491 | } 492 | ``` 493 | 494 | There is a shorthand to do this operation: 495 | 496 | ```rust 497 | fn main() { 498 | { 499 | let data = do_something()?; // returns result 500 | 501 | // work with data directly 502 | } 503 | } 504 | ``` 505 | 506 | Now if result returns an `Ok(data)`, then the question mark will return the data object to us. 507 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Attribution-ShareAlike 4.0 International 2 | 3 | ======================================================================= 4 | 5 | Creative Commons Corporation ("Creative Commons") is not a law firm and 6 | does not provide legal services or legal advice. Distribution of 7 | Creative Commons public licenses does not create a lawyer-client or 8 | other relationship. Creative Commons makes its licenses and related 9 | information available on an "as-is" basis. Creative Commons gives no 10 | warranties regarding its licenses, any material licensed under their 11 | terms and conditions, or any related information. Creative Commons 12 | disclaims all liability for damages resulting from their use to the 13 | fullest extent possible. 14 | 15 | Using Creative Commons Public Licenses 16 | 17 | Creative Commons public licenses provide a standard set of terms and 18 | conditions that creators and other rights holders may use to share 19 | original works of authorship and other material subject to copyright 20 | and certain other rights specified in the public license below. The 21 | following considerations are for informational purposes only, are not 22 | exhaustive, and do not form part of our licenses. 23 | 24 | Considerations for licensors: Our public licenses are 25 | intended for use by those authorized to give the public 26 | permission to use material in ways otherwise restricted by 27 | copyright and certain other rights. Our licenses are 28 | irrevocable. Licensors should read and understand the terms 29 | and conditions of the license they choose before applying it. 30 | Licensors should also secure all rights necessary before 31 | applying our licenses so that the public can reuse the 32 | material as expected. Licensors should clearly mark any 33 | material not subject to the license. This includes other CC- 34 | licensed material, or material used under an exception or 35 | limitation to copyright. More considerations for licensors: 36 | wiki.creativecommons.org/Considerations_for_licensors 37 | 38 | Considerations for the public: By using one of our public 39 | licenses, a licensor grants the public permission to use the 40 | licensed material under specified terms and conditions. If 41 | the licensor's permission is not necessary for any reason--for 42 | example, because of any applicable exception or limitation to 43 | copyright--then that use is not regulated by the license. Our 44 | licenses grant only permissions under copyright and certain 45 | other rights that a licensor has authority to grant. Use of 46 | the licensed material may still be restricted for other 47 | reasons, including because others have copyright or other 48 | rights in the material. A licensor may make special requests, 49 | such as asking that all changes be marked or described. 50 | Although not required by our licenses, you are encouraged to 51 | respect those requests where reasonable. More_considerations 52 | for the public: 53 | wiki.creativecommons.org/Considerations_for_licensees 54 | 55 | ======================================================================= 56 | 57 | Creative Commons Attribution-ShareAlike 4.0 International Public 58 | License 59 | 60 | By exercising the Licensed Rights (defined below), You accept and agree 61 | to be bound by the terms and conditions of this Creative Commons 62 | Attribution-ShareAlike 4.0 International Public License ("Public 63 | License"). To the extent this Public License may be interpreted as a 64 | contract, You are granted the Licensed Rights in consideration of Your 65 | acceptance of these terms and conditions, and the Licensor grants You 66 | such rights in consideration of benefits the Licensor receives from 67 | making the Licensed Material available under these terms and 68 | conditions. 69 | 70 | 71 | Section 1 -- Definitions. 72 | 73 | a. Adapted Material means material subject to Copyright and Similar 74 | Rights that is derived from or based upon the Licensed Material 75 | and in which the Licensed Material is translated, altered, 76 | arranged, transformed, or otherwise modified in a manner requiring 77 | permission under the Copyright and Similar Rights held by the 78 | Licensor. For purposes of this Public License, where the Licensed 79 | Material is a musical work, performance, or sound recording, 80 | Adapted Material is always produced where the Licensed Material is 81 | synched in timed relation with a moving image. 82 | 83 | b. Adapter's License means the license You apply to Your Copyright 84 | and Similar Rights in Your contributions to Adapted Material in 85 | accordance with the terms and conditions of this Public License. 86 | 87 | c. BY-SA Compatible License means a license listed at 88 | creativecommons.org/compatiblelicenses, approved by Creative 89 | Commons as essentially the equivalent of this Public License. 90 | 91 | d. Copyright and Similar Rights means copyright and/or similar rights 92 | closely related to copyright including, without limitation, 93 | performance, broadcast, sound recording, and Sui Generis Database 94 | Rights, without regard to how the rights are labeled or 95 | categorized. For purposes of this Public License, the rights 96 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 97 | Rights. 98 | 99 | e. Effective Technological Measures means those measures that, in the 100 | absence of proper authority, may not be circumvented under laws 101 | fulfilling obligations under Article 11 of the WIPO Copyright 102 | Treaty adopted on December 20, 1996, and/or similar international 103 | agreements. 104 | 105 | f. Exceptions and Limitations means fair use, fair dealing, and/or 106 | any other exception or limitation to Copyright and Similar Rights 107 | that applies to Your use of the Licensed Material. 108 | 109 | g. License Elements means the license attributes listed in the name 110 | of a Creative Commons Public License. The License Elements of this 111 | Public License are Attribution and ShareAlike. 112 | 113 | h. Licensed Material means the artistic or literary work, database, 114 | or other material to which the Licensor applied this Public 115 | License. 116 | 117 | i. Licensed Rights means the rights granted to You subject to the 118 | terms and conditions of this Public License, which are limited to 119 | all Copyright and Similar Rights that apply to Your use of the 120 | Licensed Material and that the Licensor has authority to license. 121 | 122 | j. Licensor means the individual(s) or entity(ies) granting rights 123 | under this Public License. 124 | 125 | k. Share means to provide material to the public by any means or 126 | process that requires permission under the Licensed Rights, such 127 | as reproduction, public display, public performance, distribution, 128 | dissemination, communication, or importation, and to make material 129 | available to the public including in ways that members of the 130 | public may access the material from a place and at a time 131 | individually chosen by them. 132 | 133 | l. Sui Generis Database Rights means rights other than copyright 134 | resulting from Directive 96/9/EC of the European Parliament and of 135 | the Council of 11 March 1996 on the legal protection of databases, 136 | as amended and/or succeeded, as well as other essentially 137 | equivalent rights anywhere in the world. 138 | 139 | m. You means the individual or entity exercising the Licensed Rights 140 | under this Public License. Your has a corresponding meaning. 141 | 142 | 143 | Section 2 -- Scope. 144 | 145 | a. License grant. 146 | 147 | 1. Subject to the terms and conditions of this Public License, 148 | the Licensor hereby grants You a worldwide, royalty-free, 149 | non-sublicensable, non-exclusive, irrevocable license to 150 | exercise the Licensed Rights in the Licensed Material to: 151 | 152 | a. reproduce and Share the Licensed Material, in whole or 153 | in part; and 154 | 155 | b. produce, reproduce, and Share Adapted Material. 156 | 157 | 2. Exceptions and Limitations. For the avoidance of doubt, where 158 | Exceptions and Limitations apply to Your use, this Public 159 | License does not apply, and You do not need to comply with 160 | its terms and conditions. 161 | 162 | 3. Term. The term of this Public License is specified in Section 163 | 6(a). 164 | 165 | 4. Media and formats; technical modifications allowed. The 166 | Licensor authorizes You to exercise the Licensed Rights in 167 | all media and formats whether now known or hereafter created, 168 | and to make technical modifications necessary to do so. The 169 | Licensor waives and/or agrees not to assert any right or 170 | authority to forbid You from making technical modifications 171 | necessary to exercise the Licensed Rights, including 172 | technical modifications necessary to circumvent Effective 173 | Technological Measures. For purposes of this Public License, 174 | simply making modifications authorized by this Section 2(a) 175 | (4) never produces Adapted Material. 176 | 177 | 5. Downstream recipients. 178 | 179 | a. Offer from the Licensor -- Licensed Material. Every 180 | recipient of the Licensed Material automatically 181 | receives an offer from the Licensor to exercise the 182 | Licensed Rights under the terms and conditions of this 183 | Public License. 184 | 185 | b. Additional offer from the Licensor -- Adapted Material. 186 | Every recipient of Adapted Material from You 187 | automatically receives an offer from the Licensor to 188 | exercise the Licensed Rights in the Adapted Material 189 | under the conditions of the Adapter's License You apply. 190 | 191 | c. No downstream restrictions. You may not offer or impose 192 | any additional or different terms or conditions on, or 193 | apply any Effective Technological Measures to, the 194 | Licensed Material if doing so restricts exercise of the 195 | Licensed Rights by any recipient of the Licensed 196 | Material. 197 | 198 | 6. No endorsement. Nothing in this Public License constitutes or 199 | may be construed as permission to assert or imply that You 200 | are, or that Your use of the Licensed Material is, connected 201 | with, or sponsored, endorsed, or granted official status by, 202 | the Licensor or others designated to receive attribution as 203 | provided in Section 3(a)(1)(A)(i). 204 | 205 | b. Other rights. 206 | 207 | 1. Moral rights, such as the right of integrity, are not 208 | licensed under this Public License, nor are publicity, 209 | privacy, and/or other similar personality rights; however, to 210 | the extent possible, the Licensor waives and/or agrees not to 211 | assert any such rights held by the Licensor to the limited 212 | extent necessary to allow You to exercise the Licensed 213 | Rights, but not otherwise. 214 | 215 | 2. Patent and trademark rights are not licensed under this 216 | Public License. 217 | 218 | 3. To the extent possible, the Licensor waives any right to 219 | collect royalties from You for the exercise of the Licensed 220 | Rights, whether directly or through a collecting society 221 | under any voluntary or waivable statutory or compulsory 222 | licensing scheme. In all other cases the Licensor expressly 223 | reserves any right to collect such royalties. 224 | 225 | 226 | Section 3 -- License Conditions. 227 | 228 | Your exercise of the Licensed Rights is expressly made subject to the 229 | following conditions. 230 | 231 | a. Attribution. 232 | 233 | 1. If You Share the Licensed Material (including in modified 234 | form), You must: 235 | 236 | a. retain the following if it is supplied by the Licensor 237 | with the Licensed Material: 238 | 239 | i. identification of the creator(s) of the Licensed 240 | Material and any others designated to receive 241 | attribution, in any reasonable manner requested by 242 | the Licensor (including by pseudonym if 243 | designated); 244 | 245 | ii. a copyright notice; 246 | 247 | iii. a notice that refers to this Public License; 248 | 249 | iv. a notice that refers to the disclaimer of 250 | warranties; 251 | 252 | v. a URI or hyperlink to the Licensed Material to the 253 | extent reasonably practicable; 254 | 255 | b. indicate if You modified the Licensed Material and 256 | retain an indication of any previous modifications; and 257 | 258 | c. indicate the Licensed Material is licensed under this 259 | Public License, and include the text of, or the URI or 260 | hyperlink to, this Public License. 261 | 262 | 2. You may satisfy the conditions in Section 3(a)(1) in any 263 | reasonable manner based on the medium, means, and context in 264 | which You Share the Licensed Material. For example, it may be 265 | reasonable to satisfy the conditions by providing a URI or 266 | hyperlink to a resource that includes the required 267 | information. 268 | 269 | 3. If requested by the Licensor, You must remove any of the 270 | information required by Section 3(a)(1)(A) to the extent 271 | reasonably practicable. 272 | 273 | b. ShareAlike. 274 | 275 | In addition to the conditions in Section 3(a), if You Share 276 | Adapted Material You produce, the following conditions also apply. 277 | 278 | 1. The Adapter's License You apply must be a Creative Commons 279 | license with the same License Elements, this version or 280 | later, or a BY-SA Compatible License. 281 | 282 | 2. You must include the text of, or the URI or hyperlink to, the 283 | Adapter's License You apply. You may satisfy this condition 284 | in any reasonable manner based on the medium, means, and 285 | context in which You Share Adapted Material. 286 | 287 | 3. You may not offer or impose any additional or different terms 288 | or conditions on, or apply any Effective Technological 289 | Measures to, Adapted Material that restrict exercise of the 290 | rights granted under the Adapter's License You apply. 291 | 292 | 293 | Section 4 -- Sui Generis Database Rights. 294 | 295 | Where the Licensed Rights include Sui Generis Database Rights that 296 | apply to Your use of the Licensed Material: 297 | 298 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 299 | to extract, reuse, reproduce, and Share all or a substantial 300 | portion of the contents of the database; 301 | 302 | b. if You include all or a substantial portion of the database 303 | contents in a database in which You have Sui Generis Database 304 | Rights, then the database in which You have Sui Generis Database 305 | Rights (but not its individual contents) is Adapted Material, 306 | 307 | including for purposes of Section 3(b); and 308 | c. You must comply with the conditions in Section 3(a) if You Share 309 | all or a substantial portion of the contents of the database. 310 | 311 | For the avoidance of doubt, this Section 4 supplements and does not 312 | replace Your obligations under this Public License where the Licensed 313 | Rights include other Copyright and Similar Rights. 314 | 315 | 316 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 317 | 318 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 319 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 320 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 321 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 322 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 323 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 324 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 325 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 326 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 327 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 328 | 329 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 330 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 331 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 332 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 333 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 334 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 335 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 336 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 337 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 338 | 339 | c. The disclaimer of warranties and limitation of liability provided 340 | above shall be interpreted in a manner that, to the extent 341 | possible, most closely approximates an absolute disclaimer and 342 | waiver of all liability. 343 | 344 | 345 | Section 6 -- Term and Termination. 346 | 347 | a. This Public License applies for the term of the Copyright and 348 | Similar Rights licensed here. However, if You fail to comply with 349 | this Public License, then Your rights under this Public License 350 | terminate automatically. 351 | 352 | b. Where Your right to use the Licensed Material has terminated under 353 | Section 6(a), it reinstates: 354 | 355 | 1. automatically as of the date the violation is cured, provided 356 | it is cured within 30 days of Your discovery of the 357 | violation; or 358 | 359 | 2. upon express reinstatement by the Licensor. 360 | 361 | For the avoidance of doubt, this Section 6(b) does not affect any 362 | right the Licensor may have to seek remedies for Your violations 363 | of this Public License. 364 | 365 | c. For the avoidance of doubt, the Licensor may also offer the 366 | Licensed Material under separate terms or conditions or stop 367 | distributing the Licensed Material at any time; however, doing so 368 | will not terminate this Public License. 369 | 370 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 371 | License. 372 | 373 | 374 | Section 7 -- Other Terms and Conditions. 375 | 376 | a. The Licensor shall not be bound by any additional or different 377 | terms or conditions communicated by You unless expressly agreed. 378 | 379 | b. Any arrangements, understandings, or agreements regarding the 380 | Licensed Material not stated herein are separate from and 381 | independent of the terms and conditions of this Public License. 382 | 383 | 384 | Section 8 -- Interpretation. 385 | 386 | a. For the avoidance of doubt, this Public License does not, and 387 | shall not be interpreted to, reduce, limit, restrict, or impose 388 | conditions on any use of the Licensed Material that could lawfully 389 | be made without permission under this Public License. 390 | 391 | b. To the extent possible, if any provision of this Public License is 392 | deemed unenforceable, it shall be automatically reformed to the 393 | minimum extent necessary to make it enforceable. If the provision 394 | cannot be reformed, it shall be severed from this Public License 395 | without affecting the enforceability of the remaining terms and 396 | conditions. 397 | 398 | c. No term or condition of this Public License will be waived and no 399 | failure to comply consented to unless expressly agreed to by the 400 | Licensor. 401 | 402 | d. Nothing in this Public License constitutes or may be interpreted 403 | as a limitation upon, or waiver of, any privileges and immunities 404 | that apply to the Licensor or You, including from the legal 405 | processes of any jurisdiction or authority. 406 | 407 | 408 | ======================================================================= 409 | 410 | Creative Commons is not a party to its public 411 | licenses. Notwithstanding, Creative Commons may elect to apply one of 412 | its public licenses to material it publishes and in those instances 413 | will be considered the “Licensor.” The text of the Creative Commons 414 | public licenses is dedicated to the public domain under the CC0 Public 415 | Domain Dedication. Except for the limited purpose of indicating that 416 | material is shared under a Creative Commons public license or as 417 | otherwise permitted by the Creative Commons policies published at 418 | creativecommons.org/policies, Creative Commons does not authorize the 419 | use of the trademark "Creative Commons" or any other trademark or logo 420 | of Creative Commons without its prior written consent including, 421 | without limitation, in connection with any unauthorized modifications 422 | to any of its public licenses or any other arrangements, 423 | understandings, or agreements concerning use of licensed material. For 424 | the avoidance of doubt, this paragraph does not form part of the 425 | public licenses. 426 | 427 | Creative Commons may be contacted at creativecommons.org. 428 | --------------------------------------------------------------------------------