basic/match-pattern/pattern-match #664
Replies: 39 comments 27 replies
-
模式匹配有可驳模式和不可驳模式两种。 |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
新知识 get,原来处处都是模式匹配 |
Beta Was this translation helpful? Give feedback.
-
把模式(pattern)看作正则表达式就好理解多了 |
Beta Was this translation helpful? Give feedback.
-
感觉好奇怪啊这个东西。。。 |
Beta Was this translation helpful? Give feedback.
-
反复看了几遍 |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
感觉非常像ts的解构赋值啊 |
Beta Was this translation helpful? Give feedback.
-
可辩驳性:模式是否会无法匹配§ 可辨驳的(对于某些可能的值,无法进行匹配的模式)例如if let Some(x) = a_value,当右边是None是就无法匹配 |
Beta Was this translation helpful? Give feedback.
-
匹配模式是rust的一种语法。 |
Beta Was this translation helpful? Give feedback.
-
感觉模式匹配的思想与 Coq 中“构造子”的思想很像 |
Beta Was this translation helpful? Give feedback.
-
没太明白 |
Beta Was this translation helpful? Give feedback.
-
let my_vec = [Some(1), Some(2), Some(3), Some(4), None, Some(6)];
let mut case5 = Vec::from(my_vec);
while let Some(tp) = case5.pop() {
println!("case success {:?}", tp);
} 为什么这段代码会产生: 这样的结果,难道不应该是在-2 索引时候退出 while 吗 Some(None) 是 while let 覆盖的结果? |
Beta Was this translation helpful? Give feedback.
-
人是不是越来越少了,评论少了不少 |
Beta Was this translation helpful? Give feedback.
-
done |
Beta Was this translation helpful? Give feedback.
-
if let是不是还有一种更好记忆的方式, (其实人家已经匹配了所有情况了,只是其余情况都在else里呢,哈哈(✿◡‿◡)) |
Beta Was this translation helpful? Give feedback.
-
请教一下在函数 |
Beta Was this translation helpful? Give feedback.
-
Vec 类型的 pop 方法返回一个 Option |
Beta Was this translation helpful? Give feedback.
-
Ok 是 Rust 中 Result 枚举的一部分。Result 枚举用于表示操作的结果,它可以是成功(Ok)或失败(Err) |
Beta Was this translation helpful? Give feedback.
-
let else匹配中,为什么说后面的代码块一定需要发散代码块处理? |
Beta Was this translation helpful? Give feedback.
-
//当while let遇到嵌套Options时 // } |
Beta Was this translation helpful? Give feedback.
-
求这一部分的练习题 :) |
Beta Was this translation helpful? Give feedback.
-
好难啊好难 |
Beta Was this translation helpful? Give feedback.
-
let else解决了没法在unwrap_or_else()里使用break return之类的痛点 |
Beta Was this translation helpful? Give feedback.
-
let (a, b): (bool,bool) = (true, false); |
Beta Was this translation helpful? Give feedback.
-
有关绑定,我的理解 |
Beta Was this translation helpful? Give feedback.
-
其实这样理解就好了: |
Beta Was this translation helpful? Give feedback.
-
1.88的版本增加了更方便的方法: |
Beta Was this translation helpful? Give feedback.
-
let-else(Rust 1.65 新增) use std::str::FromStr; fn get_count_item(s: &str) -> (u64, &str) { fn main() { // if let // let-else 最后这段儿东西 我觉得, 讲的是乱七八糟 术语横飞 例子1 let x = match x {
Some(x) => x,
_ => return, // 或 panic!(), break 等
}; 例子2 使用语法糖 |
Beta Was this translation helpful? Give feedback.
-
每次回来看都能学到新知识 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
basic/match-pattern/pattern-match
https://course.rs/basic/match-pattern/pattern-match.html
Beta Was this translation helpful? Give feedback.
All reactions