diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/i3bar_protocol.rs | 4 | ||||
| -rw-r--r-- | src/utils.rs | 29 |
2 files changed, 2 insertions, 31 deletions
diff --git a/src/i3bar_protocol.rs b/src/i3bar_protocol.rs index 8fdb0e2..d7d3f3e 100644 --- a/src/i3bar_protocol.rs +++ b/src/i3bar_protocol.rs @@ -1,7 +1,7 @@ use crate::color::Color; use crate::pointer_btn::PointerBtn; use crate::text::Align; -use crate::utils::{de_first_json, de_last_json, last_line, trim_ascii_start}; +use crate::utils::{de_first_json, de_last_json, last_line}; use serde::{de, Deserialize, Serialize}; use std::io::{self, Error, ErrorKind}; @@ -116,7 +116,7 @@ impl Protocol { } None => Ok(bytes), }, - Self::JsonNotStarted { header } => match trim_ascii_start(bytes) { + Self::JsonNotStarted { header } => match bytes.trim_ascii_start() { [] => Ok(&[]), [b'[', rem @ ..] => { *self = Self::Json { diff --git a/src/utils.rs b/src/utils.rs index c7913f1..826edc0 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -76,20 +76,6 @@ pub fn de_first_json<'a, T: Deserialize<'a>>( } } -/// Returns a byte slice with leading ASCII whitespace bytes removed. -/// -/// TODO: remove if/when slice::trim_ascii_start is stabilized. -pub fn trim_ascii_start(mut bytes: &[u8]) -> &[u8] { - while let [first, rest @ ..] = bytes { - if first.is_ascii_whitespace() { - bytes = rest; - } else { - break; - } - } - bytes -} - #[cfg(test)] mod tests { use super::*; @@ -143,19 +129,4 @@ mod tests { let s = b"hello\nworld\n..."; assert_eq!(last_line(s), Some((str!("world"), str!("...")))); } - - #[test] - fn test_trim_start() { - let s = b" "; - assert_eq!(trim_ascii_start(s), b""); - - let s = b"hello"; - assert_eq!(trim_ascii_start(s), b"hello"); - - let s = b"\t \nhello"; - assert_eq!(trim_ascii_start(s), b"hello"); - - let s = b" \t \nhello\n"; - assert_eq!(trim_ascii_start(s), b"hello\n"); - } } |
