You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How do you define the types to achieve this though? The guideline says "newtypes", but that doesn't seem applicable here - what do you put in a struct Foo(Bar) to make Small available?
This seems what enums are for, but they require much less pleasant syntax: Widget::new(MyEnum::Small, MyOtherEnum::Round).
While writing this I found that you can use Enum::Variant, like so:
This discussion was converted from issue #198 on December 21, 2020 22:12.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
https://rust-lang-nursery.github.io/api-guidelines/type-safety.html#arguments-convey-meaning-through-types-not-bool-or-option-c-custom-type says
How do you define the types to achieve this though? The guideline says "newtypes", but that doesn't seem applicable here - what do you put in a
struct Foo(Bar)
to makeSmall
available?This seems what
enum
s are for, but they require much less pleasant syntax:Widget::new(MyEnum::Small, MyOtherEnum::Round)
.While writing this I found that you can
use Enum::Variant
, like so:- does the example rely on this?
Would it make sense to hint at it in the guideline:
or is obvious to everyone else?
Beta Was this translation helpful? Give feedback.
All reactions