Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait Volume {}
- struct RawChunk; impl Volume for RawChunk {}
- struct RleChunk; impl Volume for RleChunk {}
- struct FileChunk; impl Volume for FileChunk {}
- struct Container {
- raw: Option<RawChunk>,
- rle: Option<RleChunk>,
- file: Option<FileChunk>,
- }
- impl Container {
- fn get<'a>(&'a self, variant: i32) -> Option<&'a impl Volume> {
- match variant {
- 0 => self.raw.as_ref(),
- 1 => self.raw.as_ref(),
- 2 => self.raw.as_ref(),
- _ => panic!(),
- }
- }
- }
- fn main() {
- println!("Hello, world!");
- let container = Container {
- raw: Some(RawChunk),
- rle: Some(RleChunk),
- file: Some(FileChunk),
- };
- let rle = container.get(0);
- }
Add Comment
Please, Sign In to add comment