Skip to content

Commit 119feb1

Browse files
authored
Merge branch 'master' into catch_panic_anti_pattern
2 parents 156a319 + 1a65aad commit 119feb1

File tree

19 files changed

+156
-119
lines changed

19 files changed

+156
-119
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"ignorePatterns": [
3+
{
4+
"pattern": "^(http|https)://crates.io/"
5+
}
6+
]
7+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Check Markdown links
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
8+
jobs:
9+
markdown-link-check:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@master
13+
- uses: gaurav-nelson/github-action-markdown-link-check@v1
14+
with:
15+
use-verbose-mode: 'yes'
16+
use-quiet-mode: 'yes'
17+
config-file: '.github/workflows/url-check-config.json'
18+
check-modified-files-only: 'yes'
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Check Markdown links Periodically
2+
3+
on:
4+
schedule:
5+
# Run everyday at 0:00 AM
6+
- cron: "0 0 * * *"
7+
8+
jobs:
9+
markdown-link-check:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@master
13+
- uses: gaurav-nelson/github-action-markdown-link-check@v1
14+
with:
15+
use-verbose-mode: 'yes'
16+
use-quiet-mode: 'yes'
17+
config-file: '.github/workflows/url-check-config.json'

CONTRIBUTING.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# Contributing
22

3-
## Discssion board
3+
## Discussion board
44

55
If you have a question or an idea regarding certain content but you want to have feedback of fellow community members
66
and you think it may not be appropriate to file an issue open a discussion in our [discussion board](https://github.com/rust-unofficial/patterns/discussions).
77

8-
98
## Writing a new article
109

1110
Before writing a new article please check our [issues](https://github.com/rust-unofficial/patterns/issues) and
@@ -29,9 +28,7 @@ with the [Wayback Machine](https://web.archive.org/) and use the link to that sn
2928

3029
Don't forget to add your new article to the `SUMMARY.md` to let it be rendered to the book.
3130

32-
Please make `Draft Pull requests` early so we can follow your progress and can give early feedback (see the following section).
33-
34-
31+
Please make `Draft Pull requests` early so we can follow your progress and can give early feedback (see the following section).
3532

3633
## Creating a Pull Request
3734

@@ -42,6 +39,11 @@ Early reviews of the community are not meant as an offense but to give feedback.
4239

4340
A good principle: "Work together, share ideas, teach others."
4441

42+
### Test the book locally before submitting
43+
44+
Before submitting the PR launch the commands `mdbook build` to make sure that the book builds and `mdbook test` to make sure that
45+
code examples are correct.
46+
4547
### Important Note
4648

4749
Please **don't force push** your branch to keep commit history and make it easier of us to see changes between reviews.

README.md

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,24 @@ An open source book about design patterns and idioms in the Rust programming
44
language that you can read [here](https://rust-unofficial.github.io/patterns/).
55

66

7-
## Contents
8-
9-
[Introduction](intro.md)
10-
7+
## TODOs
118

129
### Idioms
1310

14-
* [Constructor](idioms/ctor.md)
15-
* [Concatenating strings with `format!`](idioms/concat-format.md)
16-
* [Privacy for extensibility](idioms/priv-extend.md)
1711
* TODO stability for extensibility
1812
* TODO trait to separate visibility of methods from visibility of data (https://github.com/sfackler/rust-postgres/blob/v0.9.6/src/lib.rs#L1400)
19-
* [Collections are smart pointers](idioms/deref.md)
2013
* TODO leak amplification ("Vec::drain sets the Vec's len to 0 prematurely so that mem::forgetting Drain "only" mem::forgets more stuff. instead of exposing uninitialized memory or having to update the len on every iteration")
21-
* [Finalisation in destructors](idioms/dtor-finally.md)
2214
* TODO interior mutability - UnsafeCell, Cell, RefCell
23-
* [Iterating over an `Option`](idioms/option-iter.md)
24-
* [`Default` trait](idioms/default.md)
25-
* [Pass variables to closure](idioms/pass-var-to-closure.md)
26-
* [`mem::replace(_)` to avoid needless clones](idioms/mem-replace.md)
27-
* [Temporary mutability](idioms/temporary-mutability.md)
28-
* [On-Stack Dynamic Dispatch](idioms/on-stack-dyn-dispatch.md)
2915
* TODO FFI usage (By being mindful of how to provide Rust libraries, and make use of existing libraries across the FFI, you can get more out of benefits Rust can bring)
30-
* [Easy doc initialization](idioms/rustdoc-init.md)
3116

3217

3318
### Design patterns
3419

35-
* [Builder](patterns/builder.md)
36-
* [RAII guards](patterns/RAII.md)
37-
* [Newtype](patterns/newtype.md)
3820
* TODO iterators (to safely avoid bounds checks)
3921
* TODO closures and lifetimes (coupling to lifetime)
4022
* TODO platform-specific sub-modules (https://github.com/rust-lang/rfcs/blob/master/text/0517-io-os-reform.md#platform-specific-opt-in)
4123
* TODO Module organisation (by looking at examples such as Rusts `libstd`, and how it integrated into the Rusts source code, lessons can be learned about ergonomic project management and API design. Closely assosciated with platform-specific sub-modules)
42-
* [Entry API](patterns/entry.md) (TODO Currently just a boilerplate)
43-
* [Visitor](patterns/visitor.md)
44-
* [Fold](patterns/fold.md)
45-
* [Prefer small crates](patterns/small-crates.md)
46-
* [Contain unsafety in small modules](patterns/unsafe-mods.md)
24+
* [Entry API](patterns/entry.md) (Currently just a boilerplate)
4725
* TODO extension traits
4826
* TODO destructor bombs (ensure linear typing dynamically, e.g., https://github.com/Munksgaard/session-types/commit/0f25ccb7c3bc9f65fa8eaf538233e8fe344a189a)
4927
* TODO convertible to Foo trait for more generic generics (e.g., http://static.rust-lang.org/doc/master/std/fs/struct.File.html#method.open)
@@ -52,19 +30,16 @@ language that you can read [here](https://rust-unofficial.github.io/patterns/).
5230
* TODO composition of structs to please the borrow checker
5331
* TODO `Error` traits and `Result` forwarding
5432
* TODO graphs
55-
* [Compose structs together for better borrowing](patterns/compose-structs.md)
5633

5734

5835
### Anti-patterns
5936

6037
* [catch_unwind for exceptions](anti_patterns/catch_panic.md)
6138
* TODO Clone to satisfy the borrow checker
62-
* [Deref polymorphism](anti_patterns/deref.md)
6339
* TODO Matching all fields of a struct (back compat)
6440
* TODO wildcard matches
6541
* TODO taking an enum rather than having multiple functions
6642
* TODO `unwrap()`ing every `Result` instead of forwarding it
67-
* [`#[deny(warnings)]`](anti_patterns/deny-warnings.md)
6843

6944

7045
## Contributing

SUMMARY.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
- [Introduction](./intro.md)
44

5-
- [Idioms](./idioms/README.md)
5+
- [Idioms](./idioms/index.md)
66
- [Concatenating Strings with `format!`](./idioms/concat-format.md)
77
- [Constructor](./idioms/ctor.md)
88
- [The `Default` Trait](./idioms/default.md)
@@ -16,22 +16,21 @@
1616
- [Easy doc initialization](./idioms/rustdoc-init.md)
1717
- [Temporary mutability](./idioms/temporary-mutability.md)
1818

19-
- [Design Patterns](./patterns/README.md)
19+
- [Design Patterns](./patterns/index.md)
2020
- [Builder](./patterns/builder.md)
2121
- [Compose Structs](./patterns/compose-structs.md)
2222
- [Fold](./patterns/fold.md)
23-
- [Late Bound Bounds](./patterns/late-bounds.md)
2423
- [Newtype](./patterns/newtype.md)
2524
- [RAII Guards](./patterns/RAII.md)
2625
- [Prefer Small Crates](./patterns/small-crates.md)
2726
- [Contain unsafety in small modules](./patterns/unsafe-mods.md)
2827
- [Visitor](./patterns/visitor.md)
2928

30-
- [Anti-patterns](./anti_patterns/README.md)
29+
- [Anti-patterns](./anti_patterns/index.md)
3130
- [catch_unwind for exceptions](./anti_patterns/catch_panic.md)
3231
- [`#[deny(warnings)]`](./anti_patterns/deny-warnings.md)
3332
- [Deref Polymorphism](./anti_patterns/deref.md)
3433

35-
- [Functional Programming](./functional/README.md)
34+
- [Functional Programming](./functional/index.md)
3635

3736
- [Additional Resources](./additional_resources.md)
File renamed without changes.

functional/README.md renamed to functional/index.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ println!("{}", sum);
1515
With imperative programs, we have to play compiler to see what is happening. Here, we start with a `sum` of `0`. Next, we iterate through the range from 1 to 10. Each time through the loop, we add the corresponding value in the range. Then we print it out.
1616

1717
| `i` | `sum` |
18-
| --- | ----- |
19-
| 1 | 1 |
20-
| 2 | 3 |
21-
| 3 | 6 |
22-
| 4 | 10 |
23-
| 5 | 15 |
24-
| 6 | 21 |
25-
| 7 | 28 |
26-
| 8 | 36 |
27-
| 9 | 45 |
28-
| 10 | 55 |
18+
|:---:|:-----:|
19+
| 1 | 1 |
20+
| 2 | 3 |
21+
| 3 | 6 |
22+
| 4 | 10 |
23+
| 5 | 15 |
24+
| 6 | 21 |
25+
| 7 | 28 |
26+
| 8 | 36 |
27+
| 9 | 45 |
28+
| 10 | 55 |
2929

3030
This is how most of us start out programming. We learn that a program is a set of steps.
3131

@@ -40,14 +40,14 @@ Whoa! This is really different! What's going on here? Remember that with declara
4040
Here, we are composing functions of addition (this closure: `|a, b| a + b)`) with a range from 1 to 10. The `0` is the starting point, so `a` is `0` at first. `b` is the first element of the range, `1`. `0 + 1 = 1` is the result. So now we `fold` again, with `a = 1`, `b = 2` and so `1 + 2 = 3` is the next result. This process continues until we get to the last element in the range, `10`.
4141

4242
| `a` | `b` | result |
43-
| --- | --- | ------ |
44-
| 0 | 1 | 1 |
45-
| 1 | 2 | 3 |
46-
| 3 | 3 | 6 |
47-
| 6 | 4 | 10 |
48-
| 10 | 5 | 15 |
49-
| 15 | 6 | 21 |
50-
| 21 | 7 | 28 |
51-
| 28 | 8 | 36 |
52-
| 36 | 9 | 45 |
53-
| 45 | 10 | 55 |
43+
|:---:|:---:|:------:|
44+
| 0 | 1 | 1 |
45+
| 1 | 2 | 3 |
46+
| 3 | 3 | 6 |
47+
| 6 | 4 | 10 |
48+
| 10 | 5 | 15 |
49+
| 15 | 6 | 21 |
50+
| 21 | 7 | 28 |
51+
| 28 | 8 | 36 |
52+
| 36 | 9 | 45 |
53+
| 45 | 10 | 55 |

idioms/default.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ different names, but there can only be one `Default` implementation per type.
1919

2020
## Example
2121

22-
```rust,ignore
22+
```rust
23+
use std::{path::PathBuf, time::Duration};
24+
2325
// note that we can simply auto-derive Default here.
24-
#[derive(Default)]
26+
#[derive(Default, Debug)]
2527
struct MyConfiguration {
2628
// Option defaults to None
27-
output: Option<Path>,
29+
output: Option<PathBuf>,
2830
// Vecs default to empty vector
29-
search_path: Vec<Path>,
31+
search_path: Vec<PathBuf>,
3032
// Duration defaults to zero time
3133
timeout: Duration,
3234
// bool defaults to false
@@ -40,7 +42,9 @@ impl MyConfiguration {
4042
fn main() {
4143
// construct a new instance with default values
4244
let mut conf = MyConfiguration::default();
43-
// do somthing with conf here
45+
// do something with conf here
46+
conf.check = true;
47+
println!("conf = {:#?}", conf);
4448
}
4549
```
4650

idioms/dtor-finally.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ The finaliser must be assigned into a variable, otherwise it will be destroyed
7676
immediately, rather than when it goes out of scope. The variable name must start
7777
with `_` if the variable is only used as a finaliser, otherwise the compiler
7878
will warn that the finaliser is never used. However, do not call the variable
79-
`_` with no suffix - in that case it will be again be destroyed immediately.
79+
`_` with no suffix - in that case it will be destroyed immediately.
8080

8181
In Rust, destructors are run when an object goes out of scope. This happens
8282
whether we reach the end of block, there is an early return, or the program

0 commit comments

Comments
 (0)