Skip to content

Commit eaf1e6f

Browse files
committed
Fixing minor grammar issues and typo issues
1 parent 4429942 commit eaf1e6f

File tree

5 files changed

+79
-80
lines changed

5 files changed

+79
-80
lines changed

source/docs/b1.vectors.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
title: Vectors
22
---
33

4-
If you remember, array is a fixed-size list of elements, of same data type. Even with mut, its element count can not be changed. A vector is kind of **a re-sizable array** but **all elements must be in the same type**.
4+
If you remember, the array is a fixed-size list of elements, of the same data type. Even with mut, its element count cannot be changed. A vector is kind of **a re-sizable array** but **all elements must be in the same type**.
55

6-
⭐️ It’s a generic type, written as **`Vec<T>`** . T can have any type, ex. The type of a Vec of i32s is `Vec<i32>`. Also, Vectors always allocate their data in dynamically allocated heap.
6+
⭐️ It’s a generic type, written as **`Vec<T>`** . T can have any type, ex. The type of a Vec of i32s is `Vec<i32>`. Also, Vectors always allocate their data in a dynamically allocated heap.
77

88
### Create empty vector
99

1010
```rust
11-
let mut a = Vec::new(); //1.with new() keyword
12-
let mut b = vec![]; //2.using the vec! macro
11+
let mut a = Vec::new(); //1.With new() keyword
12+
let mut b = vec![]; //2.Using the vec! macro
1313
```
1414

1515
### Create with data types
1616

1717
```rust
1818
let mut a2: Vec<i32> = Vec::new();
1919
let mut b2: Vec<i32> = vec![];
20-
let mut b3 = vec![1i32, 2, 3];//sufixing 1st value with data type
20+
let mut b3 = vec![1i32, 2, 3];//Sufixing 1st value with data type
2121

2222
let mut b4 = vec![1, 2, 3];
2323
let mut b5: Vec<i32> = vec![1, 2, 3];
2424
let mut b6 = vec![1i32, 2, 3];
25-
let mut b7 = vec![0; 10]; //ten zeroes
25+
let mut b7 = vec![0; 10]; //Ten zeroes
2626
```
2727

2828
### Access and change data
@@ -32,7 +32,7 @@ let mut b7 = vec![0; 10]; //ten zeroes
3232
let mut c = vec![5, 4, 3, 2, 1];
3333
c[0] = 1;
3434
c[1] = 2;
35-
//c[6] = 2; can't assign values this way, index out of bounds
35+
//c[6] = 2; Cannot assign values this way, index out of bounds
3636
println!("{:?}", c); //[1, 2, 3, 2, 1]
3737

3838
//push and pop
@@ -55,13 +55,13 @@ e.push(11);
5555
```
5656

5757
⭐️ Mainly a vector represent 3 things,
58-
- a **pointer** to the data
58+
- A **pointer** to the data
5959
- **No of elements** currently have(**length**)
60-
- **capacity** (Amount of space allocated for any future elements).
60+
- **Capacity** (Amount of space allocated for any future elements).
6161

6262
If the length of a vector exceeds its capacity, its capacity will be increased automatically. But its elements will be reallocated(which can be slow). So always use Vec::**with_capacity** whenever it’s possible.
6363

64-
> 💡 **String** data type is a UTF-8 encoded vector. But you can not index into a String because of encoding.
64+
> 💡 The **String** data type is a UTF-8 encoded vector. But you can not index into a String because of encoding.
6565
6666

6767
💯 Vectors can be used with iterators in three ways,

source/docs/b2.structs.md

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
title: Structs
22
---
33

4-
⭐️ Structs are used to **encapsulate related properties** into one unified datatype.
4+
⭐️ Structs are used to **encapsulate related properties** into one unified data type.
55

66
💡 By convention, the name of the struct starts with a capital letter and follows **CamelCase**.
77

88
There are 3 variants of structs,
99
1. **C-like structs**
10-
* one or more comma separated name:value pairs
11-
* brace-enclosed list
12-
* similar to classes \(without its methods\) in OOP languages
13-
* because fields have names, we can access them through dot notation
10+
* One or more comma-separated name:value pairs
11+
* Brace-enclosed list
12+
* Similar to classes \(without its methods\) in OOP languages
13+
* Because fields have names, we can access them through dot notation
1414

1515
2. **Tuple structs**
16-
* one or more comma separated values
17-
* parenthesized list like tuples
18-
* looks like a named tuples
16+
* One or more comma-separated values
17+
* A parenthesized list like tuples
18+
* Looks like a named tuples
1919

2020
3. **Unit structs**
21-
* a struct with no members at all
22-
* it defines a new type but it resembles an empty tuple, \(\)
23-
* rarely in use, useful with generics
21+
* A struct with no members at all
22+
* It defines a new type but it resembles an empty tuple, \(\)
23+
* Rarely in use, useful with generics
2424

2525
⭐️ When regarding OOP in Rust, attributes and methods are placed separately on **structs** and **traits**. Structs contain only attributes, traits contain only methods. They are getting connected via **impls**.
2626

@@ -37,30 +37,30 @@ struct Color {
3737
}
3838

3939
fn main() {
40-
// creating an instance
40+
// Creating an instance
4141
let black = Color {red: 0, green: 0, blue: 0};
4242

43-
// accessing its fields using dot notation
43+
// Accessing its fields using dot notation
4444
println!("Black = rgb({}, {}, {})", black.red, black.green, black.blue); //Black = rgb(0, 0, 0)
4545

46-
// structs are immutable by default, use `mut` to make it mutable but doesn't support field level mutability
46+
// Structs are immutable by default, use `mut` to make it mutable but doesn't support field level mutability
4747
let mut link_color = Color {red: 0,green: 0,blue: 255};
4848
link_color.blue = 238;
4949
println!("Link Color = rgb({}, {}, {})", link_color.red, link_color.green, link_color.blue); //Link Color = rgb(0, 0, 238)
5050

51-
// copy elements from another instance
51+
// Copy elements from another instance
5252
let blue = Color {blue: 255, .. link_color};
5353
println!("Blue = rgb({}, {}, {})", blue.red, blue.green, blue.blue); //Blue = rgb(0, 0, 255)
5454

55-
// destructure the instance using a `let` binding, this will not destruct blue instance
55+
// Destructure the instance using a `let` binding, this will not destruct blue instance
5656
let Color {red: r, green: g, blue: b} = blue;
5757
println!("Blue = rgb({}, {}, {})", r, g, b); //Blue = rgb(0, 0, 255)
5858

59-
// creating an instance via functions & accessing its fields
59+
// Creating an instance via functions & accessing its fields
6060
let midnightblue = get_midnightblue_color();
6161
println!("Midnight Blue = rgb({}, {}, {})", midnightblue.red, midnightblue.green, midnightblue.blue); //Midnight Blue = rgb(25, 25, 112)
6262

63-
// destructure the instance using a `let` binding
63+
// Destructure the instance using a `let` binding
6464
let Color {red: r, green: g, blue: b} = get_midnightblue_color();
6565
println!("Midnight Blue = rgb({}, {}, {})", r, g, b); //Midnight Blue = rgb(25, 25, 112)
6666
}
@@ -72,31 +72,31 @@ fn get_midnightblue_color() -> Color {
7272

7373
## Tuple structs
7474

75-
⭐️ When a tuple struct has only one element, we call it **new type pattern**. Because it helps to create a new type.
75+
⭐️ When a tuple struct has only one element, we call it **newtype pattern**. Because it helps to create a new type.
7676

7777
```rust
78-
struct Color (u8, u8, u8);
78+
struct Color(u8, u8, u8);
7979
struct Kilometers(i32);
8080

8181
fn main() {
82-
// creating an instance
83-
let black = Color (0, 0, 0);
82+
// Creating an instance
83+
let black = Color(0, 0, 0);
8484

85-
// destructure the instance using a `let` binding, this will not destruct black instance
86-
let Color (r, g, b) = black;
85+
// Destructure the instance using a `let` binding, this will not destruct black instance
86+
let Color(r, g, b) = black;
8787
println!("Black = rgb({}, {}, {})", r, g, b); //black = rgb(0, 0, 0);
8888

89-
//newtype pattern
89+
// Newtype pattern
9090
let distance = Kilometers(20);
91-
// destructure the instance using a `let` binding
91+
// Destructure the instance using a `let` binding
9292
let Kilometers(distance_in_km) = distance;
9393
println!("The distance: {} km", distance_in_km); //The distance: 20 km
9494
}
9595
```
9696

9797
## Unit structs
9898

99-
This is rarely useful on its own, but in combination with other features it can become useful.
99+
This is rarely useful on its own. But in combination with other features, it can become useful.
100100

101101
> [📖](https://doc.rust-lang.org/book/first-edition/structs.html) ex: A library may ask you to create a structure that implements a certain trait to handle events. If you don’t have any data you need to store in the structure, you can create a unit-like struct.
102102

source/docs/b3.enums.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@ enum Day {
1414
Saturday
1515
}
1616

17-
// Day is the enum
17+
// The `Day` is the enum
1818
// Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday are the variants
1919
```
2020

21-
⭐️ Variants can be accessed through :: notation , ex. Day::Sunday
21+
⭐️ Variants can be accessed through :: notation, ex. Day::Sunday
2222

2323
⭐️ Each enum **variant** can have,
24-
* no data (unit variant)
25-
* unnamed ordered data (tuple variant)
26-
* named data (struct variant)
24+
* No data (unit variant)
25+
* Unnamed ordered data (tuple variant)
26+
* Named data (struct variant)
2727

2828

2929
```rust
3030
enum FlashMessage {
31-
Success, //a unit variant
32-
Warning{ category: i32, message: String }, //a struct variant
33-
Error(String) //a tuple variant
31+
Success, // A unit variant
32+
Warning{ category: i32, message: String }, // A struct variant
33+
Error(String) // A tuple variant
3434
}
3535

3636
fn main() {
@@ -45,11 +45,11 @@ fn main() {
4545
}
4646

4747
fn print_flash_message(m : FlashMessage) {
48-
// pattern matching with enum
48+
// Pattern matching with enum
4949
match m {
5050
FlashMessage::Success =>
5151
println!("Form Submitted correctly"),
52-
FlashMessage::Warning {category, message} => //Destructure, should use same field names
52+
FlashMessage::Warning {category, message} => // Destructure, should use same field names
5353
println!("Warning : {} - {}", category, message),
5454
FlashMessage::Error(msg) =>
5555
println!("Error : {}", msg)

source/docs/b4.generics.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ title: Generics
33

44
> [📖](https://doc.rust-lang.org/beta/book/first-edition/generics.html) Sometimes, when writing a function or data type, we may want it to work for multiple types of arguments. In Rust, we can do this with generics.
55
6-
💭 The concept is, instead of declaring a specific data type we use an uppercase letter(or CamelCase identifier). ex, **instead x : u8** we use **x : T** . but we have to inform to the compiler that T is a generic type(can be any type) by adding `<T>` at first.
6+
💭 The concept is, instead of declaring a specific data type we use an uppercase letter(or CamelCase identifier). ex, **instead of x : u8** we use **x : T** . but we have to inform to the compiler that T is a generic type(can be any type) by adding `<T>` at first.
77

88
### Generalizing functions
99

1010
```rust
1111
fn takes_anything<T>(x: T) { // x has type T, T is a generic type
1212
}
1313

14-
fn takes_two_of_the_same_things<T>(x: T, y: T) { // both x and y has same type
14+
fn takes_two_of_the_same_things<T>(x: T, y: T) { // Both x and y has the same type
1515
}
1616

17-
fn takes_two_things<T, U>(x: T, y: U) { // multiple types
17+
fn takes_two_things<T, U>(x: T, y: U) { // Multiple types
1818
}
1919
```
2020

@@ -31,8 +31,8 @@ fn main() {
3131
let point_b = Point { x: 0.0, y: 0.0 }; // T is a float type
3232
}
3333

34-
// 🔎 When addding an implementation for a generic struct, the type parameters should be declared after the impl as well
35-
// impl<T> Point<T> {
34+
// 🔎 When adding an implementation for a generic struct, the type parameters should be declared after the impl as well
35+
// impl<T> Point<T> {
3636
```
3737

3838
### Generalizing enums
@@ -58,28 +58,28 @@ enum Result<T, E> {
5858
```rust
5959
// 01 - - - - - - - - - - - - - - - - - - - - - -
6060
fn get_id_by_username(username: &str) -> Option<usize> {
61-
//if username can be found in the system, set userId
61+
// if username can be found in the system, set userId
6262
return Some(userId);
63-
//else
63+
// else
6464
None
6565
}
6666

67-
//💭 So on above function, instead of setting return type as usize
68-
// set return type as Option<usize>
69-
//Instead of return userId, return Some(userId)
70-
// else None (💡remember? last return statement no need return keyword and ending ;)
67+
// 💭 So, on the above function, instead of setting return type as usize
68+
// set return type as Option<usize>
69+
// Instead of return userId, return Some(userId)
70+
// else None (💡remember? last return statement no need return keyword and ending ;)
7171

7272
// 02 - - - - - - - - - - - - - - - - - - - - - -
7373
struct Task {
7474
title: String,
7575
assignee: Option<Person>,
7676
}
7777

78-
//💭 Instead of assignee: Person, we use Option<Person>
79-
//Because the task has not been assigned to a specific person
78+
// 💭 Instead of assignee: Person, we use Option<Person>
79+
// because the task has not been assigned to a specific person
8080

8181
// - - - - - - - - - - - - - - - - - - - - - - -
82-
//when using Option types as return types on functions
82+
// When using Option types as return types on functions
8383
// we can use pattern matching to catch the relevant return type(Some/None) when calling them
8484

8585
fn main() {
@@ -98,20 +98,20 @@ fn main() {
9898
```rust
9999
// - - - - - - - - - - - - - - - - - - - - - -
100100
fn get_word_count_from_file(file_name: &str) -> Result<u32, &str> {
101-
//if the file is not found on the system, return error
101+
// if the file is not found on the system, return error
102102
return Err("File can not be found!")
103-
//else, count and return the word count
104-
//let mut word_count: u32; ....
103+
// else, count and return the word count
104+
// let mut word_count: u32; ....
105105
Ok(word_count)
106106
}
107107

108-
//💭 on above function,
109-
// instead panic(break) the app, when a file can not be found; return Err(something)
108+
// 💭 On the above function,
109+
// instead panic(break) the app, when the file can not be found; return Err(something)
110110
// or when it could get the relevant data; return Ok(data)
111111

112112

113113
// - - - - - - - - - - - - - - - - - - - - - - -
114-
// we can use pattern matching to catch the relevant return type(Ok/Err) when calling it
114+
// We can use pattern matching to catch the relevant return type(Ok/Err) when calling it
115115

116116
fn main() {
117117
let mut file_name = "file_a";

0 commit comments

Comments
 (0)