An enum can't be directly extended, but you use the same composition trick one would use with structs (that is, with a struct, one would have a field storing an instance of the 'parent').
enum Base {
Alpha,
Beta(usize),
}
enum Extended {
Base(Base),
Gamma
}
If you wish to handle each case individually, this is then used like
match some_extended {
Base(Alpha) => ...,
Base(Beta(x)) => ...,
Gamma => ...
}
but you can also share/re-use code from the "parent"
match some_extended {
Base(base) => base.do_something(),
Gamma => ...,
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…