Skip to content

Commit

Permalink
crypto-bigint: add target-specific rustdocs (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri committed Jun 22, 2021
1 parent b527f61 commit 6abedc8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 7 additions & 5 deletions crypto-bigint/src/limb/from.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
//! Limb from conversions
//! `From`-like conversions for [`Limb`].

use super::{Inner, Limb, Wide};

impl Limb {
/// Create a [`Limb`] from a `u8` (const-friendly)
/// Create a [`Limb`] from a `u8` integer (const-friendly)
// TODO(tarcieri): replace with `const impl From<u8>` when stable
pub const fn from_u8(n: u8) -> Self {
Limb(n as Inner)
}

/// Create a [`Limb`] from a `u16` (const-friendly)
/// Create a [`Limb`] from a `u16` integer (const-friendly)
// TODO(tarcieri): replace with `const impl From<u16>` when stable
pub const fn from_u16(n: u16) -> Self {
Limb(n as Inner)
}

/// Create a [`Limb`] from a `u32` (const-friendly)
/// Create a [`Limb`] from a `u32` integer (const-friendly)
// TODO(tarcieri): replace with `const impl From<u32>` when stable
pub const fn from_u32(n: u32) -> Self {
Limb(n as Inner)
}

/// Create a [`Limb`] from a `u64` (const-friendly)
/// Create a [`Limb`] from a `u64` integer (const-friendly)
// TODO(tarcieri): replace with `const impl From<u64>` when stable
#[cfg(target_pointer_width = "64")]
#[cfg_attr(docsrs, doc(cfg(target_pointer_width = "64")))]
pub const fn from_u64(n: u64) -> Self {
Limb(n)
}
Expand Down Expand Up @@ -51,6 +52,7 @@ impl From<u32> for Limb {
}

#[cfg(target_pointer_width = "64")]
#[cfg_attr(docsrs, doc(cfg(target_pointer_width = "64")))]
impl From<u64> for Limb {
#[inline]
fn from(n: u64) -> Limb {
Expand Down
2 changes: 2 additions & 0 deletions crypto-bigint/src/uint/from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,15 @@ impl<const LIMBS: usize> From<u128> for UInt<LIMBS> {
}

#[cfg(target_pointer_width = "32")]
#[cfg_attr(docsrs, doc(cfg(target_pointer_width = "32")))]
impl From<U64> for u64 {
fn from(n: U64) -> u64 {
(n.limbs[0].0 as u64) | ((n.limbs[1].0 as u64) << 32)
}
}

#[cfg(target_pointer_width = "64")]
#[cfg_attr(docsrs, doc(cfg(target_pointer_width = "64")))]
impl From<U64> for u64 {
fn from(n: U64) -> u64 {
n.limbs[0].into()
Expand Down

0 comments on commit 6abedc8

Please sign in to comment.