cnsl 0.1.3

A crate that provides methods and macros for interacting with the command line.
Documentation
  • Coverage
  • 80%
    8 out of 10 items documented5 out of 7 items with examples
  • Size
  • Source code size: 6.84 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.28 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ImajinDevon

cnsl

cnsl is a crate for writing to the standard output, standard error, and reading from standard input.
This crate is lightly coded, and also requires no external dependencies.

Rust Build Status


Usage

readln macro


// without a prompt
use cnsl::readln;

fn main() {
    println!("What is your name?");
    let name = readln!();
    println!("Hello, {}!", name);
}

// with a prompt
use cnsl::readln;

fn main() {
    let name = readln!("Enter your name: ");
    println!("Hello, {}!", name);
}

// with a formatted prompt
// note: defaults are not actually supported, this is just a demonstration
use cnsl::readln;

const DEFAULT_AGE: u8 = 18;

fn main() {
    let age_input = readln!("Enter your age (default {}): ", DEFAULT_AGE);
    
    let age = if age_input.is_empty() {
        DEFAULT_AGE
    } else {
        age_input.parse::<u8>().expect("invalid input for age")
    };
}

Information

License

This software is licensed under the WTFPL.

Contributors