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

Remove our own error types from crossbeam-queue #548

Merged
merged 2 commits into from
Aug 30, 2020
Merged

Remove our own error types from crossbeam-queue #548

merged 2 commits into from
Aug 30, 2020

Conversation

taiki-e
Copy link
Member

@taiki-e taiki-e commented Aug 30, 2020

Currently, crossbeam-queue has two error types: PopError, PushError.

  • PopError is a unit struct with no field, and is returned by ArrayQueue::pop and SegQueue::pop if the queue is empty.
  • PushError is a tuple struct with a public field that stores the element that user tried to push, and is returned by ArrayQueue::push if the queue is full.

I guess the current API was influenced by channels, but there is only one kind(variant) of error in each, and unlike channels, multiple kinds(variants) of errors do not occur.
And, neither of these provides additional information about the error (fields are all public, so it doesn't seem like they are going to provide them in the future).

So, APIs that return Option (on pop methods) and Result (on ArrayQueue::push) without our own errors are simple, and I think it is preferable.
(Especially for the pop methods, it will be more consistent, because all other public pop methods in crossbeam return Option.)

(Of course, this is a breaking change, but the master already has some breaking changes.)

This changes `pop` methods to return `Option`.
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

This seems like an okay change to me. :) I only chose to return Result from pop() for symmetry between push() and pop().

@taiki-e
Copy link
Member Author

taiki-e commented Aug 30, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Aug 30, 2020

Build succeeded:

@bors bors bot merged commit 61f25e7 into master Aug 30, 2020
@taiki-e taiki-e deleted the queue-errors branch August 30, 2020 14:42
taiki-e added a commit to taiki-e/crossbeam that referenced this pull request Dec 31, 2020
@taiki-e taiki-e mentioned this pull request Jan 4, 2021
taiki-e added a commit to taiki-e/crossbeam that referenced this pull request Jan 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

1 participant