Skip to content

Commit

Permalink
fix: add functions for compatibility with alevin-fry changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-p committed Mar 5, 2024
1 parent 58b0c88 commit a9df1fa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
12 changes: 12 additions & 0 deletions src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ impl RadHeader {
tot_size
}

/// Write a summary of the current [RadHeader] to a [String]. This
/// produces an [Ok(String)] if successful. The `num_refs` argument
/// can be provided to control the number of reference names printed.
/// The default (if `None` is provided to this option) is 10.
pub fn summary(&self, num_refs: Option<usize>) -> anyhow::Result<String> {
use std::fmt::Write as _;
let mut s = String::new();
Expand All @@ -137,6 +141,14 @@ impl RadHeader {
}

impl RadPrelude {

/// Build a [RadPrelude] from the provided [RadHeader] and the
/// [TagSection]s for the file, read, and alignment tags. The header
/// and tag sections are moved, and so are no long valid after the
/// construction of the prelude. However, those fields are public
/// so they can be accessed after the prelude is returned. Unlike
/// the `from_bytes` constructor, this construction is assumed not
/// to be failable.
pub fn from_header_and_tag_sections(
hdr: RadHeader,
file_tags: TagSection,
Expand Down
4 changes: 4 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ macro_rules! u8_to_vec_of_bool {
#[macro_export]
macro_rules! tag_value_try_into_int {
($b:ty) => {
/// allow converting a [libradicl::rad_types::TagValue] into
/// an appropriate integer type. This fails
/// if the value contained is too big to fit
/// in the corresponidng type.
impl std::convert::TryInto<$b> for &libradicl::rad_types::TagValue {
type Error = anyhow::Error;

Expand Down
26 changes: 0 additions & 26 deletions src/rad_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,32 +506,6 @@ tag_value_try_into_int!(u8);
tag_value_try_into_int!(u16);
tag_value_try_into_int!(u32);
tag_value_try_into_int!(u64);
/* impl TryInto<u16> for TagValue {
type Error = anyhow::Error;
fn try_into(self) -> std::result::Result<u16, Self::Error> {
match self {
Self::U8(x) => { Ok(x as u16) },
Self::U16(x) => { Ok(x) },
Self::U32(x) => {
if x > u16::MAX as u32 {
bail!("Cannot convert value {x} to u16; too large")
} else {
Ok(x as u16)
}
},
Self::U64(x) => {
if x > u16::MAX as u64 {
bail!("Cannot convert value {x} to u16; too large")
} else {
Ok(x as u16)
}
},
_ => { bail!("cannot convert non-int TagValue to u16") }
}
}
}
*/

impl TagDesc {
/// Attempts to read a [TagDesc] from the provided `reader`. If the
Expand Down

0 comments on commit a9df1fa

Please sign in to comment.