0% found this document useful (0 votes)
3 views18 pages

A Little Bit About Rust For Web Developers

Rust is a modern programming language designed for performance and memory safety, utilizing concepts like ownership and borrowing to prevent common bugs. It is increasingly adopted in various tech environments, including Cloudflare and Discord, and is integrated into tools like SWC and Turbopack. While Rust offers advantages such as zero-cost abstractions and strong type safety, it also presents challenges like a steep learning curve and longer compilation times.

Uploaded by

mannyabeb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views18 pages

A Little Bit About Rust For Web Developers

Rust is a modern programming language designed for performance and memory safety, utilizing concepts like ownership and borrowing to prevent common bugs. It is increasingly adopted in various tech environments, including Cloudflare and Discord, and is integrated into tools like SWC and Turbopack. While Rust offers advantages such as zero-cost abstractions and strong type safety, it also presents challenges like a steep learning curve and longer compilation times.

Uploaded by

mannyabeb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

A Little Bit About Rust For

Web Developers
Discovering Rust and how its shaping new ways to write
programs

By: Muhammed Towfik Jemal


What is Rust?
Modern Systems Memory Safety
Programming Prevents common bugs and
A language built for security issues at compile
performance and safety without time.
garbage collector and runtime.

Runs Everywhere
Can be run on Web, Embedded System and Operating Systems.
Rust's Philosophy and Goals
Fearless Concurrency
Safe parallel programming without data races

Zero-cost Abstractions
High-level code with low-level performance

Memory Safety
Catch errors at compile time, not runtime
Rust is Already in Your Tools

SWC
Powers Next.js, replacing Babel with 20x faster compilation.

Turbopack
Vercel's Webpack replacement with massive speed
improvements.

esbuild & Parcel


Modern bundlers inspired by or built with Rust.
Tech’s Using Rust

Cloudflare Discord Linux & Ubuntu


Uses for cloudflare workers (with wasm) Handles millions of concurrent users with Integrating Rust into critical
and Pingora. low-latency services. infrastructure and kernel code.
Memory Handling
Rust's Approach Manual Memory Management (e.g.,
● Ownership and Borrowing C, C++) Approach
● No Runtime Overhead ● Explicit Control
● Explicit Lifetimes: ● Risk of Errors
● Zero-Cost Abstractions ( no garbage Collection) ● No Safety Guarantees

Garbage-Collected Languages (e.g., Java, Reference Counting (e.g., Swift, Python)


JavaScript, C#) Approach Approach
● Automatic Memory Management ● Automatic Deallocation (via Ref Counting)
● Non-deterministic Deallocation: ● Overhead
● Simplicity for Developers ● More Flexible than GC
● No Compile-Time Safety
Rust's Borrow Checker

Ownership Borrowing
Each value has a single owner variable References allow safe access to data

Validation Lifetimes
Compiler enforces rules at build time Track how long references stay valid
OwnerShip

● Each value has one owner


● When the owner goes out of scope, the value is automatically dropped
● You can move ownership to another variable, but only one owner exists at a time.
● You can borrow a value temporarily using references, but Rust enforces rules to prevent
data races and invalid memory access.
Borrowing
Mutable
● Allows read/write access to a value.
● Only one mutable borrow is allowed at a time.
● Prevents data races by enforcing exclusive access

Immutable
● Allows read-only access to a value.
● Many immutable borrows are allowed at the same time.
● Useful for functions or scopes that only need to inspect data.
LifeTimes

● Ensure that references are always valid — they prevent dangling references at compile
time.
● Rust usually infers lifetimes automatically, but sometimes you must annotate them
(e.g., in functions returning references).
● Lifetime annotations (like 'a) tell the compiler how long references must live relative to
each other.
● Lifetimes don’t affect program behavior at runtime — they exist only at compile time to
ensure memory safety.
Validation
Rust borrow checker validation prevents
● Use-after-free
● Double frees
● Dangling references
● Data races
● Aliasing bugs
● Unsafe mutation
● Using a reference to data that's already been dropped
Developer Experience
Cargo Crates.io
All-in-one package manager, Rich ecosystem of reusable
build tool, and test runner. packages.
• Dependency management • Over 100,000 packages
• Consistent project structure • Semantic versioning
• Built-in testing framework • Strong security focus

Tooling
First-class developer tools make coding enjoyable.

• Excellent error messages


• IDE integration
• Documentation generators
Pros & Cons

Pros Cons
• Memory Safety Without Garbage Collection • Steep Learning Curve
• Performance • Compilation Time
• Concurrency and Parallelism • Limited Ecosystem Compared to More
• Strong Type System and Compile-Time Safety Mature Languages
• Cross-Platform and Embedded Development • Smaller Talent Pool
• Zero-Cost Abstractions • Less Mature Tooling for Some Domains
• Growing Ecosystem and Tooling
When To Use Rust

1. Performance-Critical Applications

2. Memory Safety Without GC

3. Concurrency and Parallelism

4. Embedded and Low-Level Systems

5. Large-Scale Software with High Safety

Requirements
When Not To Use Rust

1. Rapid Development Need

2. Non-Systems or Non-Performance-Critical

Workloads

3. Simple CRUD APPS


Why Really Learn Rust ?
(My Take)
1. To Write Performant Code

2. To Have a Memory-First Mindset

3. To Understand Concurrency

4. To Understand Low-Level Programming

5. To Understand JavaScript Tools Written in Rust


Where To Learn?

1. The Rust Book

2. Rustlings Course

3. Rust By Example
Ownership taken. Bugs avoided.
Rust on.

Open For Any Questions

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy