Skip to content

Commit 3e6d788

Browse files
committed
Move all constructors to the top of the docs
1 parent cdf0adb commit 3e6d788

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

src/lib.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ impl<T: BitFlag> From<T> for BitFlags<T> {
378378
///
379379
/// Some `const fn`s in this crate will need an instance of this type
380380
/// for some type-level information usually provided by traits.
381-
/// For an example of usage, see [`not_c`][BitFlags::not_c]
381+
/// For an example of usage, see [`not_c`][BitFlags::not_c].
382382
pub struct ConstToken<T, N>(BitFlags<T, N>);
383383

384384
impl<T> BitFlags<T>
@@ -399,6 +399,32 @@ where
399399
BitFlags { val, marker: PhantomData }
400400
}
401401

402+
/// Returns a `BitFlags<T>` if the raw value provided does not contain
403+
/// any illegal flags.
404+
pub fn from_bits(bits: T::Numeric) -> Result<Self, FromBitsError<T>> {
405+
let flags = Self::from_bits_truncate(bits);
406+
if flags.bits() == bits {
407+
Ok(flags)
408+
} else {
409+
Err(FromBitsError {
410+
flags,
411+
invalid: bits & !flags.bits(),
412+
})
413+
}
414+
}
415+
416+
/// Truncates flags that are illegal
417+
#[inline(always)]
418+
pub fn from_bits_truncate(bits: T::Numeric) -> Self {
419+
unsafe { BitFlags::from_bits_unchecked(bits & T::ALL_BITS) }
420+
}
421+
422+
/// Turn a `T` into a `BitFlags<T>`. Also available as `flag.into()`.
423+
#[inline(always)]
424+
pub fn from_flag(flag: T) -> Self {
425+
unsafe { Self::from_bits_unchecked(flag.bits()) }
426+
}
427+
402428
/// Create a `BitFlags` with no flags set (in other words, with a value of `0`).
403429
///
404430
/// See also: [`BitFlag::empty`], a convenience reexport;
@@ -511,32 +537,6 @@ where
511537
(self.bits() & other.bits()) == other.bits()
512538
}
513539

514-
/// Returns a `BitFlags<T>` if the raw value provided does not contain
515-
/// any illegal flags.
516-
pub fn from_bits(bits: T::Numeric) -> Result<Self, FromBitsError<T>> {
517-
let flags = Self::from_bits_truncate(bits);
518-
if flags.bits() == bits {
519-
Ok(flags)
520-
} else {
521-
Err(FromBitsError {
522-
flags,
523-
invalid: bits & !flags.bits(),
524-
})
525-
}
526-
}
527-
528-
/// Turn a `T` into a `BitFlags<T>`. Also available as `flag.into()`.
529-
#[inline(always)]
530-
pub fn from_flag(flag: T) -> Self {
531-
unsafe { Self::from_bits_unchecked(flag.bits()) }
532-
}
533-
534-
/// Truncates flags that are illegal
535-
#[inline(always)]
536-
pub fn from_bits_truncate(bits: T::Numeric) -> Self {
537-
unsafe { BitFlags::from_bits_unchecked(bits & T::ALL_BITS) }
538-
}
539-
540540
/// Toggles the matching bits
541541
#[inline(always)]
542542
pub fn toggle<B: Into<BitFlags<T>>>(&mut self, other: B) {

0 commit comments

Comments
 (0)