-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# To be used together with a bazel WORKSPACE file that contains the following definitions. | ||
load("@committer_crate//:defs.bzl", "all_crate_deps") | ||
load("@rules_rust//rust:defs.bzl", "rust_binary") | ||
|
||
rust_binary( | ||
name = "committer_exe", | ||
srcs = glob(["src/**/*.rs"]), | ||
edition = "2021", | ||
proc_macro_deps = all_crate_deps(proc_macro = True), | ||
visibility = ["//visibility:public"], | ||
deps = all_crate_deps(), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use std::env; | ||
use std::path::Path; | ||
|
||
/// Gets a binary input and an output file from the command line. | ||
/// Reads the input file, adds 1 to each byte, and writes the result to the output file. | ||
fn main() { | ||
// Open the input file | ||
let args: Vec<String> = env::args().collect(); | ||
let input_file_name = Path::new(&args[1]); | ||
let output_file_name = Path::new(&args[2]); | ||
assert!( | ||
input_file_name.is_absolute() && output_file_name.is_absolute(), | ||
"Given paths must be absolute" | ||
); | ||
let mut bytes = std::fs::read(input_file_name).unwrap(); | ||
|
||
// Add 1 to each byte | ||
for byte in &mut bytes { | ||
*byte = byte.wrapping_add(1); | ||
} | ||
std::fs::write(output_file_name, bytes).expect("Failed to write output"); | ||
} |