Giter VIP home page Giter VIP logo

enum_extra's People

Contributors

ratmice avatar

Watchers

 avatar  avatar

enum_extra's Issues

MaskIterator trait bounds

currently not all bounds required by MaskIterator are enforced, some are just documented.

A MaskIterator which iterates over unique single bit non-zero enum variants.

Unique single-bit also entails unsigned, or bounded > 0, as the sign lacks uniqueness.
if I recall the implementation correctly it does not need to be contiguous.

It is probably worth enforcing trait bounds for these eventually.

default #[repr(..)] type

I haven't found the place where default type for enum repr's are given, and what guarantees the compiler gives,
Currently NonZeroRepr requires #[repr(..)] to be set explicitly, and doesn't default to any type.

It appears the compilers though do have a default type, which does not change.
e.g.

enum Foo {
    Bar = std::usize::MAX,
}
error[E0308]: mismatched types
 --> src/main.rs:2:11
  |
2 |     Bar = std::usize::MAX,
  |           ^^^^^^^^^^^^^^^ expected `isize`, found `usize`

and similar for anything attempting to

error[E0308]: mismatched types
 --> src/main.rs:2:11
  |
2 |     Bar = -1_i8,
  |           ^^^^^ expected `isize`, found `i8`

need to find if/where this is guaranteed, before I loosen the restriction...

Repr(C)

Ideally it'd be nice to be able to use this with Repr(C) but really idea (with the caveat that I haven't really tried to see if there is actually some sane mechansim) for deciding what type what type Repr(C) would pick.

Simplify

This whole lib uses a bunch of really strange generic/trait magic (like traits with equality constraints over associated types that are actually Self),

It is worth thinking about how/if it can be simplified: Is it possible to ditch the associated types and merely use Self?
I don't offhand believe so, because we only get equality constraints for traits and they aren't supported in a where clause.

But certainly there seems like a lot of complexity here and it is likely that some simplifications could be made.

For instance, it'd probably be better to rename OpaqueMetadata::Repr to something else so as to avoid inducing ambiguity with EnumMetadata::Repr.

Repr constraint trait naming

Eventually I want to add traits like SingleBitUnique, ExistsUniqueBit

where ExistsUniqueBit would accept:

  Foo = 0x5,
  Bar = 0x3,

because even though Foo and Bar overlap at bit 1, they are unique in bits 2 and 3.

where SingleUniqueBit
works with enums like:

Foo = 1 << 0,
Bar = 1 << 1,

These are okay, but think if there are better names.
Also its worth thinking whether it should bundle traits together,
for instance MaskIterator wants: NonZeroRepr + SingleBitUnique Should we define a trait which combines these 2 or leave it to MaskIterator to combine the bounds...

ValidRepr

Not sure if it is worthwhile, but we could have a type ValidRepr<T> which does not implement arithmetic operators.

It would be constructable from an enum variant and back into an enum variant using to_valid_repr and a variant from_valid_repr would not need to return an option, potentially having an unsafe unchecked constructor.

I'm not certain it is worthwhile though, it is probably worth having a use case in place before adding it.
Potential generic use case: all arithmetic is done in a private function (not publicly, but converting from ValidRepr<T> to the T::Repr), and all cases that arithmetic on T::Repr will produce a T.

by all means chime in if you have a concrete use case for such a thing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.