Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto-bigint: add target-specific rustdocs #500

Merged
merged 1 commit into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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