Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

where Clauses

Đôi khi bạn sẽ có nhiều genenic type, mỗi generic type lại có nhiều trait bound, khiến code khó đọc. Rust có một cú pháp where cho phép định nghĩa trait bound phía sau function signature. Ví dụ:

fn some_function<T: Display + Clone, U: Clone + Debug>(t: &T, u: &U) -> i32 {

Với where clause:

fn some_function<T, U>(t: &T, u: &U) -> i32
    where T: Display + Clone,
	  U: Clone + Debug,
{