struct X(Option<()>, Option<()>);
let x: Option<Result<X, ()>>;
match x {
Some(Ok(a)) if let Some(b) = a.0 && let Some(b) = a.1 => "many somes",
Some(Err(a)) => "some",
None => "none"
}
let tmp_x = x;
match tmp_x {
Some(Ok(a)) => {
if let Some(b) = a.0 && let Some(b) = a.1 {
"many somes"
} else {
contuneu;
}
}
}
if let Some(b) = a.0 && let Some(b) = a.1 {}
else if ... {}
else {}
|
v
match () {
() if let Some(b) = a.0 && let Some(b) = a.1 => {},
() if ... => {},
() => {}
}
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=b20e5d2285acaeea05f25b3bb863de93
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=c9a090bd95079e1c3991fc6696ad0ba2
#![feature(if_let_guard)]
struct S(u8);
impl Drop for S {
fn drop(&mut self) {
println!("{}", self.0);
}
}
impl S {
fn t(&self) -> bool {
true
}
fn f(&self) -> bool {
false
}
}
fn main() {
println!("A");
if let true = S(0).f() {
println!("B");
} else if let true = S(1).t() {
println!("C");
} else {
println!("D");
}
// AB0CD
println!("-----");
println!("A");
match () {
() if let true = S(0).f() => {
println!("B");
}
() if let true = S(1).t() => {
println!("C");
}
() => {
println!("D");
}
}
// A0C1
}
https://github.com/rust-lang/rust/issues/51114#issuecomment-980466680
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing