본문 바로가기

Rust

타입 가드

타입가드: 변수의 타입을 더 구체적이게 좁혀나간다.
 

*mutex=10 정수 타입을 추론하지 못한다. **mutex라고 정정하면 Mutex<T>에 값T를 역참조해서 정수 타입을 얻어 타입 추론에 성공한다

 
참고자료
https://doc.rust-lang.org/std/sync/struct.Mutex.html

Mutex in std::sync - Rust

Calls U::from(self). That is, this conversion is whatever the implementation of From for U chooses to do.

doc.rust-lang.org

 

'Rust' 카테고리의 다른 글

Rust 스레드 파킹  (0) 2024.02.04
Rust 스레드 조건 변수 대기와 알림  (0) 2024.02.04
Rust Mutex 스레드  (0) 2024.01.27
자바스크립트 러스트 클로저 비교, 메모리관리  (0) 2024.01.26
Rust Closure  (0) 2024.01.24