-
Notifications
You must be signed in to change notification settings - Fork 1.1k
pattern-match/match-iflet #177
-
pattern-match/match-iflet
Learning Rust By Practice, narrowing the gap between beginner and skilled-dev with challenging examples, exercises and projects.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 18 -
🎉 5 -
❤️ 3 -
🚀 6
Replies: 55 comments 9 replies
-
done
Beta Was this translation helpful? Give feedback.
All reactions
-
done
Beta Was this translation helpful? Give feedback.
All reactions
-
"你可以在这里找到答案(在 solutions 路径下)",这句话的超链接指向有问题
Beta Was this translation helpful? Give feedback.
All reactions
-
done
Beta Was this translation helpful? Give feedback.
All reactions
-
Done.
Beta Was this translation helpful? Give feedback.
All reactions
-
done
Beta Was this translation helpful? Give feedback.
All reactions
-
Done.
Beta Was this translation helpful? Give feedback.
All reactions
-
2022年11月15日 Done.
Beta Was this translation helpful? Give feedback.
All reactions
-
down
Beta Was this translation helpful? Give feedback.
All reactions
-
练习6中为啥我这样写 会报错 error[E0425]: cannot find value i
in this scope
fn main() {
let o = Some(7);
if let o = Some(i) {
println!("This is a really long string and `{:?}`", i);
}
}
Beta Was this translation helpful? Give feedback.
All reactions
-
單純的語法誤解
if let Some(`新的(解開包裝後的)變數名稱`) = `目標解開包裝的變數` { ...snip } 正確答案在這邊 https://github.com/sunface/rust-by-practice/blob/master/solutions/pattern-match/match.md
Beta Was this translation helpful? Give feedback.
All reactions
-
fn main() { let o = Some(7); if let Some(i) = o { println!("This is a really long string and `{:?}`", i); } }
Beta Was this translation helpful? Give feedback.
All reactions
-
done
Beta Was this translation helpful? Give feedback.
All reactions
-
done
Beta Was this translation helpful? Give feedback.
All reactions
-
小白求教,课后题第三题中Message枚举中的Move后面为啥跟的是花括号
Beta Was this translation helpful? Give feedback.
All reactions
-
Move后是一个匿名结构体,所以是花括号。
Beta Was this translation helpful? Give feedback.
All reactions
-
在第四题中,我遇到一个想不明白的问题。
fn main() { let alphabets = ['a', 'E', 'Z', '0', 'x', '9' , 'Y']; // 使用 `matches` 填空 for ab in alphabets { // 这里为什么会断言通过呢 assert!(matches!(ab , i32 )); } }
matches!(ab , i32 )
返回的结果是true,为什么不是false呢?
Beta Was this translation helpful? Give feedback.
All reactions
-
这里的i32应该只是作为一个名称而非类型名吧, 就和换成a, b之类的名称一样含义。
Beta Was this translation helpful? Give feedback.
All reactions
-
这里还会有个警告 ^^^ help: if this is intentional, prefix it with an underscore: _i32
让你不要用i32作为名称
Beta Was this translation helpful? Give feedback.
All reactions
-
lala~
Beta Was this translation helpful? Give feedback.
All reactions
-
感觉rust中的字符范围表达式
应该是按照ascii码表来看是否连续的
第四题中 matches!(ab, ' '..='~') 也是没问题的
Beta Was this translation helpful? Give feedback.
All reactions
-
个人感觉应该是按照 char
以 UTF-8标准
映射出的 bytes
的 范围
来判断
Beta Was this translation helpful? Give feedback.
All reactions
-
个人感觉应该是按照
char
以UTF-8标准
映射出的bytes
的范围
来判断
确实,是我之前理解有问题,应该是按照char
的对应unicode
编码来进行范围判断的
,教程里面已经明确说了char
是按unicode
编码的,只是很多unicode字符平常实际不怎么用就是了😂
Beta Was this translation helpful? Give feedback.
All reactions
-
终于在这章领悟到变量解构了
Beta Was this translation helpful? Give feedback.
All reactions
-
done
Beta Was this translation helpful? Give feedback.
All reactions
-
done
Beta Was this translation helpful? Give feedback.
All reactions
-
Done!
Beta Was this translation helpful? Give feedback.
All reactions
-
感觉这节相对简单点
Beta Was this translation helpful? Give feedback.
All reactions
-
完成
Beta Was this translation helpful? Give feedback.
All reactions
-
done
Beta Was this translation helpful? Give feedback.
All reactions
-
done
Beta Was this translation helpful? Give feedback.
All reactions
-
Done ✅
Day 7
Beta Was this translation helpful? Give feedback.
All reactions
-
done
Beta Was this translation helpful? Give feedback.
All reactions
-
第5题好像还能这样写
enum MyEnum { Foo, Bar } fn main() { let mut count = 0; let v = vec![MyEnum::Foo,MyEnum::Bar,MyEnum::Foo]; for e in v { if let MyEnum::Foo = e { // 修复错误,只能修改本行代码 count += 1; } } assert_eq!(count, 2); }
Beta Was this translation helpful? Give feedback.
All reactions
-
done
Beta Was this translation helpful? Give feedback.
All reactions
-
Done
Beta Was this translation helpful? Give feedback.
All reactions
-
done
Beta Was this translation helpful? Give feedback.
All reactions
-
done
Beta Was this translation helpful? Give feedback.