diff --git a/rustfmt.toml b/rustfmt.toml index ad54acc..a1ffd27 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,2 +1 @@ -edition = "2018" max_width = 79 diff --git a/src/lib.rs b/src/lib.rs index 95f5afc..b20e198 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -160,19 +160,16 @@ macro_rules! if_raw { }; } +#[cfg_attr(windows, path = "windows/mod.rs")] +#[cfg_attr(not(windows), path = "common/mod.rs")] +mod imp; + mod error; if_raw! { pub mod raw; } -#[cfg(not(windows))] -#[path = "common/mod.rs"] -mod imp; -#[cfg(windows)] -#[path = "windows/mod.rs"] -mod imp; - /// The error that occurs when a byte sequence is not representable in the /// platform encoding. /// diff --git a/src/windows/mod.rs b/src/windows/mod.rs index 56bee94..8582b7f 100644 --- a/src/windows/mod.rs +++ b/src/windows/mod.rs @@ -61,7 +61,7 @@ impl OsStringBytes for OsString { #[inline] fn into_vec(self) -> Vec { - OsStrBytes::to_bytes(self.as_os_str()).into_owned() + OsStrBytes::to_bytes(&*self).into_owned() } } diff --git a/src/windows/wtf8/convert.rs b/src/windows/wtf8/convert.rs index 46a62b6..656fbb9 100644 --- a/src/windows/wtf8/convert.rs +++ b/src/windows/wtf8/convert.rs @@ -112,15 +112,14 @@ where self.iter.next().map(|code_point| { code_point.map(|code_point| { - if let Some(offset) = - code_point.checked_sub(MIN_SURROGATE_CODE) - { - self.surrogate = - Some((offset & 0x3FF) as u16 | MIN_LOW_SURROGATE); - (offset >> 10) as u16 | MIN_HIGH_SURROGATE - } else { - code_point as u16 - } + code_point + .checked_sub(MIN_SURROGATE_CODE) + .map(|offset| { + self.surrogate = + Some((offset & 0x3FF) as u16 | MIN_LOW_SURROGATE); + (offset >> 10) as u16 | MIN_HIGH_SURROGATE + }) + .unwrap_or(code_point as u16) }) }) } diff --git a/src/windows/wtf8/string.rs b/src/windows/wtf8/string.rs index da6bbf4..05e155a 100644 --- a/src/windows/wtf8/string.rs +++ b/src/windows/wtf8/string.rs @@ -42,10 +42,6 @@ pub(in super::super) fn starts_with( string: &[u8], mut prefix: &[u8], ) -> Option { - if prefix.is_empty() { - return Some(true); - } - if let Some(&byte) = string.get(prefix.len()) { if is_continuation(byte) { let index = prefix.len().checked_sub(SURROGATE_LENGTH)?; diff --git a/tests/common.rs b/tests/common.rs index abb3856..2bdaf4d 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -57,7 +57,7 @@ pub(crate) fn test_bytes(string: &[u8]) -> Result<(), EncodingError> { pub(crate) fn test_vec(string: &[u8]) -> Result<(), EncodingError> { let os_string = from_vec(string.to_vec())?; assert_eq!(string.len(), os_string.len()); - assert_eq!(string, os_string.into_vec().as_slice()); + assert_eq!(string, &*os_string.into_vec()); Ok(()) } @@ -72,5 +72,5 @@ pub(crate) fn test_utf8_vec(string: &str) { let os_string = string.to_string().into(); let string = string.as_bytes(); assert_eq!(Ok(&os_string), from_vec(string.to_vec()).as_ref()); - assert_eq!(string, os_string.into_vec().as_slice()); + assert_eq!(string, &*os_string.into_vec()); } diff --git a/tests/random.rs b/tests/random.rs index 9537fee..d68ad26 100644 --- a/tests/random.rs +++ b/tests/random.rs @@ -67,7 +67,7 @@ fn test_random_vec() -> Result<(), getrandom::Error> { #[test] fn test_lossless() -> Result<(), getrandom::Error> { - for _ in 1..ITERATIONS { + for _ in 0..ITERATIONS { let mut string = vec![0; SMALL_LENGTH]; getrandom(&mut string)?; if let Ok(os_string) = OsStr::from_bytes(&string) { @@ -95,7 +95,7 @@ fn test_raw() -> Result<(), getrandom::Error> { }; } - for _ in 1..ITERATIONS { + for _ in 0..ITERATIONS { let mut string = random_os_string(SMALL_LENGTH)?; let prefix = string.to_bytes().into_owned(); let suffix = random_os_string(SMALL_LENGTH)?;