repline: Add a code sample demonstrating the use of prebaked::read_and
This commit is contained in:
		
							
								
								
									
										17
									
								
								repline/examples/repl_float.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								repline/examples/repl_float.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| //! Demonstrates the use of [read_and()]: | ||||
| //!  | ||||
| //! The provided closure: | ||||
| //! 1. Takes a line of input (a [String]) | ||||
| //! 2. Performs some calculation (using [FromStr]) | ||||
| //! 3. Returns a [Result] containing a [Response] or an [Err] | ||||
|  | ||||
| use repline::{prebaked::read_and, Response}; | ||||
| use std::{error::Error, str::FromStr}; | ||||
|  | ||||
| fn main() -> Result<(), Box<dyn Error>> { | ||||
|     read_and("\x1b[33m", "  >", " ?>", |line| { | ||||
|         println!("-> {:?}", f64::from_str(line.trim())?); | ||||
|         Ok(Response::Accept) | ||||
|     })?; | ||||
|     Ok(()) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user