Use new features of "print_bytes"

This commit is contained in:
dylni
2021-10-02 12:35:38 -04:00
parent c40838dd7d
commit f40c245d0f
3 changed files with 24 additions and 5 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ jobs:
runs-on: ubuntu-latest
env:
RUSTFLAGS: -Dwarnings
flags: --feature-powerset --optional-deps --exclude-features 'print_bytes' --target ${{ matrix.target }}
flags: --feature-powerset --optional-deps --target ${{ matrix.target }}
steps:
- uses: actions/checkout@v1
with:
+20 -3
View File
@@ -1089,24 +1089,41 @@ r#impl!(RawOsString, String);
#[cfg(feature = "print_bytes")]
#[cfg_attr(os_str_bytes_docs_rs, doc(cfg(feature = "print_bytes")))]
mod print_bytes {
use print_bytes::Bytes;
use print_bytes::ByteStr;
use print_bytes::ToBytes;
#[cfg(any(windows))]
use print_bytes::WideStr;
#[cfg(windows)]
use crate::imp::raw;
use super::RawOsStr;
use super::RawOsString;
impl ToBytes for RawOsStr {
#[inline]
fn to_bytes(&self) -> Bytes<'_> {
fn to_bytes(&self) -> ByteStr<'_> {
self.0.to_bytes()
}
#[cfg(any(windows))]
#[inline]
fn to_wide(&self) -> Option<WideStr> {
Some(WideStr::new(raw::encode_wide_unchecked(&self.0).collect()))
}
}
impl ToBytes for RawOsString {
#[inline]
fn to_bytes(&self) -> Bytes<'_> {
fn to_bytes(&self) -> ByteStr<'_> {
(**self).to_bytes()
}
#[cfg(any(windows))]
#[inline]
fn to_wide(&self) -> Option<WideStr> {
(**self).to_wide()
}
}
}
+3 -1
View File
@@ -6,7 +6,9 @@ pub(crate) use crate::util::is_continuation;
use super::wtf8;
use super::wtf8::CodePoints;
fn encode_wide_unchecked(string: &[u8]) -> impl '_ + Iterator<Item = u16> {
pub(crate) fn encode_wide_unchecked(
string: &[u8],
) -> impl '_ + Iterator<Item = u16> {
wtf8::encode_wide(string).map(|x| x.expect("invalid string"))
}