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:
Martin Robinson 2025-03-13 13:00:31 +01:00 committed by GitHub
parent 959720db0a
commit 294a649a6c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 51 additions and 285 deletions

View file

@ -18,6 +18,7 @@ use ipc_channel::ipc::IpcSender;
use log::warn;
use pixels::Image;
use script_traits::{AnimationState, ScriptThreadMessage, TouchEventResult};
use strum_macros::IntoStaticStr;
use style_traits::CSSPixel;
use webrender_api::DocumentId;
use webrender_traits::{CrossProcessCompositorApi, CrossProcessCompositorMessage};
@ -57,6 +58,7 @@ impl CompositorReceiver {
}
/// Messages from (or via) the constellation thread to the compositor.
#[derive(IntoStaticStr)]
pub enum CompositorMsg {
/// Alerts the compositor that the given pipeline has changed whether it is running animations.
ChangeRunningAnimationsState(WebViewId, PipelineId, AnimationState),
@ -112,24 +114,8 @@ pub struct CompositionPipeline {
}
impl Debug for CompositorMsg {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
match *self {
CompositorMsg::ChangeRunningAnimationsState(_, _, state) => {
write!(f, "ChangeRunningAnimationsState({:?})", state)
},
CompositorMsg::CreateOrUpdateWebView(..) => write!(f, "CreateOrUpdateWebView"),
CompositorMsg::RemoveWebView(..) => write!(f, "RemoveWebView"),
CompositorMsg::TouchEventProcessed(..) => write!(f, "TouchEventProcessed"),
CompositorMsg::CreatePng(..) => write!(f, "CreatePng"),
CompositorMsg::IsReadyToSaveImageReply(..) => write!(f, "IsReadyToSaveImageReply"),
CompositorMsg::SetThrottled(..) => write!(f, "SetThrottled"),
CompositorMsg::PipelineExited(..) => write!(f, "PipelineExited"),
CompositorMsg::NewWebRenderFrameReady(..) => write!(f, "NewWebRenderFrameReady"),
CompositorMsg::PendingPaintMetric(..) => write!(f, "PendingPaintMetric"),
CompositorMsg::LoadComplete(..) => write!(f, "LoadComplete"),
CompositorMsg::WebDriverMouseButtonEvent(..) => write!(f, "WebDriverMouseButtonEvent"),
CompositorMsg::WebDriverMouseMoveEvent(..) => write!(f, "WebDriverMouseMoveEvent"),
CompositorMsg::CrossProcess(..) => write!(f, "CrossProcess"),
}
fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error> {
let string: &'static str = self.into();
write!(formatter, "{string}")
}
}