{"id":17396840,"url":"https://github.com/faern/rustscript","last_synced_at":"2025-08-01T00:02:34.652Z","repository":{"id":90202593,"uuid":"77701772","full_name":"faern/rustscript","owner":"faern","description":"Use Rust as a scripting language","archived":false,"fork":false,"pushed_at":"2017-01-02T20:57:45.000Z","size":32,"stargazers_count":97,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-30T14:51:05.995Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/faern.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-30T17:55:43.000Z","updated_at":"2024-06-03T21:17:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"c1616b41-36b0-4ef1-b1bc-8e29ae704b8e","html_url":"https://github.com/faern/rustscript","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/faern/rustscript","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faern%2Frustscript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faern%2Frustscript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faern%2Frustscript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faern%2Frustscript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/faern","download_url":"https://codeload.github.com/faern/rustscript/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faern%2Frustscript/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268142838,"owners_count":24202860,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-31T02:00:08.723Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-16T13:13:30.901Z","updated_at":"2025-08-01T00:02:34.404Z","avatar_url":"https://github.com/faern.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rustscript\n\nUse Rust as a scripting language. Because RUST ALL THE THINGS etc. etc.\n\n## Installation\n\nCargo can install rustscript directly from the git url like this:\n```\ncargo install --git https://github.com/faern/rustscript\n```\n\nOptionally install it globally:\n```\nsudo cp ~/.cargo/bin/rustscript /usr/local/bin/\n```\n\n## Writing a script\n\nJust like a python or bash script start your file with a shebang telling your shell how to run your\nscript, like this: `#!/path/to/rustscript`.\n\n`rustscript` will automatically wrap your code in a main method, so just start scripting directly\nin the root of the file.\n\n```rust\n#!/usr/local/bin/rustscript\n\n#[macro_use] extern crate shells;\n\nuse std::process;\n\nlet (code, stdout, _stderr) = sh!(\"ping -c 3 127.0.0.1\");\nprintln!(\"Ping output: {}\", stdout);\nprocess::exit(code);\n```\n\nMake the script executable and run it:\n\n```\n$ chmod +x ./my_rust_pinger.rsc\n$ ./my_rust_pinger.rsc\n```\n\n### Importing external crates\n\nRustscript can pull in any crate from crates.io. As shown in the example above, just using\n`extern crate foo` will pull in `foo` for you. However, you might want to be more specific than that\n\n#### Importing specific versions of crates\n\nJust giving the name of the crate, like `extern crate foo;` will always pull in the latest version\nof that crate (`\"*\"` in Cargo.toml). You can specify a version requirement on the same format as\nyou would inside of `Cargo.toml` inside square brackets in the following way:\n\n```rust\nextern crate foo[*]; // Equivalent to just writing `extern crate foo;`\nextern crate bar[0.1]; // Will add `bar = \"0.1\"` to Cargo.toml\nextern crate baz[~1.1]; // Will add `baz = \"~1.1\"` to Cargo.toml\n```\n\n#### Importing crates with a different package name\n\nWhen rustscript compiles your script it will by default use the same package name as the crate name.\nThis does not always work as some crates have different package name than crate name. To solve\nthis, rustscript allow you to specify a package name in the square brackets followed by a semicolon\nand the desired version. If a package name is specified the version must be given and can't be left\nout. Explicitly use `*` to get the latest version.\n\n```rust\nextern crate rustc_serialize[rustc-serialize;*]; // Will put `rustc-serialize = \"*\"` in Cargo.toml\n```\n\n#### Use external crates from local paths or git urls\n\nThis is not supported yet.\n\n## Extra functionality\n\nSee the help output (`rustscript --help`) for more flags and extra functionality. For example, your\ncan make `rustscript` output the result of the script compilation even on success with:\n\n`$ rustscript -v ./my_rust_pinger.rsc`\n\n## Platform support\n\nThe idea is to support all major platforms, but because this is in an initial state only Linux\nhas been tested so far.\n\n## Ideas for the future\n\n* Automatic imports of large parts of stdlib for convenience\n  * std::io::*;\n  * std::fmt::*;\n  * std::path::*;\n* Allow importing crates from local paths and git urls\n* Allow importing modules from other files (`mod foobar;`)\n  * This is intentionally left out for now. If you need this then maybe you are not just writing a\n    small script. Then maybe you should be using cargo as normal and write a regular crate.\n\n## Internals\n\nThe first thing rustscript does is to calculate the hash of both the absolute path to your script\nand the content of the script. It then looks for the folder `\u003cuser cache\u003e/\u003cpath hash\u003e`, where\n`\u003cuser cache\u003e` is the user specific cache directory given by `app_dirs`. That directory is called\nthe *script cache*. If the folder is missing or the hash of the script content does not match the\ncontent of `\u003cscript cache\u003e/script_hash` then a script build is initiated.\n\n### Script build\n\nRustscript takes your script and creates a cargo crate out of it in the *script cache* directory.\nIt then builds that crate with the help of cargo. If the build fails the output of cargo will be\ndisplayed and rustscript aborts.\n\n### Script execution\n\nIf the cache did already contain the correct hash, or if the cargo build of the script succeeded,\nthen the built version of the script will be executed and all arguments given to the script will\nbe passed on to that subprocess.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaern%2Frustscript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffaern%2Frustscript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaern%2Frustscript/lists"}