From here, I run the snippet code.
for _ in 0..10 {
let counter = Arc::clone(&counter);
let handle = thread::spawn(move || {
let mut num = counter.lock().unwrap();
*num += 1;
});
handles.push(handle);
}
When I type this sample code in an IDE, I have no idea what the type of num
is. I event don't know to use *
to dereference the value. But fortunately, the IDE helps me.
The link provides a useful message about the type of num
. I quote:
pointer called
MutexGuard
, wrapped in aLockResult
that we handled with the call to unwrap. TheMutexGuard
smart pointer implementsDeref
to point at our inner data;
My wondering is: as a beginner, how can I know or infer the data type in Rust? If I don't got the message in the link or I don't get help from the IDE, How could I get a sense of the returned data type in Rust?