Last active
September 22, 2023 18:08
-
-
Save Samet195/d2eca28c6907dac184ac63fa7bc4b92b to your computer and use it in GitHub Desktop.
Java like OOP Programming in Rust
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
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