aboutsummaryrefslogtreecommitdiffstats
path: root/components/shared/script/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/script/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/script/lib.rs')
-rw-r--r--components/shared/script/lib.rs43
1 files changed, 4 insertions, 39 deletions
diff --git a/components/shared/script/lib.rs b/components/shared/script/lib.rs
index 31ced8764b5..5e0fe996e7a 100644
--- a/components/shared/script/lib.rs
+++ b/components/shared/script/lib.rs
@@ -50,6 +50,7 @@ use pixels::PixelFormat;
use profile_traits::{mem, time as profile_time};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use servo_url::{ImmutableOrigin, ServoUrl};
+use strum_macros::IntoStaticStr;
use style_traits::{CSSPixel, SpeculativePainter};
use stylo_atoms::Atom;
#[cfg(feature = "webgpu")]
@@ -288,7 +289,7 @@ pub enum UpdatePipelineIdReason {
/// Messages sent to the `ScriptThread` event loop from the `Constellation`, `Compositor`, and (for
/// now) `Layout`.
-#[derive(Deserialize, Serialize)]
+#[derive(Deserialize, IntoStaticStr, Serialize)]
pub enum ScriptThreadMessage {
/// Takes the associated window proxy out of "delaying-load-events-mode",
/// used if a scheduled navigated was refused by the embedder.
@@ -408,44 +409,8 @@ pub enum ScriptThreadMessage {
impl fmt::Debug for ScriptThreadMessage {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
- use self::ScriptThreadMessage::*;
- let variant = match *self {
- StopDelayingLoadEventsMode(..) => "StopDelayingLoadsEventMode",
- AttachLayout(..) => "AttachLayout",
- Resize(..) => "Resize",
- ThemeChange(..) => "ThemeChange",
- ResizeInactive(..) => "ResizeInactive",
- UnloadDocument(..) => "UnloadDocument",
- ExitPipeline(..) => "ExitPipeline",
- ExitScriptThread => "ExitScriptThread",
- SendInputEvent(..) => "SendInputEvent",
- Viewport(..) => "Viewport",
- GetTitle(..) => "GetTitle",
- SetDocumentActivity(..) => "SetDocumentActivity",
- SetThrottled(..) => "SetThrottled",
- SetThrottledInContainingIframe(..) => "SetThrottledInContainingIframe",
- NavigateIframe(..) => "NavigateIframe",
- PostMessage { .. } => "PostMessage",
- UpdatePipelineId(..) => "UpdatePipelineId",
- UpdateHistoryState(..) => "UpdateHistoryState",
- RemoveHistoryStates(..) => "RemoveHistoryStates",
- FocusIFrame(..) => "FocusIFrame",
- WebDriverScriptCommand(..) => "WebDriverScriptCommand",
- TickAllAnimations(..) => "TickAllAnimations",
- WebFontLoaded(..) => "WebFontLoaded",
- DispatchIFrameLoadEvent { .. } => "DispatchIFrameLoadEvent",
- DispatchStorageEvent(..) => "DispatchStorageEvent",
- ReportCSSError(..) => "ReportCSSError",
- Reload(..) => "Reload",
- PaintMetric(..) => "PaintMetric",
- ExitFullScreen(..) => "ExitFullScreen",
- MediaSessionAction(..) => "MediaSessionAction",
- #[cfg(feature = "webgpu")]
- SetWebGPUPort(..) => "SetWebGPUPort",
- SetScrollStates(..) => "SetScrollStates",
- SetEpochPaintTime(..) => "SetEpochPaintTime",
- };
- write!(formatter, "ConstellationControlMsg::{}", variant)
+ let variant_string: &'static str = self.into();
+ write!(formatter, "ConstellationControlMsg::{variant_string}")
}
}