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

fix: Remove more as conversions in protocol::messages #121

Merged
merged 3 commits into from
Mar 24, 2022

Conversation

pierwill
Copy link
Contributor

Part of #101.

@@ -137,7 +137,7 @@ fn read_versioned_array<R: Read, T: ReadVersionedType<R>>(
format!("Invalid negative length for array: {}", l).into(),
))),
_ => {
let len = len as usize;
let len = usize::try_from(len).map_err(ReadError::Overflow)?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be .map_err(|e| ReadVersionedError::ReadError(ReadError::Overflow(e)))??

Copy link
Collaborator

@crepererum crepererum Mar 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think thiserror and ? take care of that:

#[derive(Error, Debug)]
pub enum ReadVersionedError {
#[error("Read error: {0}")]
ReadError(#[from] ReadError),
}

See the #[from] macro. Also note that ? doesn't mean "return this error" but "return this error, rustc might apply a From/Into conversion. So

let x = f()?;

is more or less

let x = match f() {
    Ok(x) => x,
    Err(e) => {
        return e.into();
    }
};

pierwill and others added 2 commits March 15, 2022 11:12
Co-authored-by: Marco Neumann <marco@crepererum.net>
Also Merge branch 'main' into messages-as
@pierwill pierwill added the automerge Instruct kodiak to merge the PR label Mar 24, 2022
@kodiakhq kodiakhq bot merged commit 1c6fc6d into influxdata:main Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Instruct kodiak to merge the PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants