File: BitElement.md

package info (click to toggle)
rust-coreutils 0.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 505,620 kB
  • sloc: ansic: 103,594; asm: 28,570; sh: 8,910; python: 5,581; makefile: 472; cpp: 97; javascript: 72
file content (17 lines) | stat: -rw-r--r-- 862 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Unified Element Constructor

This type is a hack around the fact that `Cell` and `AtomicUN` all have
`const fn new(val: Inner) -> Self;` constructors, but the numberic fundamentals
do not. As such, the standard library does not provide a unified construction
syntax to turn an integer fundamental into the final type.

This provides a `const fn BitElement::<_>::new(R) -> Self;` function,
implemented only for the `BitStore` implementors that the crate provides, that
the constructor macros can use to turn integers into final values without using
[`mem::transmute`][0]. While `transmute` is acceptable in this case (the types
are all `#[repr(transparent)]`), it is still better avoided where possible.

As this is a macro assistant, it is publicly exposed, but is not public API. It
has no purpose outside of the crate’s macros.

[0]: core::mem::transmute.