mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2025-04-29 17:58:06 +08:00
16 lines
367 B
Rust
16 lines
367 B
Rust
// ANCHOR: here
|
|
fn last_char_of_first_line(text: &str) -> Option<char> {
|
|
text.lines().next()?.chars().last()
|
|
}
|
|
// ANCHOR_END: here
|
|
|
|
fn main() {
|
|
assert_eq!(
|
|
last_char_of_first_line("Hello, world\nHow are you today?"),
|
|
Some('d')
|
|
);
|
|
|
|
assert_eq!(last_char_of_first_line(""), None);
|
|
assert_eq!(last_char_of_first_line("\nhi"), None);
|
|
}
|