Add Rust support: usaco lang, lint, and main.rs problems
Brings in the stashed Rust work, merged onto the current CLI. A problem's language is whichever source it has (main.cpp or main.rs); 'usaco lang' sets the default for new problems (.lang, or $USACO_LANG), and 'new --rust/--cpp' picks per problem. template.rs is a paste-ready Rust template whose stdio() uses <io>.in/.out when present and stdin/stdout otherwise. run/test now feed <io>.in on stdin and capture stdout when the program doesn't write <io>.out itself, so Codeforces-style solutions work too. 'reset <name> rust|cpp' switches a problem's language (template is still an alias), and --debug builds Rust with overflow checks and debug assertions. 'usaco lint' runs clippy through a generated, gitignored Cargo.toml that also gives rust-analyzer a project; done/skip/undo keep it in step. LeetCode imports stay C++. Also: done stages solved/ and solving/ separately, so a problem that was never committed from solving/ still gets its "Solve" commit, and the site lists main.rs ahead of other files like it does main.cpp. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -16,7 +16,9 @@ const sections = [
|
||||
{
|
||||
title: "Start a problem",
|
||||
rows: [
|
||||
["usaco new <name>", "Create solving/<name>/ with main.cpp from the template and an empty .in file, then open it in $EDITOR."],
|
||||
["usaco new <name>", "Create solving/<name>/ with main.cpp (or main.rs) from the template and an empty .in file, then open it in $EDITOR."],
|
||||
["usaco new <name> --rust", "Pick the language for this problem (--cpp / --rust); otherwise the default from usaco lang."],
|
||||
["usaco lang [cpp|rust]", "Show or set the default language for new problems (stored in .lang; $USACO_LANG overrides it per shell)."],
|
||||
["usaco new <name> <io>", "Same, when the USACO file name differs from the problem name."],
|
||||
["usaco new <name> --url <link>", "Also save the problem link, for usaco open."],
|
||||
["usaco new <leetcode-link>", "Import a LeetCode problem (also usaco from): the statement as problem.md, LeetCode's C++ starter code in main.cpp, a generated driver.h that runs it on LeetCode-format input, and the examples as tests with their expected outputs."],
|
||||
@@ -26,11 +28,11 @@ const sections = [
|
||||
{
|
||||
title: "Build, run and test",
|
||||
rows: [
|
||||
["usaco run <name>", "Compile and run inside the problem dir (so file IO just works), then print the .out file."],
|
||||
["usaco build <name>", "Compile only: g++ -O2 -std=c++17 -Wall -Wextra -DLOCAL."],
|
||||
["usaco run <name>", "Compile and run inside the problem dir, feeding it the .in on stdin (so file-IO and stdin/stdout solutions both work), then print the .out file."],
|
||||
["usaco build <name>", "Compile only: g++ -O2 -std=c++17 -Wall -Wextra -DLOCAL, or rustc -O --edition 2021 for main.rs."],
|
||||
["usaco test create <name>", "Save a test case: tests/N.in (the current .in, or pasted) and the expected N.out."],
|
||||
["usaco test <name> [N…]", "Build, run every saved case (or just the ones given), diff, and show pass/fail with timings."],
|
||||
["--debug", "On run, build or test (or USACO_DEBUG=1): an ASan/UBSan + _GLIBCXX_DEBUG build, so out-of-bounds and UB crash with a stack trace."],
|
||||
["--debug", "On run, build or test (or USACO_DEBUG=1): an ASan/UBSan + _GLIBCXX_DEBUG build, so out-of-bounds and UB crash with a stack trace. Rust gets overflow checks and debug assertions."],
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -45,20 +47,21 @@ const sections = [
|
||||
{
|
||||
title: "Edit and look around",
|
||||
rows: [
|
||||
["usaco e <name>", "Open main.cpp in $EDITOR from inside the problem dir (also vim, edit)."],
|
||||
["usaco e <name>", "Open the solution in $EDITOR from inside the problem dir (also vim, edit)."],
|
||||
["usaco list", "All problems by status, oldest-touched first."],
|
||||
["usaco stats", "Counts, plus problems solved in the last 7 and 30 days."],
|
||||
["usaco open <name>", "Open the saved problem link in a browser."],
|
||||
["usaco cat <name>", "Print main.cpp to stdout."],
|
||||
["usaco copy <name>", "Copy main.cpp to the clipboard (wl-copy, xclip/xsel, or OSC52 over SSH)."],
|
||||
["usaco cat <name>", "Print the solution to stdout."],
|
||||
["usaco copy <name>", "Copy the solution to the clipboard (wl-copy, xclip/xsel, or OSC52 over SSH)."],
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Misc",
|
||||
rows: [
|
||||
["usaco reset <name>", "Fresh main.cpp from the template (the old one goes to main.cpp.bak). Asks first; -y skips. Keeps tests/ and the .in."],
|
||||
["usaco io <name> [new]", "Show the IO name, or rename the .in/.out and rewire STDIO."],
|
||||
["usaco reset <name> [cpp|rust]", "Fresh source from the template (the old one goes to a .bak); giving a language switches the problem to it. Asks first; -y skips. Keeps tests/ and the .in."],
|
||||
["usaco io <name> [new]", "Show the IO name, or rename the .in/.out and rewire STDIO / stdio."],
|
||||
["usaco clean", "Delete compiled binaries and .bak files everywhere."],
|
||||
["usaco lint [name…]", "Run clippy over the Rust solutions (or the named ones; template lints template.rs), refreshing the Cargo.toml rust-analyzer reads."],
|
||||
["usaco path <name>", "Print the problem's directory."],
|
||||
],
|
||||
},
|
||||
@@ -89,7 +92,7 @@ usaco [watermelon:solved]> q`;
|
||||
Every problem here is written in a workspace managed by <a :href="src('usaco')"><code>./usaco</code></a>, a small bash script at
|
||||
the root of <a :href="repo">the repo on Gitea</a> (the commands themselves are in
|
||||
<a :href="src('lib/cmd')"><code>lib/cmd/</code></a>). Each problem lives in <code>solving/</code>, <code>solved/</code> or
|
||||
<code>skipped/</code> as a directory with <code>main.cpp</code> and its <code>.in</code>/<code>.out</code>
|
||||
<code>skipped/</code> as a directory with <code>main.cpp</code> or <code>main.rs</code> and its <code>.in</code>/<code>.out</code>
|
||||
files. Wherever a command takes a problem name, a unique prefix works too:
|
||||
<code>usaco e diam</code> finds <code>diamond-collector</code>.
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user