Crate smart_read
source ·Expand description
§Smart-Read
Complex but easy ways to read user input
§Anything that implements the TryRead trait can be used with smart-read’s macros, and many implementations are already given
§Types that implement TryRead:
§Basics
impl TryRead for ()
impl TryRead for NonEmptyInput
impl TryRead for NonWhitespaceInput
impl TryRead for BoolInput
impl TryRead for YesNoInput
impl TryRead for CharInput
impl TryRead for UsizeInput
impl TryRead for IsizeInput
impl TryRead for U8Input, U16Input, U32Input, U64Input, U128Input
impl TryRead for I8Input, I16Input, I32Input, I64Input, I128Input
impl TryRead for F32Input
impl TryRead 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> TryRead for &[T]
impl<T: Display + Clone + PartialEq> TryRead for &[T; _]
impl<T: Display + Clone + PartialEq> TryRead for Vec<T>
impl<T: Display + Clone + PartialEq> TryRead for VecDeque<T>
impl<T: Display + Clone + PartialEq> TryRead 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>> TryRead for Range<T>
impl<T: Display + FromStr + PartialOrd<T>> TryRead for RangeInclusive<T>
impl<T: Display + FromStr + PartialOrd<T>> TryRead for RangeTo<T>
impl<T: Display + FromStr + PartialOrd<T>> TryRead for RangeFrom<T>
impl<T: Display + FromStr + PartialOrd<T>> TryRead for RangeToInclusive<T>§Extra Functionality:
In addition to the type of input, 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§
- Allows a type to be used as input. Example:
- This is what powers the whole crate. Any struct that implements this can be used with the macros
Functions§
- Utility function, mostly for internal use
- Utility function, mostly for internal use
Type Aliases§
- Just
Result<T, Box<dyn Error>>, mostly for internal use