Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.
/ grep-clone Public archive

A grep clone written in Rust following the rustlings guide. Nice practice for learning Rust :)

License

Notifications You must be signed in to change notification settings

margual56/grep-clone

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GREP clone

A clone of grep, simpler, slower and without unit testing (for the moment).

Check out the wiki if you want to dive deeper into... stuff :)

Why is this "different"?

As mentioned in multiple places in this repo, this app was created following the guide.

However, this version includes piping support (reading from stdin), meaning that the input file flag is optional. It also implements a Buffered Reader instead of loading the entire file (or stdin) into memory at once.

Note: Using a Buffered Reader has a drawback, which is that you are creating a copy of the input, and processing it later.

Note II: it also uses a Buffered output, which can cause performance issues as discussed in the performance analysis.

Future features

  • Colored output, with an optional flag.
  • Multiple patterns
  • Doing the much needed optimizations
  • Multi-threading
  • Add a debug or verbose flag(?) but I don't know what it should output

Usage

Straight from grepclone -h:

grepclone 0.2.0
Just a simple grep clone programmed in Rust.
grepclone takes either an input file (`-i` option) or reads the stdin if no file is passed as an argument.

USAGE:
    grepclone [FLAGS] [OPTIONS] [patterns]...

FLAGS:
    -c, --color      Wether to print with colored output or not
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -i, --input <input>    Input file (Optional)

ARGS:
    <patterns>...    Pattern(s) to search for. Required parameter

Cross-compiling

I used the amazing and wonderful "cross" cargo program to cross-compile the program to windows. Can't compile for Mac because I don't own one :) blame Apple.

Why is it slower?

Check the detailed explanation and analysis in the wiki.

TL;DR: They do byte manipulations and program at a lower level, as well as being smarter xD.

Multithreading?

It would be really cool, and a good learning experience, BUT!

Multithreading comes with certain overhead, meaning that it is only worth using for really large tasks. So the program would need to check the size of the input(?) and then use multithreading (single-threading otherwise).

About

A grep clone written in Rust following the rustlings guide. Nice practice for learning Rust :)

Topics

Resources

License

Stars

Watchers

Forks

Languages