Skip to content

Allow Job body to be "anything" (Vec<u8> instead of String) #5

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

Merged
merged 2 commits into from
Oct 2, 2020

Conversation

maxleiko
Copy link
Contributor

First of all, thanks for the amazing work on this Beanstalkd client.

I was about to use it for a project but I needed Jobs to be able to handle raw bytes payloads (not just utf-8 encoded strings).
Long story short, we send gzipped payload (that might not be all utf-8 chars), which lead to Utf8Error in the automatic conversion.
We can argue this choice, but we could also give the choice to the library users, with this pull request :)

So, this is a slight modification of the API:

pub struct Job<'a> {
    // ...
    body: Vec<u8>, // instead of String
    // ...
}

// and the impacted bits here and there, mainly:

impl<'a> Job<'a> {
    // ...
    /// Return job body.
    pub fn body(&self) -> &[u8] {
        &self.body[..]
    }

    /// Return job body as UTF-8 `&str`  
    /// This method is just calling `std::str::from_utf8(&self.body)`
    pub fn body_utf8(&self) -> BeanstalkcResult<&str> {
        Ok(str::from_utf8(&self.body)?)
    }
   // ...

  // and some other stuff

I'm pretty sure you don't want to merge this as-is, so feel free to ask for modifications.

@iFaceless
Copy link
Owner

iFaceless commented Oct 1, 2020

Hey, thanks for your contribution! And I'm glad to know that this a helpful crate for your project. I think it's nessary to be able to handle job body with raw bytes payload.

@maxleiko
Copy link
Contributor Author

maxleiko commented Oct 1, 2020

Hey, thanks for your contribution! And I'm glad to know that this a helpful crate for your project. I think it's nessary to be able to handle job body with raw bytes payload.

There you go

@iFaceless iFaceless merged commit 1f8d194 into iFaceless:master Oct 2, 2020
@iFaceless
Copy link
Owner

iFaceless commented Oct 2, 2020

Hi, thanks again for your feedback and contribution.
Version bumped to 1.0.0, and I've already declared that version 1.0.0 introduced a breaking change in README.

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

Successfully merging this pull request may close these issues.

2 participants