Skip to content

Commit

Permalink
Use new features of "print_bytes"
Browse files Browse the repository at this point in the history
  • Loading branch information
dylni committed Oct 2, 2021
1 parent 4ee8ed9 commit c0bf954
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 20 additions & 3 deletions src/raw_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/windows/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}

Expand Down

0 comments on commit c0bf954

Please sign in to comment.