← Back to Blog

2025-06-03

Rust struct vs TypeScript interface: What's the Difference?

Both Rust structs and TypeScript interfaces describe data shapes, but they work very differently. Here's what you need to know.

The Surface Similarity

Both struct in Rust and interface in TypeScript describe the shape of your data:

TypeScript:

export interface User {
  id: number;
  name: string;
}

Rust:

#[derive(Debug, Serialize, Deserialize)]
pub struct User {
    pub id: i64,
    pub name: String,
}

They look similar, but the implications are profoundly different.

Memory and Ownership

A TypeScript interface is a compile-time fiction — it disappears at runtime. The underlying JavaScript object is heap-allocated with no ownership semantics.

A Rust struct is a concrete memory layout. The compiler knows the exact byte size at compile time. Stack-allocated structs are possible and common.

Nullability

TypeScript uses | null or optional fields (?:). Rust uses Option<T>. Both force you to handle the absent case, but Rust's match on Option is exhaustive — the compiler won't let you ignore it.

Which to Use When?

Scenario Pick
Frontend web app TypeScript interface
High-performance API Rust struct
Microservice Go struct
.NET ecosystem C# record/class

The right tool depends on your runtime, not your data shape.

Your files never leave your machine. 100% Secure & Private.

Need to convert audio or video? mp3-converters.com — free MP4/WAV/M4A to MP3 converter, 100% in your browser.

Need to convert PDF files? pdf-word-converter.com — free PDF to Word, PDF to HTML, and HTML to PDF converter, 100% in your browser.

Works offline — install as an app via your browser's  "Add to Home Screen"  or "Install app" option.

Privacy Policy

© 2026 json-convert.com — Free, open, and private.