mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-26 07:39:59 -07:00
55 lines
1.1 KiB
Rust
55 lines
1.1 KiB
Rust
use byteview::ByteView;
|
|
use derive_deref::Deref;
|
|
use zerocopy::{FromBytes, IntoBytes};
|
|
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
|
|
|
|
use crate::copy_first_8bytes;
|
|
|
|
use super::BlockHash;
|
|
|
|
#[derive(
|
|
Debug,
|
|
Deref,
|
|
Clone,
|
|
Copy,
|
|
PartialEq,
|
|
Eq,
|
|
PartialOrd,
|
|
Ord,
|
|
FromBytes,
|
|
Immutable,
|
|
IntoBytes,
|
|
KnownLayout,
|
|
)]
|
|
pub struct BlockHashPrefix([u8; 8]);
|
|
|
|
impl From<BlockHash> for BlockHashPrefix {
|
|
fn from(value: BlockHash) -> Self {
|
|
Self::from(&value)
|
|
}
|
|
}
|
|
|
|
impl From<&BlockHash> for BlockHashPrefix {
|
|
fn from(value: &BlockHash) -> Self {
|
|
Self(copy_first_8bytes(&value[..]).unwrap())
|
|
}
|
|
}
|
|
|
|
impl From<ByteView> for BlockHashPrefix {
|
|
fn from(value: ByteView) -> Self {
|
|
Self::read_from_bytes(&value).unwrap()
|
|
}
|
|
}
|
|
|
|
impl From<&BlockHashPrefix> for ByteView {
|
|
fn from(value: &BlockHashPrefix) -> Self {
|
|
Self::new(value.as_bytes())
|
|
}
|
|
}
|
|
|
|
impl From<BlockHashPrefix> for ByteView {
|
|
fn from(value: BlockHashPrefix) -> Self {
|
|
Self::from(&value)
|
|
}
|
|
}
|