serde_hkx_features/
dump.rs
1use crate::{
3 error::{Error, Result},
4 fs::ReadExt as _,
5};
6pub use serde_hkx::bytes::hexdump;
7use std::path::Path;
8use tokio::fs;
9
10pub async fn to_bytes<I, O>(input: I, output: Option<O>) -> Result<()>
15where
16 I: AsRef<Path>,
17 O: AsRef<Path>,
18{
19 match output {
20 Some(output) => {
21 let bytes = hexdump::to_bytes(&input.read_any_string().await?);
22 fs::write(output, &bytes).await?;
23 }
24 None => return Err(Error::InvalidStdout),
25 };
26 Ok(())
27}
28
29pub async fn to_string<I, O>(input: I, output: Option<O>) -> Result<()>
37where
38 I: AsRef<Path>,
39 O: AsRef<Path>,
40{
41 let hexdump = hexdump::to_string(input.read_bytes().await?); match output {
43 Some(output) => fs::write(output, &hexdump).await?,
44 None => print!("{hexdump}"),
45 };
46 Ok(())
47}