@vocs/twoslash-rust
v0.1.0
Published
Twoslash backend for Rust code, powered by `rust-analyzer`. Extracts type information, hover docs, and completions from Rust code.
Readme
twoslash-rust
Twoslash backend for Rust code, powered by rust-analyzer. Extracts type information, hover docs, and completions from Rust code.
Installation
cargo install twoslash-rustUsage
Pipe Rust code to the binary via stdin:
echo 'fn main() { let x = 42; }' | twoslash-rustOutput is JSON with type information:
{
"hovers": [
{
"text": "i32",
"line": 0,
"character": 16,
"length": 1
}
],
"queries": [],
"completions": [],
"highlights": [],
"errors": []
}Use twoslash query markers (// ^?) to extract types at specific positions:
echo 'fn main() {
let x = 42;
// ^?
}' | twoslash-rustOptions
--cargo-toml <path>— Use a customCargo.tomlfor dependencies--target-dir <path>— Specify a custom target directory for caching
Server Mode
Set TWOSLASH_SERVER_UUID to run as a persistent TCP server for faster repeated queries:
TWOSLASH_SERVER_UUID=abc123 twoslash-rust
# Outputs: 127.0.0.1:<port>Development
Build the binary:
cargo build --releaseUse --release for development. rust-analyzer is slow at indexing sysroot in debug builds.
