-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Rework marshal.rs to use an error enum #4125
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
Conversation
coolreader18
commented
Aug 23, 2022
- Rework frozenset construction
- Rework marshal.rs to use an error enum
| use num_traits::Zero; | ||
| use std::str; | ||
|
|
||
| #[derive(num_enum::TryFromPrimitive)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| inner: PySetInner, | ||
| } | ||
|
|
||
| impl PyFrozenSetBuilder<'_> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type looks like to be able to be used for both frozenset and set.
Then instead of build and build_with_type, PyFrozenSet::from_builder PyFrozenSet::from_builder_with_type, and From<PyFrozenSetBuilder> for PySet will cover any possible use case
| let sign = if len < 0 { Sign::Minus } else { Sign::Plus }; | ||
| let len = len.unsigned_abs() as usize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big deal but this is changed from single comparison to double comparison (symentically)
| let sign = if len < 0 { Sign::Minus } else { Sign::Plus }; | |
| let len = len.unsigned_abs() as usize; | |
| let (sign, len) = if len < 0 { | |
| (Sign::Minus, (-len) as usize) | |
| } else { | |
| (Sign::Plus, len as usize) | |
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually prefer what @coolreader18 wrote here because its intention is clearer. However, I do have one improvement for the first line:
| let sign = if len < 0 { Sign::Minus } else { Sign::Plus }; | |
| let len = len.unsigned_abs() as usize; | |
| let sign = if len.is_negative() { Sign::Minus } else { Sign::Plus }; | |
| let len = len.unsigned_abs() as usize; |

