File tree Expand file tree Collapse file tree 7 files changed +14
-11
lines changed
creational/singleton/how-to-create Expand file tree Collapse file tree 7 files changed +14
-11
lines changed Original file line number Diff line number Diff line change 1515
1616 steps :
1717 - uses : actions/checkout@v2
18- - name : Use Rust 1.53
19- run : rustup install 1.53
2018 - name : Run Rustfmt
2119 run : cargo fmt -- --check
2220 - name : Run Clippy
4341 - run : cargo run --bin simple-factory
4442 - run : cargo run --bin singleton-local
4543 - run : cargo run --bin singleton-lazy
46- # - run: cargo run --bin singleton-mutex # Requires Rust 1.63
44+ - run : cargo run --bin singleton-mutex
4745 - run : cargo run --bin singleton-once
4846 - run : cargo run --bin singleton-logger
4947 - run : cargo run --bin static-creation-method
Original file line number Diff line number Diff line change 11[workspace ]
2+ resolver = " 2"
23
34members = [
45 " behavioral/chain-of-responsibility" ,
@@ -30,3 +31,6 @@ members = [
3031 " structural/flyweight" ,
3132 " structural/proxy" ,
3233]
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
1818
1919## 🔧 Requirements
2020
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).
2222
2323All examples can be launched via the command line, using ` cargo ` as follows:
2424
@@ -61,7 +61,7 @@ cargo run --bin prototype
6161cargo run --bin simple-factory
6262cargo run --bin singleton-local
6363cargo run --bin singleton-lazy
64- cargo run --bin singleton-mutex # Requires Rust 1.63
64+ cargo run --bin singleton-mutex
6565cargo run --bin singleton-once
6666cargo run --bin singleton-logger
6767cargo run --bin static-creation-method
Original file line number Diff line number Diff line change @@ -97,8 +97,7 @@ cargo run --bin singleton-once
9797⚠ Starting with ` rustc 1.63 ` .
9898
9999> 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.
102101>
103102> Now that ` Mutex::new ` is ` const ` , you can use global static ` Mutex ` locks
104103> without needing lazy initialization.
Original file line number Diff line number Diff line change 22//! https://stackoverflow.com/questions/27791532/how-do-i-create-a-global-mutable-singleton
33//!
44//! 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.
76//!
87//! Now that `Mutex::new` is `const`, you can use global static `Mutex` locks
98//! without needing lazy initialization.
Original file line number Diff line number Diff line change 1+ #![ allow( unused) ]
12mod device;
23mod remotes;
34
@@ -13,11 +14,13 @@ fn test_device(device: impl Device + Clone) {
1314 println ! ( "Tests with basic remote." ) ;
1415 let mut basic_remote = BasicRemote :: new ( device. clone ( ) ) ;
1516 basic_remote. power ( ) ;
17+ basic_remote. volume_up ( ) ;
1618 basic_remote. device ( ) . print_status ( ) ;
1719
1820 println ! ( "Tests with advanced remote." ) ;
1921 let mut advanced_remote = AdvancedRemote :: new ( device) ;
2022 advanced_remote. power ( ) ;
21- advanced_remote. mute ( ) ;
23+ advanced_remote. volume_down ( ) ;
24+ advanced_remote. mute ( ) ; // Extended functionality of the advanced remote.
2225 advanced_remote. device ( ) . print_status ( ) ;
2326}
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ fn main() {
66 // A buffered reader decorates a vector reader which wraps input data.
77 let mut input = BufReader :: new ( Cursor :: new ( "Input data" ) ) ;
88
9- input. read ( & mut buf) . ok ( ) ;
9+ input. read_exact ( & mut buf) . ok ( ) ;
1010
1111 print ! ( "Read from a buffered reader: " ) ;
1212
You can’t perform that action at this time.
0 commit comments