mirror of
https://github.com/darkicewolf50/RustBrock.git
synced 2025-06-15 04:54:17 -06:00
fixed spelling
This commit is contained in:
parent
05ef5ce477
commit
792606e001
98
.obsidian/workspace.json
vendored
98
.obsidian/workspace.json
vendored
@ -4,67 +4,20 @@
|
|||||||
"type": "split",
|
"type": "split",
|
||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
"id": "0396922c68d14225",
|
"id": "9cf638edb21842e3",
|
||||||
"type": "tabs",
|
"type": "tabs",
|
||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
"id": "bda58467a9a0a34e",
|
"id": "3025ec3e871a2841",
|
||||||
"type": "leaf",
|
"type": "leaf",
|
||||||
"state": {
|
"state": {
|
||||||
"type": "markdown",
|
"type": "empty",
|
||||||
"state": {
|
"state": {},
|
||||||
"file": "ownership.md",
|
|
||||||
"mode": "source",
|
|
||||||
"source": false
|
|
||||||
},
|
|
||||||
"icon": "lucide-file",
|
"icon": "lucide-file",
|
||||||
"title": "ownership"
|
"title": "New tab"
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "b80f5219fa24358f",
|
|
||||||
"type": "leaf",
|
|
||||||
"state": {
|
|
||||||
"type": "markdown",
|
|
||||||
"state": {
|
|
||||||
"file": "Collection of Common Data Structs.md",
|
|
||||||
"mode": "source",
|
|
||||||
"source": false
|
|
||||||
},
|
|
||||||
"icon": "lucide-file",
|
|
||||||
"title": "Collection of Common Data Structs"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "3a5f95a8df68eb56",
|
|
||||||
"type": "leaf",
|
|
||||||
"state": {
|
|
||||||
"type": "markdown",
|
|
||||||
"state": {
|
|
||||||
"file": "Error Handling.md",
|
|
||||||
"mode": "source",
|
|
||||||
"source": false
|
|
||||||
},
|
|
||||||
"icon": "lucide-file",
|
|
||||||
"title": "Error Handling"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "b6a35c226bb40634",
|
|
||||||
"type": "leaf",
|
|
||||||
"state": {
|
|
||||||
"type": "markdown",
|
|
||||||
"state": {
|
|
||||||
"file": "data_types.md",
|
|
||||||
"mode": "source",
|
|
||||||
"source": false
|
|
||||||
},
|
|
||||||
"icon": "lucide-file",
|
|
||||||
"title": "data_types"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"currentTab": 2
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"direction": "vertical"
|
"direction": "vertical"
|
||||||
@ -206,32 +159,37 @@
|
|||||||
"command-palette:Open command palette": false
|
"command-palette:Open command palette": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"active": "3a5f95a8df68eb56",
|
"active": "3025ec3e871a2841",
|
||||||
"lastOpenFiles": [
|
"lastOpenFiles": [
|
||||||
"Collection of Common Data Structs.md",
|
|
||||||
"Error Handling.md",
|
|
||||||
"Hash.md",
|
|
||||||
"String.md",
|
|
||||||
"README.md",
|
|
||||||
"Vector.md",
|
|
||||||
"data_types.md",
|
"data_types.md",
|
||||||
|
"Collection of Common Data Structs.md",
|
||||||
|
"Constants.md",
|
||||||
|
"Crates.md",
|
||||||
|
"Data Types.md",
|
||||||
|
"Enums.md",
|
||||||
|
"Error Handling.md",
|
||||||
|
"Generic Types Traits and Lifetimes.md",
|
||||||
|
"Generics.md",
|
||||||
|
"Hash.md",
|
||||||
"Modules and Use.md",
|
"Modules and Use.md",
|
||||||
"ownership.md",
|
"ownership.md",
|
||||||
"Project Organization.md",
|
|
||||||
"Packages.md",
|
"Packages.md",
|
||||||
"Crates.md",
|
|
||||||
"crates.io.md",
|
|
||||||
"Paths.md",
|
"Paths.md",
|
||||||
"does_not_compile.svg",
|
|
||||||
"Structures.md",
|
|
||||||
"Primitives.md",
|
"Primitives.md",
|
||||||
|
"Project Organization.md",
|
||||||
|
"README.md",
|
||||||
|
"Reducing_Code_Duplication.md",
|
||||||
|
"String.md",
|
||||||
|
"Structures.md",
|
||||||
|
"Traits.md",
|
||||||
|
"Variables.md",
|
||||||
|
"Vector.md",
|
||||||
|
"Reducing.md",
|
||||||
|
"crates.io.md",
|
||||||
|
"does_not_compile.svg",
|
||||||
"Untitled.canvas",
|
"Untitled.canvas",
|
||||||
"Enums.md",
|
|
||||||
"Packages and Crates.md",
|
"Packages and Crates.md",
|
||||||
"Good and Bad Code/Commenting Pratices",
|
"Good and Bad Code/Commenting Pratices",
|
||||||
"Good and Bad Code",
|
"Good and Bad Code"
|
||||||
"Data Types.md",
|
|
||||||
"Variables.md",
|
|
||||||
"Constants.md"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -21,5 +21,5 @@ choosing the right one is a skill that is developed over time
|
|||||||
# Summary
|
# Summary
|
||||||
Here are some exercise that should be able to solve after reading through some of the common collections in the std library
|
Here are some exercise that should be able to solve after reading through some of the common collections in the std library
|
||||||
- Given a list of integers, use a vector and return the median (when sorted, the value in the middle position) and mode (the value that occurs most often; a hash map will be helpful here) of the list.
|
- Given a list of integers, use a vector and return the median (when sorted, the value in the middle position) and mode (the value that occurs most often; a hash map will be helpful here) of the list.
|
||||||
- Convert strings to pig latin. The first consonant of each word is moved to the end of the word and ay is added, so first becomes irst-fay. Words that start with a vowel have hay added to the end instead (apple becomes apple-hay). Keep in mind the details about UTF-8 encoding!
|
- Convert strings to pig Latin. The first consonant of each word is moved to the end of the word and ay is added, so first becomes irst-fay. Words that start with a vowel have hay added to the end instead (apple becomes apple-hay). Keep in mind the details about UTF-8 encoding!
|
||||||
- Using a hash map and vectors, create a text interface to allow a user to add employee names to a department in a company; for example, “Add Sally to Engineering” or “Add Amir to Sales.” Then let the user retrieve a list of all people in a department or all people in the company by department, sorted alphabetically.
|
- Using a hash map and vectors, create a text interface to allow a user to add employee names to a department in a company; for example, “Add Sally to Engineering” or “Add Amir to Sales.” Then let the user retrieve a list of all people in a department or all people in the company by department, sorted alphabetically.
|
@ -1,34 +1,34 @@
|
|||||||
# Error Handing
|
# Error Handing
|
||||||
|
|
||||||
This is a factor of life in software,
|
This is a factor of life in software,
|
||||||
Rust has a number of features for handling errors. One feature is that Rust requires you to acknowledge the possibility of an error and take some action beofre our code will compile.
|
Rust has a number of features for handling errors. One feature is that Rust requires you to acknowledge the possibility of an error and take some action before our code will compile.
|
||||||
|
|
||||||
This requirement ensures that errors are handled before the possiblity could arise
|
This requirement ensures that errors are handled before the possibility could arise
|
||||||
|
|
||||||
This can be split into two major categories
|
This can be split into two major categories
|
||||||
- [*Recoverable*](#recoverable-errors) - File a file not found, just need to report the problem to the user and retry the operation
|
- [*Recoverable*](#recoverable-errors) - File a file not found, just need to report the problem to the user and retry the operation
|
||||||
- [*Unrecoverable*](#unrecoverable-errors) - A symptom of bugs, like trying to access a location beyond the end of an array. Need to immediately stop the program
|
- [*Unrecoverable*](#unrecoverable-errors) - A symptom of bugs, like trying to access a location beyond the end of an array. Need to immediately stop the program
|
||||||
|
|
||||||
Many languages dont distinguish between the two kinds of errors and handle them the same way using mechanisms such as exceptions
|
Many languages don't distinguish between the two kinds of errors and handle them the same way using mechanisms such as exceptions
|
||||||
|
|
||||||
Rust does not have exceptions
|
Rust does not have exceptions
|
||||||
|
|
||||||
Instead it has the type `Result< T, E>` for recoverable errors
|
Instead it has the type `Result< T, E>` for recoverable errors
|
||||||
|
|
||||||
It has the `panc!` macro to stop eecution when an unrecoverable error occurs
|
It has the `panc!` macro to stop execution when an unrecoverable error occurs
|
||||||
|
|
||||||
## Unrecoverable Errors
|
## Unrecoverable Errors
|
||||||
Whne bad things happen in your code and nothing you can do nothing about it then Rust has the `panc!` macro
|
When bad things happen in your code and nothing you can do nothing about it then Rust has the `panc!` macro
|
||||||
|
|
||||||
There are two ways to cause a panic:
|
There are two ways to cause a panic:
|
||||||
- by taking an action that causes the code to paic (like accessing an array past the end)
|
- by taking an action that causes the code to panic (like accessing an array past the end)
|
||||||
- explicity calling `panic!` macro
|
- explicitly calling `panic!` macro
|
||||||
|
|
||||||
By default these print a failure message, unwind, clean up the stack and then quit.
|
By default these print a failure message, unwind, clean up the stack and then quit.
|
||||||
|
|
||||||
Using an environment variable you can also have Rust display the call stack when a panic occurs. This can make it easier to track down the source of the panic
|
Using an environment variable you can also have Rust display the call stack when a panic occurs. This can make it easier to track down the source of the panic
|
||||||
|
|
||||||
When a call to `panic!` occurs the error message will be contained in the last two lines. The first line will contain our message and the second is when te source of this panic occured
|
When a call to `panic!` occurs the error message will be contained in the last two lines. The first line will contain our message and the second is when the source of this panic occurred
|
||||||
|
|
||||||
example
|
example
|
||||||
```rust
|
```rust
|
||||||
|
@ -8,14 +8,14 @@ One of these tools is *generics*
|
|||||||
|
|
||||||
They are abstract stand-ins for concrete types or other properties
|
They are abstract stand-ins for concrete types or other properties
|
||||||
|
|
||||||
We can express the behavior of generics or how they relate to other generics without knowing what type that will be in place when copiling and running the code.
|
We can express the behavior of generics or how they relate to other generics without knowing what type that will be in place when compiling and running the code.
|
||||||
|
|
||||||
Functions can either take parameters of some generic type or a concrete type (like a `i32` or `String`) in the same way they take parameters with unknwon values to run the same code on multiple concrete values
|
Functions can either take parameters of some generic type or a concrete type (like a `i32` or `String`) in the same way they take parameters with unknown values to run the same code on multiple concrete values
|
||||||
|
|
||||||
One examle where concrete values were already used was with `Option<T>`, `Vec<T>`, `HashMap<K, V>` and `Result<T, E>`
|
One example where concrete values were already used was with `Option<T>`, `Vec<T>`, `HashMap<K, V>` and `Result<T, E>`
|
||||||
|
|
||||||
This chapter covers 3 things
|
This chapter covers 3 things
|
||||||
1. [Reducing Code duplication](Reducing Code Duplication.md)
|
1. [Reducing Code duplication](Reducing_Code_Duplication.md)
|
||||||
1. [Generics](Generics.md)
|
1. [Generics](Generics.md)
|
||||||
1. [Traits](Traits.md)
|
1. [Traits](Traits.md)
|
||||||
1. [Lifetimes](Lifetimes.md)
|
1. [Lifetimes](Lifetimes.md)
|
@ -1,5 +1,5 @@
|
|||||||
# Generic Data Types
|
# Generic Data Types
|
||||||
These are used to create definitions for items like function signatures or sturctures, where it is then used with many different concrete data types
|
These are used to create definitions for items like function signatures or structures, where it is then used with many different concrete data types
|
||||||
|
|
||||||
## In Function Definitions
|
## In Function Definitions
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user