aboutsummaryrefslogtreecommitdiffstats
path: root/components/shared/embedder/lib.rs
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2025-03-13 13:00:31 +0100
committerGitHub <noreply@github.com>2025-03-13 12:00:31 +0000
commit294a649a6c96ea0fba05fad59a41dea6c7f1d66d (patch)
tree5b3de846c3e4954ff7e4d3af666d3c82108b09f9 /components/shared/embedder/lib.rs
parent959720db0a15d207e31e44ffd58d76e9e31b18c9 (diff)
downloadservo-294a649a6c96ea0fba05fad59a41dea6c7f1d66d.tar.gz
servo-294a649a6c96ea0fba05fad59a41dea6c7f1d66d.zip
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>
Diffstat (limited to 'components/shared/embedder/lib.rs')
-rw-r--r--components/shared/embedder/lib.rs49
1 files changed, 5 insertions, 44 deletions
diff --git a/components/shared/embedder/lib.rs b/components/shared/embedder/lib.rs
index a40942500e7..c1c45c52417 100644
--- a/components/shared/embedder/lib.rs
+++ b/components/shared/embedder/lib.rs
@@ -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}")
}
}