patternrustMajor
Does Rust have an equivalent of C's typedef?
Viewed 0 times
havetypedefequivalentdoesrust
Problem
C offers the keyword
This basically makes
typedef which lets you alias another type:typedef unsigned int uint;
This basically makes
uint an alias for unsigned int. This also works with more complex types and structures too. Does Rust have a similar language feature? If yes, how are typedefs handled in Rust?Solution
Yes. You can simply write
These are aliases at the name level, i.e. it is absolutely immaterial which name for the same type you then use. They are perfectly interchangeable.
type MyInt = i32;These are aliases at the name level, i.e. it is absolutely immaterial which name for the same type you then use. They are perfectly interchangeable.
Code Snippets
type MyInt = i32;Context
Stack Overflow Q#47872494, score: 69
Revisions (0)
No revisions yet.