Skip to content

nextzhou/tein

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tein - Tiny & Easy Inputer for Rust

Build Status

A simple wrapping of inputting part of Rust standard library.

Usage

Add this to your Cargo.toml:

[dependencies.tein]
git = "https://github.com/nextzhou/tein.git"

Stdin

// read n numbers from stdin to vector
extern crate tein;
use tein::*;

fn main() {
    // Same as: let mut teiner = Tein::new(std::io::stdin());
    let mut teiner = new_with_stdin();
    let n: usize = teiner.read().unwrap();
    let nums: Vec<i32> = teiner.iter().take(n).collect();
    println!("{:?}", nums);
}

String

// read values from string
extern tein;
use tein::*;

fn main() {
    let s: String = "123   34.5 true abc".to_owned();
    let mut teinner = Tein::new(s.as_bytes());

    let i: i32 = teinner.read().unwrap();
    let f: f32 = teinner.read().unwrap();
    let b: bool = teinner.read().unwrap();
    let s: String = teinner.read().unwrap();

    println!("i32:{}, bool:{}, f32:{}, String:{}", i, b, f, s);

}

Other type implemented std::io::Read trait.

Such as std::fs::File, std::net::TcpStream.

About

Tiny & Easy Inputer for Rust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages