Move const_assert to bitcoin_internals
This is an internal macro, now that we have the `internals` crate put `const_assert` in it.
This commit is contained in:
parent
5a8a5ff6c9
commit
53b681b838
|
@ -219,7 +219,7 @@ macro_rules! decoder_fn {
|
||||||
($name:ident, $val_type:ty, $readfn:ident, $byte_len: expr) => {
|
($name:ident, $val_type:ty, $readfn:ident, $byte_len: expr) => {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn $name(&mut self) -> Result<$val_type, Error> {
|
fn $name(&mut self) -> Result<$val_type, Error> {
|
||||||
$crate::internal_macros::const_assert!(::core::mem::size_of::<$val_type>() == $byte_len);
|
bitcoin_internals::const_assert!(core::mem::size_of::<$val_type>() == $byte_len);
|
||||||
let mut val = [0; $byte_len];
|
let mut val = [0; $byte_len];
|
||||||
self.read_exact(&mut val[..]).map_err(Error::Io)?;
|
self.read_exact(&mut val[..]).map_err(Error::Io)?;
|
||||||
Ok(endian::$readfn(&val))
|
Ok(endian::$readfn(&val))
|
||||||
|
|
|
@ -465,11 +465,3 @@ macro_rules! impl_bytes_newtype {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
pub(crate) use impl_bytes_newtype;
|
pub(crate) use impl_bytes_newtype;
|
||||||
|
|
||||||
/// Asserts a boolean expression at compile time.
|
|
||||||
macro_rules! const_assert {
|
|
||||||
($x:expr) => {{
|
|
||||||
const _: [(); 0 - !$x as usize] = [];
|
|
||||||
}};
|
|
||||||
}
|
|
||||||
pub(crate) use const_assert;
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ macro_rules! define_be_to_array {
|
||||||
($name: ident, $type: ty, $byte_len: expr) => {
|
($name: ident, $type: ty, $byte_len: expr) => {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn $name(val: $type) -> [u8; $byte_len] {
|
pub fn $name(val: $type) -> [u8; $byte_len] {
|
||||||
$crate::internal_macros::const_assert!(::core::mem::size_of::<$type>() == $byte_len);
|
bitcoin_internals::const_assert!(core::mem::size_of::<$type>() == $byte_len);
|
||||||
let mut res = [0; $byte_len];
|
let mut res = [0; $byte_len];
|
||||||
for i in 0..$byte_len {
|
for i in 0..$byte_len {
|
||||||
res[i] = ((val >> ($byte_len - i - 1)*8) & 0xff) as u8;
|
res[i] = ((val >> ($byte_len - i - 1)*8) & 0xff) as u8;
|
||||||
|
@ -43,7 +43,7 @@ macro_rules! define_le_to_array {
|
||||||
($name: ident, $type: ty, $byte_len: expr) => {
|
($name: ident, $type: ty, $byte_len: expr) => {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn $name(val: $type) -> [u8; $byte_len] {
|
pub fn $name(val: $type) -> [u8; $byte_len] {
|
||||||
$crate::internal_macros::const_assert!(::core::mem::size_of::<$type>() == $byte_len);
|
bitcoin_internals::const_assert!(core::mem::size_of::<$type>() == $byte_len);
|
||||||
let mut res = [0; $byte_len];
|
let mut res = [0; $byte_len];
|
||||||
for i in 0..$byte_len {
|
for i in 0..$byte_len {
|
||||||
res[i] = ((val >> i*8) & 0xff) as u8;
|
res[i] = ((val >> i*8) & 0xff) as u8;
|
||||||
|
|
|
@ -73,3 +73,11 @@ macro_rules! debug_from_display {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Asserts a boolean expression at compile time.
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! const_assert {
|
||||||
|
($x:expr) => {{
|
||||||
|
const _: [(); 0 - !$x as usize] = [];
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue