args: use PathBuf instead of string for file path
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
11
flake.nix
11
flake.nix
@@ -34,10 +34,11 @@
|
|||||||
|
|
||||||
commonArgs = { inherit src; };
|
commonArgs = { inherit src; };
|
||||||
|
|
||||||
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
|
# there are no deps right now
|
||||||
|
# cargoArtifacts = craneLib.buildDepsOnly commonArgs;
|
||||||
|
|
||||||
tricc = craneLib.buildPackage (commonArgs // {
|
tricc = craneLib.buildPackage (commonArgs // {
|
||||||
inherit cargoArtifacts;
|
# inherit cargoArtifacts;
|
||||||
doCheck = false;
|
doCheck = false;
|
||||||
});
|
});
|
||||||
in
|
in
|
||||||
@@ -49,7 +50,7 @@
|
|||||||
# not using flake checks to run them individually
|
# not using flake checks to run them individually
|
||||||
checks = {
|
checks = {
|
||||||
clippy = craneLib.cargoClippy (commonArgs // {
|
clippy = craneLib.cargoClippy (commonArgs // {
|
||||||
inherit cargoArtifacts;
|
# inherit cargoArtifacts;
|
||||||
});
|
});
|
||||||
|
|
||||||
fmt = craneLib.cargoFmt {
|
fmt = craneLib.cargoFmt {
|
||||||
@@ -57,11 +58,11 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
doc = craneLib.cargoDoc (commonArgs // {
|
doc = craneLib.cargoDoc (commonArgs // {
|
||||||
inherit cargoArtifacts;
|
# inherit cargoArtifacts;
|
||||||
});
|
});
|
||||||
|
|
||||||
nextest = craneLib.cargoNextest (commonArgs // {
|
nextest = craneLib.cargoNextest (commonArgs // {
|
||||||
inherit cargoArtifacts;
|
# inherit cargoArtifacts;
|
||||||
partitions = 1;
|
partitions = 1;
|
||||||
partitionType = "count";
|
partitionType = "count";
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use std::env;
|
use std::env;
|
||||||
|
use std::path::PathBuf;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
|
||||||
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
@@ -8,7 +9,7 @@ const CRATE: &str = env!("CARGO_CRATE_NAME");
|
|||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
version: bool,
|
version: bool,
|
||||||
file: Option<String>,
|
file: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Args {
|
impl Args {
|
||||||
@@ -34,7 +35,7 @@ impl Args {
|
|||||||
if self.file.is_some() {
|
if self.file.is_some() {
|
||||||
panic!("please specify only a single source file!");
|
panic!("please specify only a single source file!");
|
||||||
}
|
}
|
||||||
self.file = Some(file.to_owned());
|
self.file = Some(PathBuf::from(file));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,7 +56,7 @@ impl Args {
|
|||||||
/// Fetches the file from the arguments.
|
/// Fetches the file from the arguments.
|
||||||
/// Panics if there is no file in the arguments
|
/// Panics if there is no file in the arguments
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_file(self) -> String {
|
pub fn get_file(self) -> PathBuf {
|
||||||
self.file.expect("no file supplied!")
|
self.file.expect("no file supplied!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
12
src/main.rs
12
src/main.rs
@@ -27,8 +27,14 @@ fn main() {
|
|||||||
args.handle();
|
args.handle();
|
||||||
|
|
||||||
let file = args.get_file();
|
let file = args.get_file();
|
||||||
let content = fs::read_to_string(file).expect("Couldn't read the file");
|
let content = fs::read_to_string(&file).expect("Couldn't read the file");
|
||||||
let mut parser = Parser::new(&content);
|
let mut parser = Parser::new(&content);
|
||||||
|
let Some(parent) = parser.parse() else {
|
||||||
println!("{:?}", parser.parse());
|
eprintln!(
|
||||||
|
"Failed to parse {} - See the errors above",
|
||||||
|
file.to_string_lossy()
|
||||||
|
);
|
||||||
|
std::process::exit(1);
|
||||||
|
};
|
||||||
|
println!("Parsed AST:\n{:#?}", parent);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user