File tree 7 files changed +14
-11
lines changed
creational/singleton/how-to-create
7 files changed +14
-11
lines changed Original file line number Diff line number Diff line change 15
15
16
16
steps :
17
17
- uses : actions/checkout@v2
18
- - name : Use Rust 1.53
19
- run : rustup install 1.53
20
18
- name : Run Rustfmt
21
19
run : cargo fmt -- --check
22
20
- name : Run Clippy
43
41
- run : cargo run --bin simple-factory
44
42
- run : cargo run --bin singleton-local
45
43
- run : cargo run --bin singleton-lazy
46
- # - run: cargo run --bin singleton-mutex # Requires Rust 1.63
44
+ - run : cargo run --bin singleton-mutex
47
45
- run : cargo run --bin singleton-once
48
46
- run : cargo run --bin singleton-logger
49
47
- run : cargo run --bin static-creation-method
Original file line number Diff line number Diff line change 1
1
[workspace ]
2
+ resolver = " 2"
2
3
3
4
members = [
4
5
" behavioral/chain-of-responsibility" ,
@@ -30,3 +31,6 @@ members = [
30
31
" structural/flyweight" ,
31
32
" structural/proxy" ,
32
33
]
34
+
35
+ [patch .crates-io ]
36
+ draw = { git = " https://github.com/fadeevab/draw" , branch = " master" }
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ The repository is developed to be a part of the
18
18
19
19
## 🔧 Requirements
20
20
21
- These examples have been tested with a _ stable_ ` rustc 1.62 ` (2021 edition).
21
+ These examples have been tested with a _ stable_ ` rustc 1.82 ` (2021 edition).
22
22
23
23
All examples can be launched via the command line, using ` cargo ` as follows:
24
24
@@ -61,7 +61,7 @@ cargo run --bin prototype
61
61
cargo run --bin simple-factory
62
62
cargo run --bin singleton-local
63
63
cargo run --bin singleton-lazy
64
- cargo run --bin singleton-mutex # Requires Rust 1.63
64
+ cargo run --bin singleton-mutex
65
65
cargo run --bin singleton-once
66
66
cargo run --bin singleton-logger
67
67
cargo run --bin static-creation-method
Original file line number Diff line number Diff line change @@ -97,8 +97,7 @@ cargo run --bin singleton-once
97
97
⚠ Starting with ` rustc 1.63 ` .
98
98
99
99
> Starting with ` Rust 1.63 ` , it can be easier to work with global mutable
100
- > singletons, although it's still preferable to avoid global variables in most
101
- > cases.
100
+ > singletons.
102
101
>
103
102
> Now that ` Mutex::new ` is ` const ` , you can use global static ` Mutex ` locks
104
103
> without needing lazy initialization.
Original file line number Diff line number Diff line change 2
2
//! https://stackoverflow.com/questions/27791532/how-do-i-create-a-global-mutable-singleton
3
3
//!
4
4
//! Starting with Rust 1.63, it can be easier to work with global mutable
5
- //! singletons, although it's still preferable to avoid global variables in most
6
- //! cases.
5
+ //! singletons.
7
6
//!
8
7
//! Now that `Mutex::new` is `const`, you can use global static `Mutex` locks
9
8
//! without needing lazy initialization.
Original file line number Diff line number Diff line change
1
+ #![ allow( unused) ]
1
2
mod device;
2
3
mod remotes;
3
4
@@ -13,11 +14,13 @@ fn test_device(device: impl Device + Clone) {
13
14
println ! ( "Tests with basic remote." ) ;
14
15
let mut basic_remote = BasicRemote :: new ( device. clone ( ) ) ;
15
16
basic_remote. power ( ) ;
17
+ basic_remote. volume_up ( ) ;
16
18
basic_remote. device ( ) . print_status ( ) ;
17
19
18
20
println ! ( "Tests with advanced remote." ) ;
19
21
let mut advanced_remote = AdvancedRemote :: new ( device) ;
20
22
advanced_remote. power ( ) ;
21
- advanced_remote. mute ( ) ;
23
+ advanced_remote. volume_down ( ) ;
24
+ advanced_remote. mute ( ) ; // Extended functionality of the advanced remote.
22
25
advanced_remote. device ( ) . print_status ( ) ;
23
26
}
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ fn main() {
6
6
// A buffered reader decorates a vector reader which wraps input data.
7
7
let mut input = BufReader :: new ( Cursor :: new ( "Input data" ) ) ;
8
8
9
- input. read ( & mut buf) . ok ( ) ;
9
+ input. read_exact ( & mut buf) . ok ( ) ;
10
10
11
11
print ! ( "Read from a buffered reader: " ) ;
12
12
You can’t perform that action at this time.
0 commit comments