#input #io #cmd #scanf #cli

reader

一个简单的受 Python 启发的终端数据读取器

5 个版本

0.1.4 2020 年 12 月 22 日
0.1.3 2020 年 12 月 19 日
0.1.2 2020 年 12 月 5 日
0.1.1 2020 年 12 月 1 日
0.1.0 2020 年 12 月 1 日

#8 in #scanf

Download history 11/week @ 2024-03-29 3/week @ 2024-04-05 3/week @ 2024-05-17 7/week @ 2024-05-24 8/week @ 2024-05-31 2/week @ 2024-06-07 2/week @ 2024-06-14

191 次每月下载

自定义许可证

6KB

Reader

GitHub

一个简单的受 Python 启发的终端数据读取器。

示例

使用示例:

extern crate reader;
use reader::input;

let name = input("Enter your name: ");
println!("Your name is: {}", name);

将字符串转换为整数

extern crate reader;
use reader::{input, int};

// Reading a integer (i64)
let age = int(input("Enter your age: ")).unwrap();
println!("Your age is: {}", age);

// Reading a integer (i32)
let age = int(input("Enter your age: ")).unwrap() as i32;
println!("Your age is: {}", age);

// Reading a integer (i16)
let age = int(input("Enter your age: ")).unwrap() as i16;
println!("Your age is: {}", age);

// Reading a integer (i8)
let age = int(input("Enter your age: ")).unwrap() as i8;
println!("Your age is: {}", age);

将字符串转换为浮点数

extern crate reader;
use reader::{input, float};

// Reading a float (f64) 
let salary = float(input("Enter your salary: ")).unwrap();
println!("Your salary is: {}", salary);

// Reading a float (f32)
let salary = float(input("Enter your salary: ")).unwrap() as f32;
println!("Your salary is: {}", salary);

无运行时依赖