mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Use strum
to iterate through enum variants and get their names (#35933)
`strum` allows us to avoid manually listing enum variant names and also to get their names as static strings. We cannot use this for all cases due to https://github.com/Peternator7/strum/issues/152, but we can still use it to remove a lot of code. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
959720db0a
commit
294a649a6c
17 changed files with 51 additions and 285 deletions
|
@ -19,6 +19,7 @@ use malloc_size_of_derive::MallocSizeOf;
|
|||
use num_derive::FromPrimitive;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use servo_url::ServoUrl;
|
||||
use strum_macros::IntoStaticStr;
|
||||
use url::Url;
|
||||
use webrender_api::units::{DeviceIntPoint, DeviceIntRect, DeviceIntSize};
|
||||
|
||||
|
@ -213,7 +214,7 @@ pub enum AllowOrDeny {
|
|||
Deny,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
#[derive(Deserialize, IntoStaticStr, Serialize)]
|
||||
pub enum EmbedderMsg {
|
||||
/// A status message to be displayed by the browser chrome.
|
||||
Status(WebViewId, Option<String>),
|
||||
|
@ -322,49 +323,9 @@ pub enum EmbedderMsg {
|
|||
}
|
||||
|
||||
impl Debug for EmbedderMsg {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
|
||||
match *self {
|
||||
EmbedderMsg::Status(..) => write!(f, "Status"),
|
||||
EmbedderMsg::ChangePageTitle(..) => write!(f, "ChangePageTitle"),
|
||||
EmbedderMsg::MoveTo(..) => write!(f, "MoveTo"),
|
||||
EmbedderMsg::ResizeTo(..) => write!(f, "ResizeTo"),
|
||||
EmbedderMsg::ShowSimpleDialog(..) => write!(f, "ShowSimpleDialog"),
|
||||
EmbedderMsg::RequestAuthentication(..) => write!(f, "RequestAuthentication"),
|
||||
EmbedderMsg::AllowUnload(..) => write!(f, "AllowUnload"),
|
||||
EmbedderMsg::AllowNavigationRequest(..) => write!(f, "AllowNavigationRequest"),
|
||||
EmbedderMsg::Keyboard(..) => write!(f, "Keyboard"),
|
||||
EmbedderMsg::ClearClipboard(..) => write!(f, "ClearClipboard"),
|
||||
EmbedderMsg::GetClipboardText(..) => write!(f, "GetClipboardText"),
|
||||
EmbedderMsg::SetClipboardText(..) => write!(f, "SetClipboardText"),
|
||||
EmbedderMsg::SetCursor(..) => write!(f, "SetCursor"),
|
||||
EmbedderMsg::NewFavicon(..) => write!(f, "NewFavicon"),
|
||||
EmbedderMsg::HistoryChanged(..) => write!(f, "HistoryChanged"),
|
||||
EmbedderMsg::NotifyFullscreenStateChanged(..) => {
|
||||
write!(f, "NotifyFullscreenStateChanged")
|
||||
},
|
||||
EmbedderMsg::NotifyLoadStatusChanged(_, status) => {
|
||||
write!(f, "NotifyLoadStatusChanged({status:?})")
|
||||
},
|
||||
EmbedderMsg::WebResourceRequested(..) => write!(f, "WebResourceRequested"),
|
||||
EmbedderMsg::Panic(..) => write!(f, "Panic"),
|
||||
EmbedderMsg::GetSelectedBluetoothDevice(..) => write!(f, "GetSelectedBluetoothDevice"),
|
||||
EmbedderMsg::SelectFiles(..) => write!(f, "SelectFiles"),
|
||||
EmbedderMsg::PromptPermission(..) => write!(f, "PromptPermission"),
|
||||
EmbedderMsg::ShowIME(..) => write!(f, "ShowIME"),
|
||||
EmbedderMsg::HideIME(..) => write!(f, "HideIME"),
|
||||
EmbedderMsg::AllowOpeningWebView(..) => write!(f, "AllowOpeningWebView"),
|
||||
EmbedderMsg::WebViewClosed(..) => write!(f, "WebViewClosed"),
|
||||
EmbedderMsg::WebViewFocused(..) => write!(f, "WebViewFocused"),
|
||||
EmbedderMsg::WebViewBlurred => write!(f, "WebViewBlurred"),
|
||||
EmbedderMsg::ReportProfile(..) => write!(f, "ReportProfile"),
|
||||
EmbedderMsg::MediaSessionEvent(..) => write!(f, "MediaSessionEvent"),
|
||||
EmbedderMsg::OnDevtoolsStarted(..) => write!(f, "OnDevtoolsStarted"),
|
||||
EmbedderMsg::RequestDevtoolsConnection(..) => write!(f, "RequestDevtoolsConnection"),
|
||||
EmbedderMsg::ShowContextMenu(..) => write!(f, "ShowContextMenu"),
|
||||
EmbedderMsg::PlayGamepadHapticEffect(..) => write!(f, "PlayGamepadHapticEffect"),
|
||||
EmbedderMsg::StopGamepadHapticEffect(..) => write!(f, "StopGamepadHapticEffect"),
|
||||
EmbedderMsg::ShutdownComplete => write!(f, "ShutdownComplete"),
|
||||
}
|
||||
fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error> {
|
||||
let string: &'static str = self.into();
|
||||
write!(formatter, "{string}")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue