If we can do pub use u8 as GameState
, pub use () as GameState
should also be okay.
I didn't know you could do that with u8
, but I think the grammar is pretty firm that ()
is not a valid path for use
. You should be able to write pub type GameState = ();
for the same effect though.
i think it would be nice to allow use () as X
but it is a bit weird to allow use () as X
but not stuff like use ((),) as X
though. The issue with type GameState = ();
is that it doesn't add an alias for ()
to the value namespace, e.g. consider
struct Unit;
use Unit as GameState1;
type GameState2 = Unit;
fn main() {
let _ = GameState1;
let _ = GameState2; // error[E0423]: expected value, found type alias `GameState2`
}
Also, if you need both type and value, consider doing this:
pub type GameState = ();
pub const GameState: GameState = ();
(you may need to silence a warning about style, if you really want this)
Ok, but you don't get a value with use u8
either.
u8
isn't a value, though. If you use UnitStruct
you get the value as well.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.