mirror of https://github.com/rust-lang/book
29 lines
613 B
Rust
29 lines
613 B
Rust
struct ImportantExcerpt<'a> {
|
|
part: &'a str,
|
|
}
|
|
|
|
// ANCHOR: 1st
|
|
impl<'a> ImportantExcerpt<'a> {
|
|
fn level(&self) -> i32 {
|
|
3
|
|
}
|
|
}
|
|
// ANCHOR_END: 1st
|
|
|
|
// ANCHOR: 3rd
|
|
impl<'a> ImportantExcerpt<'a> {
|
|
fn announce_and_return_part(&self, announcement: &str) -> &str {
|
|
println!("Attention please: {announcement}");
|
|
self.part
|
|
}
|
|
}
|
|
// ANCHOR_END: 3rd
|
|
|
|
fn main() {
|
|
let novel = String::from("Call me Ishmael. Some years ago...");
|
|
let first_sentence = novel.split('.').next().expect("Could not find a '.'");
|
|
let i = ImportantExcerpt {
|
|
part: first_sentence,
|
|
};
|
|
}
|