What do people do when they have a keyword collision? Eg, I have a struct that I'd like to give a type
field:
pub enum Type {
Battery,
Mains,
}
pub struct PowerSupply {
type: Type,
}
I can do a syntactic change like type_
, or I can add more words like power_supply_type
. The first is ugly, the second verbose and redundant. What do people do in this sort of situation?
1 Like
Sometimes a synonym is ok -- perhaps kind
instead of type
.
1 Like
Rustc often abbreviates 'type' to 'ty'.
2 Likes
Or suffix it with an underscore, as in:
pub struct PowerSupply {
type_: Type,
}
1 Like
ty
for type
and krate
for crate
.
The problem with this is that kind
is already a term of art when talking about types...
1 Like
bugaevc
November 11, 2016, 5:52pm
6
But what do I do if i need this for FFI? How do I call a C function void type(void)
?
1 Like
extern {
#[link_name = "type"]
fn type_();
}
4 Likes