1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2024-12-02 11:03:18 +02:00

Remove explicit typing in Mutex example (#405)

Example contained unnecessary explicit type info for the vector in Mutex v. Rust will magically do the needful conversions for us. Code looks cleaner/simpler without the explicit typing.
This commit is contained in:
Matt Smith 2023-02-14 18:40:22 +01:00 committed by GitHub
parent 8ff5a54599
commit 916c297d8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,11 +7,10 @@ behind a read-only interface:
use std::sync::Mutex;
fn main() {
let v: Mutex<Vec<i32>> = Mutex::new(vec![10, 20, 30]);
let v = Mutex::new(vec![10, 20, 30]);
println!("v: {:?}", v.lock().unwrap());
{
let v: &Mutex<Vec<i32>> = &v;
let mut guard = v.lock().unwrap();
guard.push(40);
}