Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Code shared from the Rust Playground
use std::collections::HashMap;
use std::io;
struct PhoneEntry {
name: String,
phone: String,
impl PhoneEntry {
fn new(self, name: String, phone: String) -> PhoneEntry {
PhoneEntry { name, phone }
struct PhoneBook {
phone_book: HashMap<String, PhoneEntry>,
impl PhoneBook {
fn add_contact(self) {
let mut name = String::new();
let mut phone = String::new();
io::stdin().read_line(&mut name).unwrap();
fn main() {
let mut pb = PhoneBook {
phone_book: HashMap::new(),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment