imservice: Use discriminants in enums

This commit is contained in:
Dorota Czaplejewicz
2019-07-31 09:50:26 +00:00
parent 8326bd7016
commit 58d01bf502

View File

@ -155,7 +155,7 @@ pub mod c {
eekboard_context_service_set_hint_purpose( eekboard_context_service_set_hint_purpose(
imservice.ui_manager, imservice.ui_manager,
imservice.current.content_hint.bits(), imservice.current.content_hint.bits(),
imservice.current.content_purpose.as_num()); imservice.current.content_purpose.clone() as u32);
} else { } else {
eekboard_context_service_hide_keyboard(imservice.ui_manager); eekboard_context_service_hide_keyboard(imservice.ui_manager);
} }
@ -200,22 +200,26 @@ bitflags!{
} }
/// Map to `text_input_unstable_v3.content_purpose` values /// Map to `text_input_unstable_v3.content_purpose` values
///
/// ```
/// assert_eq!(ContentPurpose::Alpha as u32, 0);
/// ```
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum ContentPurpose { pub enum ContentPurpose {
Normal, Normal = 0,
Alpha, Alpha = 1,
Digits, Digits = 2,
Number, Number = 3,
Phone, Phone = 4,
Url, Url = 5,
Email, Email = 6,
Name, Name = 7,
Password, Password = 8,
Pin, Pin = 9,
Date, Date = 10,
Time, Time = 11,
Datetime, Datetime = 12,
Terminal, Terminal = 13,
} }
impl ContentPurpose { impl ContentPurpose {
@ -239,32 +243,13 @@ impl ContentPurpose {
_ => None, _ => None,
} }
} }
fn as_num(self: &ContentPurpose) -> u32 {
use self::ContentPurpose::*;
match self {
Normal => 0,
Alpha => 1,
Digits => 2,
Number => 3,
Phone => 4,
Url => 5,
Email => 6,
Name => 7,
Password => 8,
Pin => 9,
Date => 10,
Time => 11,
Datetime => 12,
Terminal => 13,
}
}
} }
/// Map to `text_input_unstable_v3.change_cause` values /// Map to `text_input_unstable_v3.change_cause` values
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum ChangeCause { pub enum ChangeCause {
InputMethod, InputMethod = 0,
Other, Other = 1,
} }
impl ChangeCause { impl ChangeCause {
@ -275,12 +260,6 @@ impl ChangeCause {
_ => None _ => None
} }
} }
pub fn as_num(&self) -> u32 {
match &self {
ChangeCause::InputMethod => 0,
ChangeCause::Other => 1,
}
}
} }
/// Describes the desired state of the input method as requested by the server /// Describes the desired state of the input method as requested by the server