Improve rustdocs on U256 type
Improve the rustdocs on the private `U256` type by doing: - Remove link to self within constructors, just use backticks - Use `U256` instead of `Self` or `self` - Fix incorrect usage of `CompactTarget` [0] [0] We knew this was wrong when we merged it but because the docs are private we elected to do this follow up patch.
This commit is contained in:
parent
6ec93ce685
commit
81a704302c
|
@ -400,7 +400,7 @@ impl U256 {
|
||||||
|
|
||||||
const ONE: U256 = U256(0, 1);
|
const ONE: U256 = U256(0, 1);
|
||||||
|
|
||||||
/// Creates a `U256` from an prefixed hex string.
|
/// Creates a `U256` from a prefixed hex string.
|
||||||
fn from_hex(s: &str) -> Result<Self, PrefixedHexError> {
|
fn from_hex(s: &str) -> Result<Self, PrefixedHexError> {
|
||||||
let stripped = if let Some(stripped) = s.strip_prefix("0x") {
|
let stripped = if let Some(stripped) = s.strip_prefix("0x") {
|
||||||
stripped
|
stripped
|
||||||
|
@ -412,7 +412,7 @@ impl U256 {
|
||||||
Ok(U256::from_hex_internal(stripped)?)
|
Ok(U256::from_hex_internal(stripped)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a `CompactTarget` from an unprefixed hex string.
|
/// Creates a `U256` from an unprefixed hex string.
|
||||||
fn from_unprefixed_hex(s: &str) -> Result<Self, UnprefixedHexError> {
|
fn from_unprefixed_hex(s: &str) -> Result<Self, UnprefixedHexError> {
|
||||||
if s.starts_with("0x") || s.starts_with("0X") {
|
if s.starts_with("0x") || s.starts_with("0X") {
|
||||||
return Err(ContainsPrefixError::new(s).into());
|
return Err(ContainsPrefixError::new(s).into());
|
||||||
|
@ -437,7 +437,7 @@ impl U256 {
|
||||||
Ok(U256(high, low))
|
Ok(U256(high, low))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates [`U256`] from a big-endian array of `u8`s.
|
/// Creates `U256` from a big-endian array of `u8`s.
|
||||||
#[cfg_attr(all(test, mutate), mutate)]
|
#[cfg_attr(all(test, mutate), mutate)]
|
||||||
fn from_be_bytes(a: [u8; 32]) -> U256 {
|
fn from_be_bytes(a: [u8; 32]) -> U256 {
|
||||||
let (high, low) = split_in_half(a);
|
let (high, low) = split_in_half(a);
|
||||||
|
@ -446,7 +446,7 @@ impl U256 {
|
||||||
U256(big, little)
|
U256(big, little)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a [`U256`] from a little-endian array of `u8`s.
|
/// Creates a `U256` from a little-endian array of `u8`s.
|
||||||
#[cfg_attr(all(test, mutate), mutate)]
|
#[cfg_attr(all(test, mutate), mutate)]
|
||||||
fn from_le_bytes(a: [u8; 32]) -> U256 {
|
fn from_le_bytes(a: [u8; 32]) -> U256 {
|
||||||
let (high, low) = split_in_half(a);
|
let (high, low) = split_in_half(a);
|
||||||
|
@ -455,7 +455,7 @@ impl U256 {
|
||||||
U256(big, little)
|
U256(big, little)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts `Self` to a big-endian array of `u8`s.
|
/// Converts `U256` to a big-endian array of `u8`s.
|
||||||
#[cfg_attr(all(test, mutate), mutate)]
|
#[cfg_attr(all(test, mutate), mutate)]
|
||||||
fn to_be_bytes(self) -> [u8; 32] {
|
fn to_be_bytes(self) -> [u8; 32] {
|
||||||
let mut out = [0; 32];
|
let mut out = [0; 32];
|
||||||
|
@ -464,7 +464,7 @@ impl U256 {
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts `Self` to a little-endian array of `u8`s.
|
/// Converts `U256` to a little-endian array of `u8`s.
|
||||||
#[cfg_attr(all(test, mutate), mutate)]
|
#[cfg_attr(all(test, mutate), mutate)]
|
||||||
fn to_le_bytes(self) -> [u8; 32] {
|
fn to_le_bytes(self) -> [u8; 32] {
|
||||||
let mut out = [0; 32];
|
let mut out = [0; 32];
|
||||||
|
@ -515,7 +515,7 @@ impl U256 {
|
||||||
/// Returns the low 128 bits.
|
/// Returns the low 128 bits.
|
||||||
fn low_u128(&self) -> u128 { self.1 }
|
fn low_u128(&self) -> u128 { self.1 }
|
||||||
|
|
||||||
/// Returns `self` as a `u128` saturating to `u128::MAX` if `self` is too big.
|
/// Returns this `U256` as a `u128` saturating to `u128::MAX` if `self` is too big.
|
||||||
// Matagen gives false positive because >= and > both return u128::MAX
|
// Matagen gives false positive because >= and > both return u128::MAX
|
||||||
fn saturating_to_u128(&self) -> u128 {
|
fn saturating_to_u128(&self) -> u128 {
|
||||||
if *self > U256::from(u128::MAX) {
|
if *self > U256::from(u128::MAX) {
|
||||||
|
|
Loading…
Reference in New Issue