initial commit

This commit is contained in:
Youwen Wu 2024-08-24 03:20:46 -07:00
commit 99ebda0e56
Signed by: youwen5
GPG key ID: 865658ED1FE61EC3
17 changed files with 2162 additions and 0 deletions

39
' Normal file
View file

@ -0,0 +1,39 @@
use std::env;
use std::fs;
use std::process;
fn main() {
let args: Vec<String> = env::args().collect();
let config = Config::build(&args).unwrap_or_else(|err| {
println!("Problem parsing arguments: {err}");
process::exit(1);
});
run(config);
}
fn run(config: Config) -> Result<(), Box<dyn Error>> {
let contents =
fs::read_to_string(config.file_path).expect("Should have have been able to read the file!");
println!("With text:\n{contents}");
}
struct Config {
query: String,
file_path: String,
}
impl Config {
fn build(args: &[String]) -> Result<Config, &'static str> {
if args.len() < 3 {
return Err("not enough arguments!");
}
let query = args[1].clone();
let file_path = args[2].clone();
Ok(Config { query, file_path })
}
}

19
.direnv/bin/nix-direnv-reload Executable file
View file

@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -e
if [[ ! -d "/home/youwen/Source/active/minigrep" ]]; then
echo "Cannot find source directory; Did you move it?"
echo "(Looking for "/home/youwen/Source/active/minigrep")"
echo 'Cannot force reload with this script - use "direnv reload" manually and then try again'
exit 1
fi
# rebuild the cache forcefully
_nix_direnv_force_reload=1 direnv exec "/home/youwen/Source/active/minigrep" true
# Update the mtime for .envrc.
# This will cause direnv to reload again - but without re-building.
touch "/home/youwen/Source/active/minigrep/.envrc"
# Also update the timestamp of whatever profile_rc we have.
# This makes sure that we know we are up to date.
touch -r "/home/youwen/Source/active/minigrep/.envrc" "/home/youwen/Source/active/minigrep/.direnv"/*.rc

View file

@ -0,0 +1 @@
/nix/store/0zm67d16ijif01c3fzcng4lhazz3b08i-source

View file

@ -0,0 +1 @@
/nix/store/byd6aqsq9m8kk6wwvz3dgdd1114bqmbb-source

View file

@ -0,0 +1 @@
/nix/store/na7sykizsgkzh9i3wc8m8pz5xfqib2rv-source

View file

@ -0,0 +1 @@
/nix/store/sfycwi72zfjsspidinx56ajaiffpyh17-source

View file

@ -0,0 +1 @@
/nix/store/v9dvfkr6rpl1dh02b4lyjx0gzwkiwvk3-source

View file

@ -0,0 +1 @@
/nix/store/yj1wxm9hh8610iyzqnz75kvs6xl8j3my-source

View file

@ -0,0 +1 @@
/nix/store/hg9ymxmrlw6csbbppwhbr552icsy375x-nix-shell-env

File diff suppressed because it is too large Load diff

1
.envrc Normal file
View file

@ -0,0 +1 @@
use flake github:youwen5/nix-dev-envs#rustStable

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

7
Cargo.lock generated Normal file
View file

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "minigrep"
version = "0.1.0"

6
Cargo.toml Normal file
View file

@ -0,0 +1,6 @@
[package]
name = "minigrep"
version = "0.1.0"
edition = "2021"
[dependencies]

9
poem.txt Normal file
View file

@ -0,0 +1,9 @@
I'm nobody! Who are you?
Are you nobody, too?
Then there's a pair of us - don't tell!
They'd banish us, you know.
How dreary to be somebody!
How public, like a frog
To tell your name the livelong day
To an admiring bog!

28
src/lib.rs Normal file
View file

@ -0,0 +1,28 @@
use std::error::Error;
use std::fs;
pub fn run(config: Config) -> Result<(), Box<dyn Error>> {
let contents = fs::read_to_string(config.file_path)?;
println!("With text:\n{contents}");
Ok(())
}
pub struct Config {
pub query: String,
pub file_path: String,
}
impl Config {
pub fn build(args: &[String]) -> Result<Config, &'static str> {
if args.len() < 3 {
return Err("not enough arguments!");
}
let query = args[1].clone();
let file_path = args[2].clone();
Ok(Config { query, file_path })
}
}

21
src/main.rs Normal file
View file

@ -0,0 +1,21 @@
use std::env;
use std::process;
use minigrep::Config;
fn main() {
let args: Vec<String> = env::args().collect();
let config = Config::build(&args).unwrap_or_else(|err| {
println!("Problem parsing arguments: {err}");
process::exit(1);
});
println!("Searching for {}", config.query);
println!("In file {}", config.file_path);
if let Err(e) = minigrep::run(config) {
println!("Application error: {e}");
process::exit(1);
}
}