-
-
Save rust-play/37075e88e2270adc623fbf0aa81a93a0 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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
struct Ticket { | |
title: String | |
} | |
impl Ticket { | |
pub fn title(&self) -> &String { | |
&self.title | |
} | |
pub fn set_title(&mut self, title: String) -> &mut Self { | |
self.title = title; | |
println!("title: {}", self.title()); | |
self | |
} | |
} | |
fn main () { | |
let mut ticket = Ticket { | |
title: "one".to_string() | |
}; | |
ticket.set_title("two".to_string()).set_title("three".to_string()); | |
println!("result: {}", ticket.title()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment