Generalize `box` keyword to Rc and Arc and possibly other pointers


Hi all, I’m very new to Rust, so I’ll not be disappointed if someone will explain me that this idea is a nonsense.

When I see this code:

use std::rc::Rc;
use std::sync::Arc;

fn main() {
    let a: Box<i32> = box 1;
    let b: Rc<i32> = Rc::new(2);
    let c: Arc<i32> = Arc::new(3);
    println!("a = {}, b = {}, c = {}", *a, *b, *c);

I think: if box is something like a syntactic sugar for something like Box::new, why not generalize the boxing concept to other pointers too? Something similar to the * operator in the opposite sense.

That could be valuable for example to switch between Rc and Arc without involving macros.



This was always the intention, it just hasn’t been done yet.



Ok, thanks! I see the future of box has been discussed in this week meeting too.


closed #4

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.