Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created May 30, 2024 00:57
Show Gist options
  • Save rust-play/37075e88e2270adc623fbf0aa81a93a0 to your computer and use it in GitHub Desktop.
Save rust-play/37075e88e2270adc623fbf0aa81a93a0 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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