Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Rust Fundamentals

Lesson 38 of 50 · rust

Unsafe Rust

Duration: 15 minutes

Unsafe Rust\n\nunsafe blocks allow you to perform operations the compiler cannot guarantee safety for, such as dereferencing raw pointers.\n\nrust\nfn main() {\n let mut num = 5;\n let r1 = &num as *const i32;\n let r2 = &mut num as *mut i32;\n unsafe {\n println!(\"r1 points to: {}\", *r1);\n *r2 = 10;\n }\n println!(\"num is now: {}\", num);\n}\n\n\nUse unsafe sparingly and encapsulate it in safe abstractions.

Previous: Mutexes and Shared StateNext: Foreign Function Interface (FFI)