Skip to content

Commit

Permalink
Restore Rust 1.41.0 compatibility
Browse files Browse the repository at this point in the history
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 NixOS/nixpkgs#82447 .)
  • Loading branch information
bb010g committed May 2, 2020
1 parent 3faf56c commit e03afbf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
17 changes: 17 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{ pkgs ? import <nixpkgs> { } }:

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
];
}
26 changes: 14 additions & 12 deletions src/lib/parse_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,25 @@ pub(crate) fn parse_format_string(input: &str) -> Result<Format, String> {
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);
Expand Down

0 comments on commit e03afbf

Please sign in to comment.