2 ms·
So in Rust, the equivalent of void* with references instead looks like: enum Void{} fn foo(v: &Void){ ... } let bar : Void; fn abc() -> &Void{
by vertex-four 10y ago
So in Rust, the equivalent of void* with references instead looks like:
enum Void{}
fn foo(v: &Void){ ... }
let bar : Void;
fn abc() -> &Void{ ...}
fn xyz() -> Void{ ... }
You can't create a Void, and you can't cast to it either - it's not a bottom type. So you can't put anything in bar. And as a result, you can't create a reference to a Void, so you can't call foo. And abc and xyz just can't be implemented in the first place.
On the other hand, you can do all of these just fine:
fn foo(v: ()){ ... }
fn bar(v: &()){ ... }
...
let v = ();
bar(&v);
foo(v);
The fact that you can create and use an empty tuple as a value shows that it is not equivalent to Void.
(All statements here are made within the safe subset of the language - unsafe allows access to intrinsics that would allow a Void to be made, and a reference to Void.)