bpt 0.1.6

Bedrock Linux package manager
1
2
3
4
5
6
7
8
9
10
11
12
13
14
use std::io::{Error, ErrorKind};

pub trait IntoString {
    fn into_string(self) -> Result<String, std::io::Error>;
}

impl IntoString for &[u8] {
    fn into_string(self) -> Result<String, std::io::Error> {
        String::from_utf8(self.into()).map_err(|_| {
            let s = String::from_utf8_lossy(self);
            Error::new(ErrorKind::InvalidData, format!("`{s}` is not valid UTF-8"))
        })
    }
}