2 releases

0.1.1 May 14, 2020
0.1.0 Jun 6, 2019

#673 in Command-line interface

50 downloads per month
Used in 3 crates

MIT/Apache

7KB

scanln

The inverse of println


Overview

scanln is a macro that reads a line from stdin, removes the trailing newline (if present), and leaves other whitespace intact. It expands to an expression that returns a String, so it can be assigned to a variable or used directly. scanln may take arguments like those to the print macro, which can be used to generate a prompt.

Examples

Simple prompt

let input = scanln!("> ");

This results in a prompt that looks like this (where _ represents where the user will start typing):

> _

No prompt

let input = scanln!();

Result:

_

Formatted prompt

let input = scanln!("{}", 0);

Result:

0_

lib.rs:

The inverse of println

scanln is a macro that reads a line from stdin, removes the trailing newline (if present), and leaves other whitespace intact. It expands to an expression that returns a String, so it can be assigned to a variable or used directly. scanln may take arguments like those to the print macro, which can be used to generate a prompt.

Examples

Simple prompt

let input = scanln!("> ");

This results in a prompt that looks like this (where _ represents where the user will start typing):

> _

No prompt

let input = scanln!();

Result:

_

Formatted prompt

let input = scanln!("{}", 0);

Result:

0_

No runtime deps