什么时候在Rust中使用ref?
我注意到Microsoft 的 Take your first steps with Rust 中的代码:
fn count_letters(text: &str) -> usize {
text.chars().filter(|ref c| c.is_alphabetic()).count()
}
很明显,没有ref.
为什么ref用在这里?我应该什么时候使用ref?这里有什么惯用的编程实践吗?
我注意到Microsoft 的 Take your first steps with Rust 中的代码:
fn count_letters(text: &str) -> usize {
text.chars().filter(|ref c| c.is_alphabetic()).count()
}
很明显,没有ref.
为什么ref用在这里?我应该什么时候使用ref?这里有什么惯用的编程实践吗?