Skip to main content

read_input

Function read_input 

Source
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:

  1. If file is Some, reads from that file path
  2. If inline is Some, returns that string
  3. 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)?;