Sitemap

Rustaceans

Exploring Rust: Insights and Expertise from Rustaceans

Rustlings: rc1.rs #Issue83 — Smart Pointers in Rust

Rustlings Challenge: rc1.rs Solution Walkthrough

4 min readOct 11, 2023
Press enter or click to view image in full size
Image by João Henrique Machado Silva

This is the Eighty-third (83rd) issue of the Rustlings series. In this issue, we provide solutions to Rustlings exercises along with detailed explanations. In this issue we will solve the challenge on rc1.rs.

Previous challenge #Issue 82

In Rust, smart pointers are variables that contain an address in memory and reference some other data, but they also have additional metadata and capabilities. Smart pointers in Rust often own the data they point to, while references only borrow data.

Rc<T> stands for Reference Counted, and it’s a smart pointer in Rust. It’s used to enable multiple ownership of data by keeping track of how many references there are to a given piece of data and allowing shared ownership without the need for explicit lifetimes or borrowing rules.

Here’s a basic example of using Rc<T>:

use std::rc::Rc;

fn main() {
let data = Rc::new(vec![1, 2, 3])…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web
Already have an account? Sign in
Rustaceans

Published in Rustaceans

Exploring Rust: Insights and Expertise from Rustaceans

John Philip

Written by John Philip

Dev | Life Café | Twitter at @amjohnphilip | Email: dxphilo@gmail.com

No responses yet

Write a response