Crates.io | convenience |
lib.rs | convenience |
version | 0.1.0 |
source | src |
created_at | 2016-03-24 21:00:45.291805 |
updated_at | 2016-03-24 21:00:45.291805 |
description | Useful utilities that are not part of the standard library. |
homepage | |
repository | https://github.com/yberreby/convenience-rs |
max_upload_size | |
id | 4557 |
size | 2,869 |
Useful stuff that isn't in std.
Currently there isn't much to see there apart from a few file I/O functions.
This is somewhat inspired by what I saw of Go's rich standard library, but I only took a quick look at it so take this with a grain of salt.
If you need to do something substantially more complex than what if possible
with this crate's API, chances are you really want to use the standard library
directly instead of this crate.
I was tired of writing this:
let mut s = String::new();
let mut f = try!(File::open("/path/to/file"));
try!(f.read_to_string(&mut s));
When I really wanted to do this:
let s = try!(read_file("/path/to/file"));
This is strictly less flexible than the version using only std
: you can't
allocate just the right amount of memory if you know the size of your file
upfront, you can't read a non-UTF-8 file, and you can't reuse a buffer. However,
most of the time you don't need to do any of this, you just want to get your
code working. Rust's std
is a low-level foundation, and rightly so, but
sometimes you want something that is more rigid but also simpler.
Implemented:
read_file(path)
write_file(path, contents)
To do:
random_string(len)
Any reasonably common and simple task that you could expect to be in std
, but
isn't.