Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
LyonSyonII committed Feb 2, 2024
1 parent 04ec1c1 commit fc80821
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 48 deletions.
2 changes: 1 addition & 1 deletion runfile.run
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ cmd args(name age) {
echo "Hello $name, you are $age years old."
}

// You can read other arguments from the environment (argv in C).
// You can read other arguments from the environment (argv in C)
/// Try calling me with more than one argument!
rs cmd extra-args(first) {
println!("The first explicit argument is $first");
Expand Down
2 changes: 0 additions & 2 deletions src/lang/c.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::io::Write;

use crate::fmt::Str;

const BINARIES: &[&str] = &["gcc", "clang"];
Expand Down
6 changes: 5 additions & 1 deletion src/lang/csharp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ impl super::Language for CSharp {
&["dotnet-sdk"]
}

fn execute(&self, input: &str, args: impl AsRef<[String]>) -> Result<(), crate::fmt::Str<'static>> {
fn execute(
&self,
input: &str,
args: impl AsRef<[String]>,
) -> Result<(), crate::fmt::Str<'static>> {
super::execute_compiled(
"csharp",
"Program.cs",
Expand Down
44 changes: 0 additions & 44 deletions src/lang/rust.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::io::Write;

use crate::fmt::Str;

const BINARY: &str = "cargo";
Expand Down Expand Up @@ -44,45 +42,3 @@ impl super::Language for Rust {
)
}
}

/// Creates a new Rust project in the cache directory, sets the current directory to it and writes `input` into main.rs
fn create_project(mut program: std::process::Command, input: &str) -> Result<(), Str<'static>> {
let app_info = app_dirs2::AppInfo {
name: "runfile",
author: "lyonsyonii",
};
let path = format!("cache/rust/{:x}", md5::compute(input));
let Ok(path) = app_dirs2::app_dir(app_dirs2::AppDataType::UserCache, &app_info, &path) else {
return Err("Could not create project directory".into());
};

let Ok(_) = std::env::set_current_dir(&path) else {
return Err(format!("Could not set current directory to {path:?}").into());
};

if std::fs::metadata(path.join("Cargo.toml")).is_err() {
program
.arg("init")
.args(["--name", "runfile"])
// .stderr(std::process::Stdio::piped())
.spawn()
.map_err(|error| super::execution_failed(BINARY, error))?
.wait()
.map_err(|error| super::execution_failed(BINARY, error))?;
}

let path = path.join("src");

let Ok(_) = std::env::set_current_dir("./src") else {
return Err(format!("Could not set current directory to {path:?}").into());
};

let mut main = std::fs::File::create("main.rs")
.map_err(|e| format!("Could not create main.rs\nComplete error: {e}"))?;

let input = format!("fn main() {{\n{}\n}}", input);
main.write_all(input.as_bytes())
.map_err(|e| format!("Could not write input to main.rs\nComplete error: {e}"))?;

Ok(())
}

0 comments on commit fc80821

Please sign in to comment.