Comments (15)
cat /proc/cpuinfo
orcat /proc/vmstat
ls /tmp
df
groups
from rust-cookbook.
By non-contrived I mean things that you couldn't just do in ordinary Rust. So I would prefer not to show cat /proc/cpuinfo
or ls /tmp
because you would just write those using the standard library.
df
isn't the best for an example because it would need a lot of code to parse and do anything useful with the output.
groups
could be a good one! I think the libc
crate has a function to list groups but unclear whether that is more or less complicated than parsing the command output.
from rust-cookbook.
oh now I get it. How about these then:
uname -a
lsblk
history
mount
journalctl
something simple yet not easily doable with std
from rust-cookbook.
Do we want to make sure the command used is commonly available on both Windows and unix systems? If so that probably limits this to commands like git
and rustc -Z
because I doubt most Windows people would have GNU Binutils (nm
) installed.
from rust-cookbook.
Yes good call, that would be ideal.
from rust-cookbook.
Would it be acceptable to pull in the regex
crate as a dependency? Regex is pretty much the swiss army knife of text manipulation, so I imagine the cookbook will include several uses of it anyway.
from rust-cookbook.
Yes that would be fine! What do you have in mind?
from rust-cookbook.
Off the top of my head, parsing something like git log --oneline
into a commit hash, some optional tags or branch names, and its message?
61d6ac0 (HEAD -> master) Added a collapsible sidebar
2318e2b Added chart.js and a Chart component
4d0fb2a Started setting up the component tree
06fa097 Initial ReactJS app skeleton
I'm happy to make a PR for this one when I get home.
from rust-cookbook.
Okay that seems reasonable to me.
If someone wanted to get commit hashes and messages would you feel comfortable recommending this shell command + regex approach over using the git2
crate?
from rust-cookbook.
For something reasonably simple like this I'd recommend parsing the process's output like we're doing here. Anything more complex though and it's probably going to be easier to use the library.
As it is, this should just be a couple lines of filter_map()
and map()
corresponding to what you'd usually do in bash, so pulling in git2
is probably overkill.
from rust-cookbook.
Makes sense! I look forward to the PR.
from rust-cookbook.
I've made an initial implementation (gist). @dtolnay, any chance you can give it a look over and see if it can be improved?
In particular, the error handling on line 32 (where I'm creating a new io::Error
) feels a little odd. I was thinking of implementing my own error type or using error_chain!{...}
but that's adding a lot of boilerplate to an already lengthy example.
from rust-cookbook.
@Michael-F-Bryan This looks great!.
I would have only one small nit:
Please see our error handling section section. Using error_chain! is the promoted error handling way (please do not worry about the noise we are working on it https://github.com/brson/rust-cookbook/pull/107).
Also could you update the example to the form
fn run() -> Result<()> {
//actual main
Ok(())
}
quick_main!(run);
The rationale is neatly explained in https://github.com/brson/rust-cookbook/pull/53#issuecomment-300244571
from rust-cookbook.
Cheers for the links, I've updated the gist and added error_chain
to make error handling nicer/more idiomatic.
Do you think that intermediate Commit
type is still necessary now that I've put everything into a single run()
function? I could just use a tuple, but that loses a bit of the readability gained by having named fields.
Also, which section would this belong in? I was thinking of adding it to the bottom of the "basics" section, but if we end up adding examples like piping one subprocess's output into another or running a child process in the background and doing other things while you wait for it to exit, it may be worth creating a new section in the cookbook. Thoughts?
from rust-cookbook.
The gist looks excellent, please create a PR.
I would add the example to the "basics" section for now. Once we have more examples we will think about how these should be split.
from rust-cookbook.
Related Issues (20)
- Indexing a map with a non-Copy structural key
- Replace lazy_static with once_cell
- Text refers to "Expand" button, actually it's "Show hidden lines"
- The header for the bitfield page is incorrect
- querying-the-web-api examples don't work due to missing user-agent-headers
- `GUI` create‘s introduce and contrast
- Use clap-derive instead of raw clap for argument parsing HOT 1
- 3.1 Decompress a tarball while removing a prefix from the paths with E0107 HOT 1
- Some documents are unavailable
- Mime crate badges show CSV's version HOT 1
- Missing (hard to find?) edit link to github
- Add recipe to building custom format-like macros
- Is this repo abandoned? HOT 5
- Bug: Sample Code Doesn't Work
- replace crossbeam's scoped threads with std's scoped threads
- Dead links in Mathematics section
- rusqlite first example does not compile HOT 2
- clap-basic.md is stale, wrong
- Clap basic got a wrong demo
- update Log Messages/Configure Logging sections HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-cookbook.