-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Alter Reflect::*_any methods to return remote type
- Loading branch information
Showing
7 changed files
with
73 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use quote::quote; | ||
|
||
/// A helper function for quickly implementing the `Reflect::*_any` methods while taking remote types into account. | ||
/// | ||
/// Specifically, this handles `Reflect::into_any`, `Reflect::as_any`, and `Reflect::as_any_mut`. | ||
pub(crate) fn impl_reflect_any_methods(is_remote_wrapper: bool) -> proc_macro2::TokenStream { | ||
if is_remote_wrapper { | ||
quote! { | ||
#[inline] | ||
fn into_any(self: Box<Self>) -> Box<dyn ::std::any::Any> { | ||
Box::new(self.0) | ||
} | ||
|
||
#[inline] | ||
fn as_any(&self) -> &dyn ::std::any::Any { | ||
&self.0 | ||
} | ||
|
||
#[inline] | ||
fn as_any_mut(&mut self) -> &mut dyn ::std::any::Any { | ||
&mut self.0 | ||
} | ||
} | ||
} else { | ||
quote! { | ||
#[inline] | ||
fn into_any(self: Box<Self>) -> Box<dyn ::std::any::Any> { | ||
self | ||
} | ||
|
||
#[inline] | ||
fn as_any(&self) -> &dyn ::std::any::Any { | ||
self | ||
} | ||
|
||
#[inline] | ||
fn as_any_mut(&mut self) -> &mut dyn ::std::any::Any { | ||
self | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod any; | ||
mod enums; | ||
mod structs; | ||
mod tuple_structs; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters