Skip to content

Commit

Permalink
Merge pull request #38 from rubdos/spelling
Browse files Browse the repository at this point in the history
Fix spelling and grammar
  • Loading branch information
hdoordt authored Jun 19, 2023
2 parents 594a530 + 06e33dd commit 38d2629
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
4 changes: 2 additions & 2 deletions exercises/book/A3-traits-generics/mod.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## A3 Local Storage Vec
In this exercise, we'll create a type called `LocalStorageVec`, which is generic list of items that resides either on the stack or the heap, depending on its size. If its size is small enough for items to be put on the stack, the `LocalStorageVec` buffer is backed by an array. `LocalStorageVec` is not only generic over the type (`T`) of items in the list, but also by the size (`N`) of this stack-located array using a relatively new feature called ["const generics"](https://doc.rust-lang.org/reference/items/generics.html#const-generics). Once the `LocalStorageVec` contains more items than fit in the array, a heap based [`Vec`](https://doc.rust-lang.org/std/vec/struct.Vec.html) is allocated as space for the items to reside in.

**Within this exercise, the objectives are annotated with a number of stars (⭐), indicating the difficulty. You are likely not to be able to finish all exercises during the turorial session**
**Within this exercise, the objectives are annotated with a number of stars (⭐), indicating the difficulty. You are likely not to be able to finish all exercises during the tutorial session**

**Questions**
1. When is such a data structure more efficient than a standard `Vec`?
Expand Down Expand Up @@ -49,7 +49,7 @@ pub enum LocalStorageVec<T, const N: usize> {
```
</details>

### A3.B `impl`-ing `From<Vec<T>`
### A3.B `impl`-ing `From<Vec<T>>`

Uncomment the test `it_from_vecs`, and add an implementation for `From<Vec<T>>` to `LocalStorageVec<T>`. To do so, copy the following code in your `lib.rs` file and replace the `todo!` macro invocation with your code that creates a heap-based `LocalStorageVec` containing the passed `Vec<T>`.

Expand Down
26 changes: 13 additions & 13 deletions slides/A1-intro-to-rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ layout: default
layout: section
---

# Anyone have experience with Rust?
# Anyone has experience with Rust?

---
layout: cover
Expand Down Expand Up @@ -208,7 +208,7 @@ error[E0384]: cannot assign twice to immutable variable `some_x`
| help: consider making this binding mutable: `mut some_x`
3 | println!("some_x = {}", some_x);
4 | some_x = 6;
| ^^^^^^^^^^ c annot assign twice to immutable variable
| ^^^^^^^^^^ cannot assign twice to immutable variable
For more information about this error, try `rustc --explain E0384`.
error: could not compile `hello-world` due to previous error
Expand All @@ -219,7 +219,7 @@ error: could not compile `hello-world` due to previous error
</v-click>

<!--
- By convention rust uses snake case (i.e. all lowercase with underscores) for
- By convention Rust uses snake case (i.e. all lowercase with underscores) for
variable names
- The immutable variable cannot be mutated in any way (exceptions apply)
-->
Expand Down Expand Up @@ -327,8 +327,8 @@ fn main() {
}
```

- `f32`: single precision (32 bit) floating point number
- `f64`: double precision (64 bit) floating point number
- `f32`: single precision (32-bit) floating point number
- `f64`: double precision (64-bit) floating point number

<!--
- Rust uses f64 by default
Expand Down Expand Up @@ -429,12 +429,12 @@ fn main() {
}
```

- A character is a 32 bit unicode scalar value
- A character is a 32-bit unicode scalar value
- Very much unlike C/C++ where char is 8 bits

<!--
- The final scalar type is the character, but it isn't often seen.
- Note that it is not the same as u8 (a byte) in rust, and cannot be used
- Note that it is not the same as u8 (a byte) in Rust, and cannot be used
interchangeably.
- We'll see later that strings do not use chars, but are encoded as UTF-8
instead.
Expand All @@ -445,12 +445,12 @@ instead.
# Strings
```rust
// Owned, heap-allocated string *slice*
let s1: String = String::from("Hello, 🌍!");
let s1: String = String::new("Hello, 🌍!");
```

- Rust strings are UTF-8-encoded
- Unlike C/C++: *Not null-terminated*
- Cannot be indexed like C Strings
- Cannot be indexed like C strings
- Actually many types of strings in Rust

<!--
Expand Down Expand Up @@ -599,7 +599,7 @@ expression
the return type
- Unit may be omitted, note the syntax looks like an empty tuple: a tuple with
no value members has no instances, just as with unit.
- In rust you must always specify your type signatures for function boundaries
- In Rust you must always specify your type signatures for function boundaries
-->

---
Expand Down Expand Up @@ -736,7 +736,7 @@ we need them somewhere else
- We don't want to pass a copy all the time
- Large data that we do not want to copy
- Modifying original data
- What about datastructures with a variable size?
- What about data structures with a variable size?

::right::

Expand Down Expand Up @@ -891,7 +891,7 @@ The stack has limitations though, because it only grows as a result of a
function call.

* Size of items on stack frame must be known at compile time
* If I don't know the size of a variable upfront: What size should my stack
* If I don't know the size of a variable up front: What size should my stack
frame be?
* How can I handle arbitrary user input efficiently?

Expand Down Expand Up @@ -1227,7 +1227,7 @@ layout: default
* Loads of syntax
* Values are owned by variables
* Values may be moved to new owners or copied
* Some typse may be explicitly `Clone`d
* Some types may be explicitly `Clone`d

---
layout: default
Expand Down
21 changes: 11 additions & 10 deletions slides/A2-advanced-intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Advanced Rust syntax
# Ownership
We previously talked about ownership

* In rust there is always a single owner for each stack value
* In Rust there is always a single owner for each stack value
* Once the owner goes out of scope any associated values should be cleaned up
* Copy types creates copies, all other types are *moved*

Expand Down Expand Up @@ -63,7 +63,7 @@ fn calculate_length(s: String) -> usize {
borrow it from them, but eventually you have to give it back
- If a value is borrowed, it is not moved and the ownership stays with the
original owner
- To borrow in rust, we create a *reference*
- To borrow in Rust, we create a *reference*

```rust {all|3|7|all}
fn main() {
Expand Down Expand Up @@ -197,7 +197,7 @@ These rules are enforced by the Rust compiler.
Combined with the ownership model we can be sure that whole classes of errors
cannot occur.

* Rust is memory safe without having to use any runtime background proces such
* Rust is memory safe without having to use any runtime background process such
as a garbage collector
* But we still get the performance of a language that would normally let you
manage memory manually
Expand Down Expand Up @@ -512,6 +512,7 @@ fn accept_home(ip: IpAddress) {
_ => {
println!("You are not home");
},
}
}
```

Expand Down Expand Up @@ -550,7 +551,7 @@ struct PointFloat(f64, f64);
struct PointInt(i64, i64);
```

We are repeating ourselves here, what if we could write a datastructure for
We are repeating ourselves here, what if we could write a data structure for
both of these cases?

<v-click>
Expand Down Expand Up @@ -1052,7 +1053,7 @@ There are several reasons to box a variable on the heap

* When something is too large to move around
* We need something that is sized dynamically
* For writing recursive datastructures
* For writing recursive data structures

```rust
struct Node {
Expand All @@ -1068,7 +1069,7 @@ There are several reasons to box a variable on the heap

* When something is too large to move around
* We need something that is sized dynamically
* For writing recursive datastructures
* For writing recursive data structures

```rust
struct Node {
Expand Down Expand Up @@ -1128,7 +1129,7 @@ to support summing up only parts of a vector?
* Contiguous: elements are layed out in memory such that they are evenly spaced
* Dynamically sized: the size of the slice is not stored in the type, but is
determined at runtime
* View: a slice is never an owned datastructure
* View: a slice is never an owned data structure
* Slices are typed as `[T]`, where `T` is the type of the elements in the slice

---
Expand Down Expand Up @@ -1168,7 +1169,7 @@ help: function arguments must have a statically known size, borrowed types alway

<!--
- This cannot compile because [T] cannot exist on its own because it is never
an owned datastructure
an owned data structure
- We must always put slices behind a pointer type
-->

Expand Down Expand Up @@ -1419,7 +1420,7 @@ It should be possible to have a reference to part of a string. But what is it?
| - | `String` | `&str` |

* There is no static variant of str
* This would only be useful if we wanted strings of an extact length
* This would only be useful if we wanted strings of an exact length
* But just like we had the static slice literals, we can use `&'static str`
literals for that instead!

Expand Down Expand Up @@ -1460,7 +1461,7 @@ fn string_len(data: &str) -> usize {
* Define methods and associated functions with impl blocks
* Use `Vec<T>` for growable array storage
* Use `Box<T>` to put something on the heap
* Use slices whenever possible instead of owned Vec and String types
* Use slices whenever possible instead of owned `Vec<T>` and `String` types

---

Expand Down
2 changes: 1 addition & 1 deletion slides/A3-traits-generics.md
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ layout: default
# What lifetime?

- References refer to variable
- Varable has a lifetime:
- Variable has a lifetime:
- Start at declaration
- End at drop

Expand Down

0 comments on commit 38d2629

Please sign in to comment.