From 415dea09f386173e84b4af8a76d8e64fcb53ba13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Nied=C5=BAwied=C5=BA?= Date: Fri, 28 Dec 2018 13:08:18 +0100 Subject: [PATCH] Update of hello-world example for Rust 2018 This is more concise and readable in my opinion, you be the judge. --- README.md | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 22b0fff..bdb8415 100644 --- a/README.md +++ b/README.md @@ -30,36 +30,26 @@ git = "https://github.com/gchp/rustbox.git" Then, in your `src/example.rs`: ```rust -extern crate rustbox; - use std::error::Error; use std::default::Default; -use rustbox::{Color, RustBox}; -use rustbox::Key; +use rustbox::{self, Color, RustBox, Key}; -fn main() { - let rustbox = match RustBox::init(Default::default()) { - Result::Ok(v) => v, - Result::Err(e) => panic!("{}", e), - }; +fn main() -> Result<(), Box> { + let rustbox = RustBox::init(Default::default())?; rustbox.print(1, 1, rustbox::RB_BOLD, Color::White, Color::Black, "Hello, world!"); - rustbox.print(1, 3, rustbox::RB_BOLD, Color::White, Color::Black, - "Press 'q' to quit."); + rustbox.print(1, 3, rustbox::RB_BOLD, Color::White, Color::Black, "Press 'q' to quit."); rustbox.present(); + loop { - match rustbox.poll_event(false) { - Ok(rustbox::Event::KeyEvent(key)) => { - match key { - Key::Char('q') => { break; } - _ => { } - } - }, - Err(e) => panic!("{}", e.description()), - _ => { } + match rustbox.poll_event(false)? { + rustbox::Event::KeyEvent(Key::Char('q')) => { break; }, + _ => { }, } } + + Ok(()) } ```