summaryrefslogtreecommitdiff
path: root/minigrep/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'minigrep/src/lib.rs')
-rw-r--r--minigrep/src/lib.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/minigrep/src/lib.rs b/minigrep/src/lib.rs
new file mode 100644
index 0000000..78610ba
--- /dev/null
+++ b/minigrep/src/lib.rs
@@ -0,0 +1,29 @@
+use std::error::Error;
+use std::fs;
+
+pub struct Config {
+ pub query: String,
+ pub filename: String,
+}
+
+impl Config {
+
+ pub fn new(args: &[String]) -> Result<Config, &'static str> {
+
+ if args.len() < 3 {
+ return Err("Not enough arguments.");
+ }
+
+ let query = args[1].clone();
+ let filename = args[2].clone();
+ Ok(Config { query, filename })
+ }
+
+}
+
+pub fn run(config: Config) -> Result<(), Box<dyn Error>> {
+ let contents = fs::read_to_string(config.filename)?;
+ dbg!(contents);
+ Ok(())
+}
+