mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2025-05-05 04:58:03 +08:00
16 lines
367 B
Rust
Executable File
16 lines
367 B
Rust
Executable File
// 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);
|
|
}
|