rust-for-kotlin-devs
A complete Rust language guide for Kotlin developers — side-by-side comparisons, idiom cheat sheet, 7-day plan, and runnable examples.
File Explorer
- deploy-docs.yml
- header.png
- page.jsx
- layout.jsx
- theme.css
- _meta.js
- async-and-concurrency.mdx
- cheat-sheet.mdx
- collections-and-modules.mdx
- errors-and-traits.mdx
- fundamentals.mdx
- index.mdx
- learning-plan.mdx
- null-and-options.mdx
- ownership.mdx
- rust-vs-kotlin.mdx
- structs-and-enums.mdx
- tooling.mdx
- .gitignore
- .npmrc
- mdx-components.jsx
- next.config.mjs
- package.json
- pnpm-lock.yaml
- pnpm-workspace.yaml
- 01_ownership.rs
- 02_option.rs
- 03_enums_match.rs
- 04_result.rs
- 05_traits.rs
- 06_iterators.rs
- 07_async.rs
- 08_variables.rs
- 09_types_tuples.rs
- 10_strings.rs
- 11_functions_closures.rs
- 12_structs.rs
- 13_derive.rs
- 14_lifetimes.rs
- 15_generics.rs
- 16_modules.rs
- 17_concurrency.rs
- lib.rs
- .gitignore
- Cargo.toml
- LICENSE
- README.md
# Use via CDN
jsDelivrjsDelivr serves any public GitHub repository as a CDN with zero setup. Pick a version and a file to get a ready-to-paste link and snippet.
Command Glossary
Commands referenced in this DOCs, explained below.
interface
View Details ▼
interface
Manage interfaces.
Accessed in configuration mode.
interface vlan {{1}}
Configure a VLAN:
{{no shutdown|shutdown}}
Set an interface to be active or inactive (this is run inside the interface command):
cargo add
View Details ▼
cargo add
Add dependencies to a Rust project's `Cargo.toml` manifest.
cargo add {{dependency}}
Add the latest version of a dependency to the current project:
cargo add {{dependency}}@{{version}}
Add a specific version of a dependency:
cargo add {{dependency}} {{[-F|--features]}} {{feature_1,feature_2,...}}
Add a dependency and enable one or more specific features:
cargo build
View Details ▼
cargo build
Compile a local package and all of its dependencies.
cargo {{[b|build]}}
Build the package or packages defined by the `Cargo.toml` manifest file in the local path:
cargo {{[b|build]}} {{[-r|--release]}}
Build artifacts in release mode, with optimizations:
cargo {{[b|build]}} --locked
Require that `Cargo.lock` is up to date:
cargo check
View Details ▼
cargo check
Check a local package and all of its dependencies for errors.
cargo {{[c|check]}}
Check the current package:
cargo {{[c|check]}} --tests
Check all tests:
cargo {{[c|check]}} --test {{integration_test1}}
Check the integration tests in `tests/integration_test1.rs`:
cargo clippy
View Details ▼
cargo clippy
A collection of lints to catch common mistakes and improve your Rust code.
cargo clippy
Run checks over the code in the current directory:
cargo clippy --locked
Require that `Cargo.lock` is up to date:
cargo clippy --workspace
Run checks on all packages in the workspace:
cargo doc
View Details ▼
cargo doc
Build the documentation of Rust packages.
cargo {{[d|doc]}}
Build the documentation for the current project and all dependencies:
cargo {{[d|doc]}} --no-deps
Do not build documentation for dependencies:
cargo {{[d|doc]}} --open
Build and open the documentation in a browser:
cargo fmt
View Details ▼
cargo fmt
Run `rustfmt` on all source files in a Rust project.
See also: `rustfmt`.
cargo fmt
Format all source files:
cargo fmt --check
Check for formatting errors without writing to the files:
cargo fmt -- {{rustfmt_args}}
Pass arguments to each `rustfmt` call:
cargo new
View Details ▼
cargo new
Create a new Cargo package.
Equivalent of `cargo init`, but specifying a directory is required.
cargo new {{path/to/directory}}
Create a new Rust project with a binary target:
cargo run
View Details ▼
cargo run
Run the current Cargo package.
Note: The working directory of the executed binary will be set to the current working directory.
cargo {{[r|run]}}
Run the default binary target:
cargo {{[r|run]}} --bin {{name}}
Run the specified binary:
cargo {{[r|run]}} --example {{name}}
Run the specified example:
cargo test
View Details ▼
cargo test
Execute the unit and integration tests of a Rust package.
cargo {{[t|test]}} {{test_name}}
Only run tests containing a specific string in their names:
cargo {{[t|test]}} -- --test-threads {{count}}
Set the number of simultaneous running test cases:
cargo {{[t|test]}} {{[-r|--release]}}
Test artifacts in release mode, with optimizations:
fold
View Details ▼
fold
Wrap each line in an input file to fit a specified width and print it to `stdout`.
fold {{path/to/file}}
Wrap each line to default width (80 characters):
fold {{[-w|--width]}} {{width}} {{path/to/file}}
Fold lines in a fixed width:
fold -w30 {{path/to/file}}
Wrap each line to width "30":
gradle init
View Details ▼
gradle init
Initialize a new Gradle project interactively.
gradle init
Initialize a new Gradle project interactively:
gradle init --type {{basic|java-application|java-library|...}}
Initialize a project of a specific type:
gradle init --dsl {{groovy|kotlin}}
Initialize a project with a specific DSL:
join
View Details ▼
join
Join lines of two sorted files on a common field.
join {{path/to/file1}} {{path/to/file2}}
Join two files on the first (default) field:
join -t ',' {{path/to/file1}} {{path/to/file2}}
Join two files using a comma (instead of a space) as the field separator:
join -1 {{3}} -2 {{1}} {{path/to/file1}} {{path/to/file2}}
Join field3 of file1 with field1 of file2:
rustfmt
View Details ▼
rustfmt
Format Rust source code.
rustfmt {{path/to/source.rs}}
Format a file, overwriting the original file in-place:
rustfmt --check {{path/to/source.rs}}
Check a file for formatting and display any changes on the console:
rustfmt --backup {{path/to/source.rs}}
Backup any modified files before formatting (the original file is renamed with a `.bk` extension):
rustup
View Details ▼
rustup
Install, manage, and update Rust toolchains.
Some subcommands, such as `toolchain`, `target`, `update`, etc. have their own usage documentation.
rustup install nightly
Install the nightly toolchain for your system:
rustup default nightly
Switch the default toolchain to nightly so that the `cargo` and `rustc` commands will use it:
rustup override set nightly
Use the nightly toolchain when inside the current project but leave global settings unchanged:
select
View Details ▼
select
Bash builtin construct for creating menus.
select {{word}} in {{apple orange pear banana}}; do echo ${{word}}; done
Create a menu out of individual words:
select {{line}} in $({{command}}); do echo ${{line}}; done
Create a menu from the output of another command:
PS3="{{Select a file: }}"; select {{file}} in *; do echo ${{file}}; done
Specify the prompt string for `select` and create a menu for picking a file or folder from the current directory:
sum
View Details ▼
sum
Compute checksums and the number of blocks for a file.
A predecessor to the more modern `cksum`.
sum {{path/to/file}}
Compute a checksum with BSD-compatible algorithm and 1024-byte blocks:
sum {{[-s|--sysv]}} {{path/to/file}}
Compute a checksum with System V-compatible algorithm and 512-byte blocks:
suspend
View Details ▼
suspend
Suspend the execution of the current shell.
{{bash}} <Enter> suspend
Suspend the current shell (useful for when you are in nested shells like `su`):
pkill -CONT {{bash}}
Continue from suspension if `suspend` was used in a non-nested shell (run this in a separate terminal):
suspend -f
Force suspension even if this would lock you out of the system:
where
View Details ▼
where
Report all known instances of a command.
It could be an executable in the `$PATH` environment variable, an alias, or a shell builtin.
where {{command}}
Find all instances of a command:
tldr where-object
View the documentation of the equivalent PowerShell command:
where {{file_pattern}}
Display the location of file pattern:
copy
View Details ▼
copy
Copy files.
COPY {{path/to/source_file}} {{path/to/destination_file}}
Copy a file:
move
View Details ▼
move
Move or rename files and directories.
In PowerShell, this command is an alias of `Move-Item`. This documentation is based on the Command Prompt (`cmd`) version of `move`.
tldr move-item
View documentation of the equivalent PowerShell command:
move {{path\to\source}} {{path\to\target}}
Rename a file or directory when the target is not an existing directory:
move {{path\to\source}} {{path\to\existing_directory}}
Move a file or directory into an existing directory:
