Skip to content

Conversation

burrbull
Copy link
Member

@burrbull burrbull requested a review from a team as a code owner August 24, 2019 08:03
@rust-highfive rust-highfive added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-tools labels Aug 24, 2019
@therealprof
Copy link
Contributor

Interesting, what's the intended use for that?

pub fn unwrap(self) -> T {
match self {
Val(v) => v,
Res(u) => panic!("Unexpected variant: {:?}", u),
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not to hot about this panic! and the expect method below. If this ends up in use in real code it'd add significant bloat.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can remove unwrap and keep expect as it is more explicit.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine with with those methods per se but let's get rid of the formatting and the Debug bound, please.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok

Copy link
Member Author

Choose a reason for hiding this comment

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

Is now better?

@burrbull
Copy link
Member Author

Sometimes enumeratedValues does not cover all variants of bits (number of variants less then 2^field_width).
In these cases we have to return Variant<_,T> with reserved bits field instead of T (~10% of enums).
изображение
It is rare used feature. Usually we simply call is_something().

But if you want to get variant as enum, you need to call variant and unwrap it.
Getting reserved bits usually means something go wrong.

@burrbull

This comment has been minimized.

use Variant::*;
impl<U, T> Variant<U, T> {
/// Check if the variant is expected
pub fn is_value(&self) -> bool {
Copy link
Member

Choose a reason for hiding this comment

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

This naming is strange. At least function name does not correspond to the docs. I can't suggest anything nicer, though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you have suggestions?

///
/// Panics if the value is an `Res`, with a panic message including the
/// passed message, and the content of the `Res`.
pub fn expect(self, msg: &'static str) -> T {
Copy link
Member

Choose a reason for hiding this comment

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

Do you really need 'static bound here?

Copy link
Member Author

Choose a reason for hiding this comment

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

It doesn’t compile without 'static.

Copy link
Contributor

Choose a reason for hiding this comment

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

Weird. The original expect doesn't have it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's because original expect use formatted panic!("{}", msg).
With 2 arguments.

https://doc.rust-lang.org/src/core/macros.rs.html#12

@therealprof
Copy link
Contributor

@Disasm Are you happy with the current state?
@burrbull Can you fix the conflict, please?

@burrbull
Copy link
Member Author

Rebased.

@burrbull
Copy link
Member Author

See #496

@burrbull burrbull closed this Mar 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants