Minor improvements

This commit is contained in:
dylni
2020-08-01 23:13:58 -04:00
parent 96b3151bec
commit 558fdc9035
10 changed files with 17 additions and 21 deletions
+5 -4
View File
@@ -9,16 +9,17 @@ Traits for converting between byte sequences and platform-native strings
"""
repository = "https://github.com/dylni/os_str_bytes"
readme = "README.md"
keywords = ["osstr", "osstring", "path", "bytes", "windows"]
keywords = ["bytes", "osstr", "osstring", "path", "windows"]
categories = ["command-line-interface", "development-tools::ffi", "encoding", "os", "rust-patterns"]
license = "MIT OR Apache-2.0"
[package.metadata.docs.rs]
all-features = true
rustc-args = ["--cfg", "os_str_bytes_docs_rs"]
rustdoc-args = ["--cfg", "os_str_bytes_docs_rs"]
[features]
raw = []
[dev-dependencies]
getrandom = "0.1"
[features]
raw = []
+1 -1
View File
@@ -20,7 +20,7 @@ use super::OsStrBytes;
use super::OsStringBytes;
if_raw! {
pub(crate) mod raw;
pub(super) mod raw;
}
impl OsStrBytes for OsStr {
+1 -1
View File
@@ -6,7 +6,7 @@ use std::fmt::Formatter;
#[cfg_attr(not(windows), allow(dead_code))]
#[derive(Debug, Eq, PartialEq)]
pub(crate) enum EncodingError {
pub(super) enum EncodingError {
Byte(u8),
CodePoint(u32),
End(),
+2 -2
View File
@@ -154,7 +154,7 @@ use std::path::PathBuf;
macro_rules! if_raw {
( $($item:item)+ ) => {
$(
#[cfg(any(all(doc, not(doctest)), feature = "raw"))]
#[cfg(feature = "raw")]
$item
)+
};
@@ -190,7 +190,7 @@ mod imp;
/// [`OsStringExt`]: https://doc.rust-lang.org/std/os/unix/ffi/trait.OsStringExt.html
/// [`Result::unwrap`]: https://doc.rust-lang.org/std/result/enum.Result.html#method.unwrap
#[derive(Debug, Eq, PartialEq)]
pub struct EncodingError(pub(crate) error::EncodingError);
pub struct EncodingError(error::EncodingError);
impl Display for EncodingError {
#[inline]
+1 -1
View File
@@ -13,7 +13,7 @@ use super::OsStrBytes;
use super::OsStringBytes;
if_raw! {
pub(crate) mod raw;
pub(super) mod raw;
}
mod wtf8;
-1
View File
@@ -7,7 +7,6 @@ use super::is_continuation;
use super::BYTE_SHIFT;
use super::CONT_MASK;
#[derive(Debug)]
pub(in super::super) struct CodePoints<TIter> {
iter: Fuse<TIter>,
next: Option<u8>,
-2
View File
@@ -15,7 +15,6 @@ const MIN_LOW_SURROGATE: u16 = 0xDC00;
const MIN_SURROGATE_CODE: u32 = (u16::max_value() as u32) + 1;
#[derive(Debug)]
pub(in super::super) struct DecodeWide<TIter> {
iter: TIter,
code_point: Option<u32>,
@@ -80,7 +79,6 @@ where
}
}
#[derive(Debug)]
pub(in super::super) struct EncodeWide<TIter> {
iter: TIter,
surrogate: Option<u16>,
+4 -3
View File
@@ -5,6 +5,7 @@ use std::borrow::Cow;
use std::ffi::OsStr;
use std::ffi::OsString;
use std::fmt::Debug;
use std::ops::Deref;
use std::path::Path;
use std::path::PathBuf;
@@ -22,7 +23,7 @@ fn assert_bytes_eq<TString>(
{
assert_eq!(
expected.as_ref().map(Borrow::borrow),
result.as_ref().map(Borrow::borrow),
result.as_ref().map(Deref::deref),
);
}
@@ -49,7 +50,7 @@ pub(crate) fn from_vec(string: Vec<u8>) -> Result<OsString, EncodingError> {
pub(crate) fn test_bytes(string: &[u8]) -> Result<(), EncodingError> {
let os_string = from_bytes(string)?;
assert_eq!(string.len(), os_string.len());
assert_eq!(string, os_string.to_bytes().as_ref());
assert_eq!(string, &*os_string.to_bytes());
Ok(())
}
@@ -64,7 +65,7 @@ pub(crate) fn test_utf8_bytes(string: &str) {
let os_string = string.into();
let string = string.as_bytes();
assert_eq!(Ok(&os_string), from_bytes(string).as_ref());
assert_eq!(string, os_string.to_bytes().as_ref());
assert_eq!(string, &*os_string.to_bytes());
}
pub(crate) fn test_utf8_vec(string: &str) {
+1 -2
View File
@@ -1,4 +1,3 @@
use std::borrow::Borrow;
use std::ffi::OsStr;
use std::ffi::OsString;
@@ -73,7 +72,7 @@ fn test_lossless() -> Result<(), getrandom::Error> {
getrandom(&mut string)?;
if let Ok(os_string) = OsStr::from_bytes(&string) {
let encoded_string = os_string.to_bytes();
assert_eq!(string, Borrow::<[u8]>::borrow(&encoded_string));
assert_eq!(string, &*encoded_string);
}
}
Ok(())
+2 -4
View File
@@ -11,8 +11,7 @@ fn test_ends_with() {
test(true, b"r");
test(true, b"ar");
test(true, b"bar");
#[cfg(not(windows))]
{
if cfg!(not(windows)) {
test(true, b"\xA9bar");
test(true, b"\x92\xA9bar");
test(true, b"\x9F\x92\xA9bar");
@@ -43,8 +42,7 @@ fn test_starts_with() {
test(true, b"fo");
test(true, b"foo");
test(true, b"foo\xED\xA0\xBD");
#[cfg(not(windows))]
{
if cfg!(not(windows)) {
test(true, b"foo\xED\xA0\xBD\xF0");
test(true, b"foo\xED\xA0\xBD\xF0\x9F");
test(true, b"foo\xED\xA0\xBD\xF0\x9F\x92");