Demo Rust hello server from Rust book.
Contains collection of Rust design patterns:
- create OS native threads with
std::thread; - thread communication with
std::sync::mpsc channel; - use
Arc<Mutex<...>>for safe share receiver end between threads (use channel as shared queue); - passing job closure to worker theads (use trait object type
Box<dyn FnOnce() + Send + 'static>for it); - simple use Tcp Listener;
- use
Option<...>enum totake()some value from mutable self reference (moveJoinHandlervalue from self tojoin()); - use type alias;
- impl
Droptrait for gracefull shutdown.