mismatched types expected `i32`, found `PayPeroidType`

  Kiến thức lập trình

I have define the enum PayPeroidType in Rust like this:

#[derive(Debug, PartialEq, PartialOrd, Eq)]
pub enum PayPeroidType {
    DAY = 1,
    OneMonth = 2,
    ThreeMonth = 3,
    SixMonth = 4,
    OneYear = 5
}

impl From<PayPeroidType> for i32 {
    fn from(online_status: PayPeroidType) -> Self {
        match online_status {
            PayPeroidType::DAY => 1,
            PayPeroidType::OneMonth => 2,
            PayPeroidType::ThreeMonth => 3,
            PayPeroidType::SixMonth => 4,
            PayPeroidType::OneYear => 5,
        }
    }
}

then I want to match the enum from entity peroid define like this:

fn get_sub_time(iap_product: &IapProduct, bas_time: &i64) -> i64 {
    match iap_product.period {
        PayPeroidType::DAY => 1,
    }
}

but the code shows error:

mismatched types
expected `i32`, found `PayPeroidType`

I have tried to convert to i32 like this:

fn get_sub_time(iap_product: &IapProduct, bas_time: &i64) -> i64 {
    match iap_product.period {
        PayPeroidType::DAY as i32 => 1,
    }
}

seems did not work.Am I missing something? what should I do to matched the enum?

LEAVE A COMMENT