.rs File Extension

Learn what a .rs file contains, how to open and build Rust source code, how Poly supports it, and how it fits into a Cargo project.

File extension details for .rs

Full Support
File typeRust source code
MIME type
EncodingUTF-8 Unicode plain text
Operating systemsWindows, macOS, Linux
Opens withVisual Studio Code, RustRover, Vim or Neovim, Any text editor
Poly supportYes. Poly recognizes .rs as readable Rust source code.
Indexed by PolyYes. Poly indexes readable source for exact and semantic search.
Preview in PolyYes. Rust source opens in Poly's code editor with syntax highlighting.
Poly agentYes. The Poly agent can read and reason about the source text.

What kind of file is a .rs?

A .rs file contains source code for the Rust programming language. It is editable text, not a compiled executable. The Rust Reference defines .rs as the source-file extension and explains that one input file forms the root of a crate, which can load other .rs files as modules.1

Rust requires valid UTF-8 source. The compiler removes an initial byte-order mark and normalizes CRLF line endings before tokenizing the file.2 There are no fixed magic bytes, so tools identify Rust source from its suffix, project context, and syntax. IANA does not register a Rust-specific media type. Some software uses unregistered labels such as text/x-rust, while Poly treats .rs as readable text/plain.3

Renaming another text file to .rs does not translate it into Rust or prove that it will compile. Building Rust source creates separate artifacts and leaves the source file as text.

How do I open a .rs on my computer?

Any text editor can open .rs files on Windows, macOS, or Linux. Visual Studio Code with rust-analyzer, JetBrains RustRover, Vim, Neovim, and Emacs can add syntax highlighting, completion, navigation, formatting, and diagnostics. Microsoft recommends rust-analyzer for Rust work in Visual Studio Code.4

Install Rust with rustup when you need to check, test, or build a project. From the directory containing Cargo.toml, common commands are:

cargo check
cargo test
cargo build
cargo fmt

Opening source as text does not execute it. Building an unfamiliar Cargo package can compile dependencies and run a package's build.rs script before the rest of the package, so review untrusted projects and use an isolated environment.5

Poly support for .rs

Poly opens .rs files in a code-friendly viewer with Rust syntax highlighting, word wrap, and in-file search. It indexes readable source for exact and semantic search, so you can find a symbol by name or search for code by its likely purpose. The Poly agent can summarize a module, explain a trait implementation, and help trace behavior across the source you provide.

Poly does not compile or run code, fetch crates, execute build scripts, or reproduce rust-analyzer's project state. Keep related source, Cargo.toml, Cargo.lock, tests, and documentation together when workspace-level context matters.

History of .rs

Rust 1.0 was released on May 15, 2015, with an emphasis on reliable, efficient systems programming without requiring a garbage collector or runtime.6 The .rs suffix was already Rust's established source-file convention and remains the extension specified by the language reference.

Rust has evolved through editions while retaining that suffix. A filename alone does not identify the Rust edition or minimum compiler version. Cargo configuration and the source itself provide that context.

Cargo uses conventional locations to decide how Rust source participates in a package:7

File or pathTypical role
src/main.rsDefault executable crate root
src/lib.rsDefault library crate root
src/bin/name.rsAdditional executable target
tests/name.rsIntegration test target
build.rsBuild script that Cargo may compile and run
Cargo.tomlPackage manifest, not Rust source

Use cargo fmt for consistent formatting and cargo test to run the project's tests.8 Keep .rs files and manifests in version control. Build artifacts under target/ are normally reproducible and should not be confused with the source. To create WebAssembly, a native executable, or a library, compile the project for the appropriate target rather than changing the filename extension.

Footnotes

  1. Rust Project. Crates and Source Files. Defines .rs source files, crate roots, and modules.
  2. Rust Project. The Rust Reference: Input Format. Specifies UTF-8 input, byte-order-mark removal, and CRLF normalization.
  3. Internet Assigned Numbers Authority. Media Types Registry. The registry has no Rust-specific media type.
  4. Microsoft. Rust in Visual Studio Code. Documents rust-analyzer installation and editor features.
  5. Rust Project. Cargo Build Scripts. Explains that Cargo compiles and runs build.rs before building a package.
  6. Rust Core Team. Announcing Rust 1.0.
  7. Rust Project. Cargo Package Layout. Documents conventional source, binary, test, and build-script paths.
  8. Rust Project. Useful Development Tools. Describes rustfmt and cargo fmt.
© Poly Corp. 2026