From e03afbf5930d256b11f40e8ec688f5a88fb6de34 Mon Sep 17 00:00:00 2001 From: Dusk Banks Date: Fri, 1 May 2020 20:40:05 -0700 Subject: [PATCH] Restore Rust 1.41.0 compatibility This allows building with default Rust on Nixpkgs channel `nixos-20.03`. A `shell.nix` file has been added for easier future compatibility tests. (Subslice patterns were introduced in 1.42; the Nixpkgs PR for Rust 1.41.0 -> 1.42.0 is https://github.com/NixOS/nixpkgs/pull/82447 .) --- shell.nix | 17 +++++++++++++++++ src/lib/parse_format.rs | 26 ++++++++++++++------------ 2 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 shell.nix diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..7d6283d --- /dev/null +++ b/shell.nix @@ -0,0 +1,17 @@ +{ pkgs ? import { } }: + +pkgs.mkShell { + name = "nexromancers-hacksaw-shell"; + nativeBuildInputs = [ + pkgs.pkgconfig + pkgs.python3 + ]; + buildInputs = [ + pkgs.cargo + pkgs.clippy + pkgs.rustc + pkgs.rustfmt + pkgs.xorg.libX11 + pkgs.xorg.libXrandr + ]; +} diff --git a/src/lib/parse_format.rs b/src/lib/parse_format.rs index 60e1e68..9413b5f 100644 --- a/src/lib/parse_format.rs +++ b/src/lib/parse_format.rs @@ -18,23 +18,25 @@ pub(crate) fn parse_format_string(input: &str) -> Result { let mut input = input.as_bytes(); loop { - let (token, rest) = match input { - [b'%', b'i', rest @ ..] => (FormatToken::WindowId, rest), - [b'%', b'g', rest @ ..] => (FormatToken::Geometry, rest), - [b'%', b'w', rest @ ..] => (FormatToken::Width, rest), - [b'%', b'h', rest @ ..] => (FormatToken::Height, rest), - [b'%', b'x', rest @ ..] => (FormatToken::X, rest), - [b'%', b'y', rest @ ..] => (FormatToken::Y, rest), - [b'%', b'%', rest @ ..] => (FormatToken::Literal("%".to_owned()), rest), - [b'%', c, ..] => break Err(format!("Unknown format '%{}'", *c as char)), - [b'%'] => break Err("Incorrectly terminated '%'".to_owned()), - [_, ..] => { + let (token, rest) = match input.split_first() { + Some((b'%', format_rest)) => match format_rest.split_first() { + Some((b'i', rest)) => (FormatToken::WindowId, rest), + Some((b'g', rest)) => (FormatToken::Geometry, rest), + Some((b'w', rest)) => (FormatToken::Width, rest), + Some((b'h', rest)) => (FormatToken::Height, rest), + Some((b'x', rest)) => (FormatToken::X, rest), + Some((b'y', rest)) => (FormatToken::Y, rest), + Some((b'%', rest)) => (FormatToken::Literal("%".to_owned()), rest), + Some((c, _)) => break Err(format!("Unknown format '%{}'", *c as char)), + None => break Err("Incorrectly terminated '%'".to_owned()), + } + Some((_, _)) => { let next_perc = input.iter().position(|&c| c == b'%'); let (literal, rest) = input.split_at(next_perc.unwrap_or_else(|| input.len())); let literal = FormatToken::Literal(String::from_utf8_lossy(literal).into_owned()); (literal, rest) } - [] => break Ok(tokens), + None => break Ok(tokens), }; tokens.push(token);