chore: Replace as_any functions with trait upcasting (#28221)

Closes #ISSUE

Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2025-04-08 22:16:27 +02:00 committed by GitHub
parent 38ec45008c
commit 0b75c13034
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 23 additions and 87 deletions

View file

@ -42,13 +42,10 @@ use std::{
/// }
/// register_action!(Paste);
/// ```
pub trait Action: 'static + Send {
pub trait Action: Any + Send {
/// Clone the action into a new box
fn boxed_clone(&self) -> Box<dyn Action>;
/// Cast the action to the any type
fn as_any(&self) -> &dyn Any;
/// Do a partial equality check on this action and the other
fn partial_eq(&self, action: &dyn Action) -> bool;
@ -94,9 +91,9 @@ impl std::fmt::Debug for dyn Action {
}
impl dyn Action {
/// Get the type id of this action
pub fn type_id(&self) -> TypeId {
self.as_any().type_id()
/// Type-erase Action type.
pub fn as_any(&self) -> &dyn Any {
self as &dyn Any
}
}
@ -557,9 +554,6 @@ macro_rules! __impl_action {
::std::boxed::Box::new(self.clone())
}
fn as_any(&self) -> &dyn ::std::any::Any {
self
}
$($items)*
}

View file

@ -597,10 +597,6 @@ mod tests {
Box::new(TestAction)
}
fn as_any(&self) -> &dyn ::std::any::Any {
self
}
fn build(_value: serde_json::Value) -> anyhow::Result<Box<dyn Action>>
where
Self: Sized,