pub fn read_input<P: AsRef<Path>>(
file: Option<P>,
inline: Option<String>,
) -> Result<String>Expand description
Reads input from a file, inline string, or stdin.
Priority order:
- If
fileis Some, reads from that file path - If
inlineis Some, returns that string - Otherwise, reads from stdin
ยงExamples
use rh_foundation::cli::read_input;
use std::path::PathBuf;
// Read from file
let content = read_input(Some("input.txt"), None)?;
// Read from PathBuf
let path = PathBuf::from("input.txt");
let content = read_input(Some(&path), None)?;
// Read from inline argument
let content = read_input::<&str>(None, Some("inline data".to_string()))?;
// Read from stdin
let content = read_input::<&str>(None, None)?;