43 |
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 | [](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 | [](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 |
--------------------------------------------------------------------------------