<commit_before>#![no_std]

pub struct Error;

/// Interface for the CLI to consume bytes.
pub trait Read {
    fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>;
}

/// Interface for the CLI to emit bytes.
pub trait Write {
    fn write(&mut self, buf: &[u8]) -> Result<usize, Error>;
}

/// Adapter for writing core::fmt formatted strings.
impl core::fmt::Write for dyn Write + '_ {
    /// Writes the bytes of a &str to the underlying writer.
    fn write_str(&mut self, s: &str) -> core::fmt::Result {
        match self.write(s.as_bytes()) {
            Ok(_) => Ok(()),
            Err(_) => Err(core::fmt::Error),
        }
    }
}

impl dyn Read + '_ {
    pub fn get_u8(&mut self) -> Result<u8, Error> {
        let mut buf: [u8; 1] = [0u8];
        let n_read = self.read(&mut buf)?;
        match n_read {
            1usize => Ok(buf[0]),
            _ => Err(Error),
        }
    }
}
<commit_msg>kata-io alias analogous to io::Result<commit_after>#![no_std]

pub struct Error;

pub type Result<T> = core::result::Result<T, Error>;

/// Interface for the CLI to consume bytes.
pub trait Read {
    fn read(&mut self, buf: &mut [u8]) -> Result<usize>;
}

/// Interface for the CLI to emit bytes.
pub trait Write {
    fn write(&mut self, buf: &[u8]) -> Result<usize>;
}

/// Adapter for writing core::fmt formatted strings.
impl core::fmt::Write for dyn Write + '_ {
    /// Writes the bytes of a &str to the underlying writer.
    fn write_str(&mut self, s: &str) -> core::fmt::Result {
        match self.write(s.as_bytes()) {
            Ok(_) => Ok(()),
            Err(_) => Err(core::fmt::Error),
        }
    }
}

impl dyn Read + '_ {
    pub fn get_u8(&mut self) -> Result<u8> {
        let mut buf: [u8; 1] = [0u8];
        let n_read = self.read(&mut buf)?;
        match n_read {
            1usize => Ok(buf[0]),
            _ => Err(Error),
        }
    }
}

{'fraction_non_alphanumeric': 0.1664025356576862, 'fraction_numerical': 0.010565240359218173, 'mean_word_length': 2.2881944444444446, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4665545', 'n_tokens_mistral': 654, 'n_tokens_neox': 642, 'n_words': 198}