Crate smart_read

source ·
Expand description

§Smart-Read

Complex but easy ways to read user input


§Anything that implements ReadLine can be used with smart-read’s macros, and many implementations are already given



§Existing functionalities:


§No Args

If you don’t pass any args, this is the default functionality

Implemented type:

impl ReadLine for ()

§Boundless

These allow you to take any usize, bool, etc. Example: read!(YesNoInput)

Implemented types:

impl ReadLine for BoolInput
impl ReadLine for YesNoInput
impl ReadLine for CharInput
impl ReadLine for UsizeInput
impl ReadLine for IsizeInput
impl ReadLine for U8Input, U16Input, U32Input, U64Input, U128Input
impl ReadLine for I8Input, I16Input, I32Input, I64Input, I128Input
impl ReadLine for F32Input
impl ReadLine for F64Input

§Input Options

These allow you to specify which inputs are allowed. Example: read!(&["a", "b", "c"])

Special syntax: read!(= 1, 2, 3)

Implemented types:

impl<T: Display + Clone + PartialEq> ReadLine for &[T]
impl<T: Display + Clone + PartialEq> ReadLine for &[T; _]
impl<T: Display + Clone + PartialEq> ReadLine for Vec<T>
impl<T: Display + Clone + PartialEq> ReadLine for VecDeque<T>
impl<T: Display + Clone + PartialEq> ReadLine for LinkedList<T>

§Ranges

These allow you to take a number within a specified range. Example: read!(1. .. 100.), or read!(10..), etc

Implemented types:

impl<T: Display + FromStr + PartialOrd<T>> ReadLine for Range<T>
impl<T: Display + FromStr + PartialOrd<T>> ReadLine for RangeInclusive<T>
impl<T: Display + FromStr + PartialOrd<T>> ReadLine for RangeTo<T>
impl<T: Display + FromStr + PartialOrd<T>> ReadLine for RangeFrom<T>
impl<T: Display + FromStr + PartialOrd<T>> ReadLine for RangeToInclusive<T>


§Extra Functionality:

Additional data can be added at the start of read!() / prompt!(). In order, these additions are:


§Custom Input

input >> (must implement crate’s IntoInput)


§Prompt Message

prompt_value; (only available with prompt!())


§Default Value

[default_value]


§Example:   prompt!("Enter a color: "; prev_user_input >> ["red"] = "red", "green", "blue")


If you have ideas for more functionality (including things that you’ve found to be useful for yourself), feel free to open an issue



Modules§

Macros§

  • Same as read!(), but also prints a prompt
  • Reads a line of text, a number, etc
  • Same as prompt!(), but returns a result
  • Same as read!(), but returns a result

Structs§

  • Specifies the source of user input
  • This contains all possible information about the read / prompt

Traits§

  • This is what powers the whole crate. Any struct that implements this can be used with the macros

Functions§

Type Aliases§

  • Just Result<T, Box<dyn Error>>, mostly for internal use