Skip to content

feat: introduce NonZeroU* types with null-pointer optimization #4

@hubcycle

Description

@hubcycle

Description

Currently, oblux only provides U7, U15, U31, U63, U127 types and each one contains the corresponding underlying u* type. We want to introduce the following NonZero* types:

NonZeroU7
NonZeroU15
NonZeroU31
NonZeroU63
NonZeroU127

Implementation

Introduce the above types that will wrap the corresponding NonZeroU* types from the core library. We're specifically interested in the memory layout when wrapped by an Option. The implemented representation must use null pointer optimization.

Test

Add new doc tests to verify the constraints.

Acceptance Criteria

  • cargo build succeeds.
  • size_of::<Option<NonZeroU7>>() == size_of::<NonZeroU7>() == size_of::<U7>().
  • size_of::<Option<NonZeroU15>>() == size_of::<NonZeroU15>() == size_of::<U15>().
  • size_of::<Option<NonZeroU31>>() == size_of::<NonZeroU31>() == size_of::<U31>().
  • size_of::<Option<NonZeroU63>>() == size_of::<NonZero63>() == size_of::<U63>().
  • size_of::<Option<NonZeroU127>>() == size_of::<NonZeroU127>() == size_of::<U127>().

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions