Skip to content

Instantly share code, notes, and snippets.

@Samet195
Last active September 22, 2023 18:08
Show Gist options
  • Save Samet195/d2eca28c6907dac184ac63fa7bc4b92b to your computer and use it in GitHub Desktop.
Save Samet195/d2eca28c6907dac184ac63fa7bc4b92b to your computer and use it in GitHub Desktop.
Java like OOP Programming in Rust
use std::fmt::Display;
use std::io::{stdin, stdout, Write};
struct Library;
impl Library {
pub fn main() {
Self.greet(Self::input("Who are you?: "));
}
fn greet(&self, name: impl Display) {
println!("Hello, {}!", name);
}
pub fn input(prompt: impl Display) -> Box<str> {
let mut buffer = String::new();
stdout().write(prompt.to_string().as_bytes()).unwrap();
stdout().flush().unwrap();
stdin().read_line(&mut buffer).unwrap();
buffer.trim().into()
}
}
fn main() {
Library::main();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment