Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Dec 7th, 2018 112 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. use std::fs;
  2. use std::error::Error;
  3.  
  4.  
  5. pub struct Config {
  6.     pub query: String,
  7.     pub filename: String
  8. }
  9.  
  10. impl Config {
  11.     pub fn new(args: &[String]) -> Result<Config, &'static str> {
  12.         if args.len() < 3 {
  13.             return Err("Not enough args supplied.")
  14.         }
  15.  
  16.         let query = args[1].clone();
  17.         let filename = args[2].clone();
  18.  
  19.         return Ok(Config { query, filename })
  20.     }
  21. }
  22.  
  23.  
  24. pub fn run(config: Config) -> Result<(), Box<dyn Error>> {
  25.     let contents = fs::read_to_string(config.filename)?;
  26.  
  27.     println!("File text:\n{}", contents);
  28.  
  29.     Ok(())
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Pastebin PRO 'CHRISTMAS SPECIAL'!
Get 60% OFF Pastebin PRO accounts!
 
Top