Yet another thing that irks me in rust

let zero = Box::<u32>::new_zeroed();
let zero = unsafe { zero.assume_init() };

assert_eq!(*zero, 0)//<<HERE!!!

Why is '*zero' instead of just zero?
If we don't have to have 'zero->assume_init()', note the -> operator for pointers from C/C++, because that's how we access objects via pointer in C/C++, why do we HAVE TO HAVE zero, the '', also known as dereference operator? Especially in view of the fact that rust does have trait defer. For christ sake, to me rust is a language with great intentions but so terribly executed...
Rust is half baked, that's all I can say.

Is there a question here, or are you posting just to rant?

6 Likes

Please study the type system of the language before making strong unfounded assertions. You'll discover pretty quickly why you need a dereference here.

5 Likes

Maybe it becomes clearer when you write out all types:

let zero: Box<MaybeUninit<u32>> = Box::<u32>::new_zeroed();
let zero: Box<u32> = unsafe { zero.assume_init() };

assert_eq!(*zero, 0)//<<HERE!!!

Edit: mixed up the type of the first zero.

3 Likes

You seem to misunderstood my point. If rust does NOT need '->' operator with usage of pointer why does it needs '*' operator? Please explain that to me.

Typically when I start to have those thoughts about some aspect of Rust I soon discover that I did not understand the situation very well in the first place. That there is a reason why things are as they are and people much smarter than I have thought it through very thoroughly.

7 Likes

The implicit derefs that make -> unnecessary only happen when performing a method call. It doesn't happen in any other case.

No... It is simply not well thought...
If rust doesn't need '->' operator whilst operating with pointers it SHOULD NOT need '*'.

Because the arrow operator in C++ was a hack in the first place.

1 Like

Why?

Do you perhaps know of the Deref trait?

Any link that will actually support your opinion?

image

I don't understand what you even want in this case? zero and *zero are not even the same type. Deref is a nice convenience, but it's not like it has truly turned a Box<T> into a T

1 Like

I agree, the '->' in C++ seemed like a hack to me way back when C++ was a new thing.

Link to the source to confirm your feeling.

Adding auto-deref to operators is definitely something that could be useful. There was some work on this in the past in issue #44762 and RFC #2147. See those issues for details of some of the changes required and any open questions. It looks like this could maybe use someone interested in completing that work.

However, I must ask you again to not try to argue with every single response to your posts, and to please focus on requesting information about why things are a certain way, rather than simply criticizing. If you continue in this vein, your account will be banned. Thank you.

13 Likes

Why not?

How can I not argue with every possible person when every possible person doesn't seem to understand the problem I'm presenting. Even your post confirms my feelings towards auto deref, so it is not like I'm trying to start some language war here.
I simply am stating that there are some things in rust that irks me and are half baked. That's all.

Because if rust could get rid of '->' is should also get rid of '*'. To make the language clear/clean.

Sorry, I'm interested in using rust not working on it.