Defining a method for a struct only when a field is a certain enum variant?
问题 I have the following struct: #[derive(Debug)] pub struct Entry { pub index: usize, pub name: String, pub filename_offset: u64, pub entry_type: EntryType, } #[derive(Debug)] pub enum EntryType { File { file_offset: u64, length: usize, }, Directory { parent_index: usize, next_index: usize, }, } Entry is an entry in a GameCube ROM file system table which describes a file or directory. I defined various methods for Entry such as Entry::read_filename and Entry::write_to_disk . However, I have some