mirror of https://github.com/KaiserY/trpl-zh-cn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
367 B
16 lines
367 B
// 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);
|
|
}
|