Serialize option enums to u8, for backward compatibility.
This commit is contained in:
		
							parent
							
								
									41be111857
								
							
						
					
					
						commit
						8901e0e8b0
					
				
					 2 changed files with 217 additions and 80 deletions
				
			
		| 
						 | 
				
			
			@ -1,9 +1,12 @@
 | 
			
		|||
use std::marker::PhantomData;
 | 
			
		||||
 | 
			
		||||
use serde::{Deserialize, Serialize};
 | 
			
		||||
 | 
			
		||||
use crate::InvalidEnumError;
 | 
			
		||||
 | 
			
		||||
#[derive(Debug)]
 | 
			
		||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
 | 
			
		||||
#[repr(u8)]
 | 
			
		||||
#[serde(into = "u8", try_from = "u8")]
 | 
			
		||||
pub enum BossType {
 | 
			
		||||
    Kholdstare,
 | 
			
		||||
    Moldorm,
 | 
			
		||||
| 
						 | 
				
			
			@ -22,6 +25,29 @@ pub enum BossType {
 | 
			
		|||
    NoBoss = 255,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl From<BossType> for u8 {
 | 
			
		||||
    fn from(t: BossType) -> u8 {
 | 
			
		||||
        use BossType::*;
 | 
			
		||||
 | 
			
		||||
        match t {
 | 
			
		||||
            Kholdstare => 0,
 | 
			
		||||
            Moldorm => 1,
 | 
			
		||||
            Mothula => 2,
 | 
			
		||||
            Vitreous => 3,
 | 
			
		||||
            Helmasaur => 4,
 | 
			
		||||
            Armos => 5,
 | 
			
		||||
            Lanmola => 6,
 | 
			
		||||
            Blind => 7,
 | 
			
		||||
            Arrghus => 8,
 | 
			
		||||
            Trinexx => 9,
 | 
			
		||||
            Agahnim => 10,
 | 
			
		||||
            Agahnim2 => 11,
 | 
			
		||||
            Ganon => 12,
 | 
			
		||||
            NoBoss => 255,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl TryFrom<u8> for BossType {
 | 
			
		||||
    type Error = InvalidEnumError<Self>;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue