Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convenience functions? #44

Open
phayes opened this issue Jan 14, 2020 · 1 comment
Open

Convenience functions? #44

phayes opened this issue Jan 14, 2020 · 1 comment

Comments

@phayes
Copy link

phayes commented Jan 14, 2020

Hi there,

I was thinking about opening up a pull request with convenience functions, and was wondering if the maintainers of this crate would be open to merging such a PR.

Specifically, I'm thinking of creating a bunch of functions (one per format mod) with signatures similar to this:

pub fn decode(input: &[u8]) -> Result<Vec<u8>> {
    let mut output = Vec::with_capacity(input.len());
    let mut decoder = Decoder::new(input)?;
    decoder.read_to_end(&mut output)?;
    Ok(output)
}

pub fn encode(input: &[u8]) -> Result(Vec<u8>) {
    let output = Vec::with_capacity(input.len());
    let mut encoder = Encoder::new(&mut output)?;
    encoder.write(input)?;
    let output = encoder.finish().into_result();
    output.shrink_to_fit()
    Ok(output)
}

This code is just back-of-the-napkin sketches of what these convenience functions would look like.

I find that these types of convenience functions are very nice when I run into them in other encoding/decoding crates and was thinking they would make a nice addition here too.

If you give me the go-ahead, I'll work up a proper PR for review.

@sile
Copy link
Owner

sile commented Jan 15, 2020

Sounds good. Please go for it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants