How can you call new on an alias type?


#1

Hi everyone,

I’m looking for a way to call new on an alias type like the following:

type Flag = Arc<Mutex<bool>>

Because the following doesn’t work:

flag : Flag::new(false);

Any ideas?

Thank you very much!


#2

For now, you can’t:


#3

There’s no Arc::<Mutex<bool>>::new(bool) so how could that have worked?


#4

Now I have the following:

flag: Arc<Mutex<bool>>

flag: Arc::new(Mutex::new(false));

#5

I mean, that type you’re aliasing Flag to doesn’t have a new constructor that takes bool. But you can add a constructor with a different name.


#6

Ah, ok. I just wanted to know if the compiler was able to figure it out by itself.