From 3d8ee620875085ae7e8d7ef31f4f8e3738cfdca1 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 7 Feb 2022 18:49:59 +0300 Subject: style(rust): Format all Rust code with rustfmt Change-Id: Iab7e00cc26a4f9727d3ab98691ef379921a33052 Reviewed-on: https://cl.tvl.fyi/c/depot/+/5240 Tested-by: BuildkiteCI Reviewed-by: kanepyork Reviewed-by: Profpatsch Reviewed-by: grfn Reviewed-by: tazjin --- nix/nint/nint.rs | 55 ++++++++++++++++++++++++------------------------------- 1 file changed, 24 insertions(+), 31 deletions(-) (limited to 'nix') diff --git a/nix/nint/nint.rs b/nix/nint/nint.rs index 1fa4dccb4f..abb0153c3a 100644 --- a/nix/nint/nint.rs +++ b/nix/nint/nint.rs @@ -1,11 +1,11 @@ extern crate serde_json; use serde_json::Value; +use std::convert::TryFrom; use std::ffi::OsString; -use std::os::unix::ffi::{OsStringExt, OsStrExt}; -use std::io::{Error, ErrorKind, Write, stdout, stderr}; +use std::io::{stderr, stdout, Error, ErrorKind, Write}; +use std::os::unix::ffi::{OsStrExt, OsStringExt}; use std::process::Command; -use std::convert::{TryFrom}; fn render_nix_string(s: &OsString) -> OsString { let mut rendered = Vec::new(); @@ -16,8 +16,8 @@ fn render_nix_string(s: &OsString) -> OsString { match char::from(*b) { '\"' => rendered.extend(b"\\\""), '\\' => rendered.extend(b"\\\\"), - '$' => rendered.extend(b"\\$"), - _ => rendered.push(*b), + '$' => rendered.extend(b"\\$"), + _ => rendered.push(*b), } } @@ -48,17 +48,14 @@ fn render_nix_list(arr: &[OsString]) -> OsString { macro_rules! handle_set_output { ($map_name:ident, $output_name:ident) => { match $map_name.get(stringify!($output_name)) { - Some(Value::String(s)) => - $output_name().write_all(s.as_bytes()), - Some(_) => Err( - Error::new( - ErrorKind::Other, - format!("Attribute {} must be a string!", stringify!($output_name)), - ) - ), + Some(Value::String(s)) => $output_name().write_all(s.as_bytes()), + Some(_) => Err(Error::new( + ErrorKind::Other, + format!("Attribute {} must be a string!", stringify!($output_name)), + )), None => Ok(()), } - } + }; } fn main() -> std::io::Result<()> { @@ -83,7 +80,7 @@ fn main() -> std::io::Result<()> { } if in_args { - match(arg.to_str()) { + match (arg.to_str()) { Some("--arg") | Some("--argstr") => { nix_args.push(arg); nix_args.push(args.next().unwrap()); @@ -116,9 +113,7 @@ fn main() -> std::io::Result<()> { nix_args.push(argv[0].clone()); - let run = Command::new("nix-instantiate") - .args(nix_args) - .output()?; + let run = Command::new("nix-instantiate").args(nix_args).output()?; match serde_json::from_slice(&run.stdout[..]) { Ok(Value::String(s)) => stdout().write_all(s.as_bytes()), @@ -132,25 +127,23 @@ fn main() -> std::io::Result<()> { match code { Some(i) => std::process::exit(i), - None => Err( - Error::new( - ErrorKind::Other, - "Attribute exit is not an i32" - ) - ), + None => { + Err(Error::new(ErrorKind::Other, "Attribute exit is not an i32")) + } } - }, - Some(_) => Err( - Error::new(ErrorKind::Other, "exit must be a number") - ), + } + Some(_) => Err(Error::new(ErrorKind::Other, "exit must be a number")), None => Ok(()), } - }, - Ok(_) => Err(Error::new(ErrorKind::Other, "output must be a string or an object")), + } + Ok(_) => Err(Error::new( + ErrorKind::Other, + "output must be a string or an object", + )), _ => { stderr().write_all(&run.stderr[..]); Err(Error::new(ErrorKind::Other, "internal nix error")) - }, + } } } } -- cgit 1.4.1