Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix rewrite of closures with a return type
If the closure's body fits in a line, the block is removed but it is necessary if the closure has a return type.
- Loading branch information
1 parent
4cfb9ef
commit c536d80
Showing
3 changed files
with
48 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
fn main() { | ||
let s: String = "ABAABBAA".chars() | ||
.filter(|c| { | ||
if *c == 'A' { | ||
true | ||
} | ||
else { | ||
false | ||
} | ||
}) | ||
.map(|c| -> char { | ||
if c == 'A' { | ||
'0' | ||
} else { | ||
'1' | ||
} | ||
}).collect(); | ||
|
||
println!("{}", s); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
fn main() { | ||
let s: String = "ABAABBAA" | ||
.chars() | ||
.filter(|c| if *c == 'A' { true } else { false }) | ||
.map(|c| -> char { | ||
if c == 'A' { | ||
'0' | ||
} else { | ||
'1' | ||
} | ||
}) | ||
.collect(); | ||
|
||
println!("{}", s); | ||
} |