@@ -25,7 +25,6 @@ impl Box<dyn Any> {
2525 self . 0 . into_any ( )
2626 }
2727}
28- #[ allow( clippy:: use_self) ]
2928impl Box < dyn Any + Send > {
3029 /// Convert into a `std::boxed::Box<dyn std::any::Any + Send>`.
3130 pub fn into_any_send ( self ) -> boxed:: Box < dyn any:: Any + Send > {
@@ -34,7 +33,6 @@ impl Box<dyn Any + Send> {
3433 }
3534 }
3635}
37- #[ allow( clippy:: use_self) ]
3836impl Box < dyn Any + Sync > {
3937 /// Convert into a `std::boxed::Box<dyn std::any::Any + Sync>`.
4038 pub fn into_any_sync ( self ) -> boxed:: Box < dyn any:: Any + Sync > {
@@ -43,7 +41,6 @@ impl Box<dyn Any + Sync> {
4341 }
4442 }
4543}
46- #[ allow( clippy:: use_self) ]
4744impl Box < dyn Any + Send + Sync > {
4845 /// Convert into a `std::boxed::Box<dyn std::any::Any + Send + Sync>`.
4946 pub fn into_any_send_sync ( self ) -> boxed:: Box < dyn any:: Any + Send + Sync > {
@@ -504,13 +501,11 @@ impl<'a> AsRef<Self> for dyn Error + Send + 'a {
504501 }
505502}
506503
507- #[ allow( clippy:: use_self) ]
508504impl < ' a , E : error:: Error + Serialize + Deserialize + ' a > From < E > for Box < dyn Error + ' a > {
509505 fn from ( err : E ) -> Self {
510506 Box :: new ( err)
511507 }
512508}
513- #[ allow( clippy:: use_self) ]
514509impl < ' a , E : error:: Error + Serialize + Deserialize + ' a > From < E > for boxed:: Box < dyn Error + ' a > {
515510 fn from ( err : E ) -> Self {
516511 boxed:: Box :: new ( err)
@@ -858,3 +853,184 @@ impl<'de, Args: 'static, Output: 'static> serde::de::Deserialize<'de>
858853 . map ( |x| x. 0 )
859854 }
860855}
856+
857+ /// Convenience traits implemented on all (de)serializable implementors of [`serde_closure::traits::*`](serde_closure::traits).
858+ #[ cfg( feature = "serde_closure" ) ]
859+ pub mod sc {
860+ use super :: { serialize, Box , Deserialize , Serialize } ;
861+ use serde_closure:: traits as sc;
862+ use std:: boxed;
863+
864+ /// A convenience trait implemented on all (de)serializable implementors of [`serde_closure::traits::FnOnce`].
865+ ///
866+ /// It can be made into a trait object which is then (de)serializable.
867+ pub trait FnOnce < Args > : sc:: FnOnceBox < Args > + Serialize + Deserialize { }
868+ impl < T : ?Sized , Args > FnOnce < Args > for T where T : sc:: FnOnceBox < Args > + Serialize + Deserialize { }
869+
870+ impl < ' a , Args , Output > AsRef < Self > for dyn FnOnce < Args , Output = Output > + ' a {
871+ fn as_ref ( & self ) -> & Self {
872+ self
873+ }
874+ }
875+ impl < ' a , Args , Output > AsRef < Self > for dyn FnOnce < Args , Output = Output > + Send + ' a {
876+ fn as_ref ( & self ) -> & Self {
877+ self
878+ }
879+ }
880+
881+ impl < Args : ' static , Output : ' static > serde:: ser:: Serialize for dyn FnOnce < Args , Output = Output > {
882+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
883+ where
884+ S : serde:: Serializer ,
885+ {
886+ serialize ( self , serializer)
887+ }
888+ }
889+ impl < ' de , Args : ' static , Output : ' static > serde:: de:: Deserialize < ' de >
890+ for boxed:: Box < dyn FnOnce < Args , Output = Output > + ' static >
891+ {
892+ fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
893+ where
894+ D : serde:: Deserializer < ' de > ,
895+ {
896+ <Box < dyn FnOnce < Args , Output = Output > + ' static > >:: deserialize ( deserializer)
897+ . map ( |x| x. 0 )
898+ }
899+ }
900+ impl < Args : ' static , Output : ' static > serde:: ser:: Serialize
901+ for dyn FnOnce < Args , Output = Output > + Send
902+ {
903+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
904+ where
905+ S : serde:: Serializer ,
906+ {
907+ serialize ( self , serializer)
908+ }
909+ }
910+ impl < ' de , Args : ' static , Output : ' static > serde:: de:: Deserialize < ' de >
911+ for boxed:: Box < dyn FnOnce < Args , Output = Output > + Send + ' static >
912+ {
913+ fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
914+ where
915+ D : serde:: Deserializer < ' de > ,
916+ {
917+ <Box < dyn FnOnce < Args , Output = Output > + Send + ' static > >:: deserialize ( deserializer)
918+ . map ( |x| x. 0 )
919+ }
920+ }
921+
922+ /// A convenience trait implemented on all (de)serializable implementors of [`serde_closure::traits::FnMut`].
923+ ///
924+ /// It can be made into a trait object which is then (de)serializable.
925+ pub trait FnMut < Args > : sc:: FnMut < Args > + Serialize + Deserialize { }
926+ impl < T : ?Sized , Args > FnMut < Args > for T where T : sc:: FnMut < Args > + Serialize + Deserialize { }
927+
928+ impl < ' a , Args , Output > AsRef < Self > for dyn FnMut < Args , Output = Output > + ' a {
929+ fn as_ref ( & self ) -> & Self {
930+ self
931+ }
932+ }
933+ impl < ' a , Args , Output > AsRef < Self > for dyn FnMut < Args , Output = Output > + Send + ' a {
934+ fn as_ref ( & self ) -> & Self {
935+ self
936+ }
937+ }
938+
939+ impl < Args : ' static , Output : ' static > serde:: ser:: Serialize for dyn FnMut < Args , Output = Output > {
940+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
941+ where
942+ S : serde:: Serializer ,
943+ {
944+ serialize ( self , serializer)
945+ }
946+ }
947+ impl < ' de , Args : ' static , Output : ' static > serde:: de:: Deserialize < ' de >
948+ for boxed:: Box < dyn FnMut < Args , Output = Output > + ' static >
949+ {
950+ fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
951+ where
952+ D : serde:: Deserializer < ' de > ,
953+ {
954+ <Box < dyn FnMut < Args , Output = Output > + ' static > >:: deserialize ( deserializer)
955+ . map ( |x| x. 0 )
956+ }
957+ }
958+ impl < Args : ' static , Output : ' static > serde:: ser:: Serialize
959+ for dyn FnMut < Args , Output = Output > + Send
960+ {
961+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
962+ where
963+ S : serde:: Serializer ,
964+ {
965+ serialize ( self , serializer)
966+ }
967+ }
968+ impl < ' de , Args : ' static , Output : ' static > serde:: de:: Deserialize < ' de >
969+ for boxed:: Box < dyn FnMut < Args , Output = Output > + Send + ' static >
970+ {
971+ fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
972+ where
973+ D : serde:: Deserializer < ' de > ,
974+ {
975+ <Box < dyn FnMut < Args , Output = Output > + Send + ' static > >:: deserialize ( deserializer)
976+ . map ( |x| x. 0 )
977+ }
978+ }
979+
980+ /// A convenience trait implemented on all (de)serializable implementors of [`serde_closure::traits::Fn`].
981+ ///
982+ /// It can be made into a trait object which is then (de)serializable.
983+ pub trait Fn < Args > : sc:: Fn < Args > + Serialize + Deserialize { }
984+ impl < T : ?Sized , Args > Fn < Args > for T where T : sc:: Fn < Args > + Serialize + Deserialize { }
985+
986+ impl < ' a , Args , Output > AsRef < Self > for dyn Fn < Args , Output = Output > + ' a {
987+ fn as_ref ( & self ) -> & Self {
988+ self
989+ }
990+ }
991+ impl < ' a , Args , Output > AsRef < Self > for dyn Fn < Args , Output = Output > + Send + ' a {
992+ fn as_ref ( & self ) -> & Self {
993+ self
994+ }
995+ }
996+
997+ impl < Args : ' static , Output : ' static > serde:: ser:: Serialize for dyn Fn < Args , Output = Output > {
998+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
999+ where
1000+ S : serde:: Serializer ,
1001+ {
1002+ serialize ( self , serializer)
1003+ }
1004+ }
1005+ impl < ' de , Args : ' static , Output : ' static > serde:: de:: Deserialize < ' de >
1006+ for boxed:: Box < dyn Fn < Args , Output = Output > + ' static >
1007+ {
1008+ fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
1009+ where
1010+ D : serde:: Deserializer < ' de > ,
1011+ {
1012+ <Box < dyn Fn < Args , Output = Output > + ' static > >:: deserialize ( deserializer) . map ( |x| x. 0 )
1013+ }
1014+ }
1015+ impl < Args : ' static , Output : ' static > serde:: ser:: Serialize
1016+ for dyn Fn < Args , Output = Output > + Send
1017+ {
1018+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
1019+ where
1020+ S : serde:: Serializer ,
1021+ {
1022+ serialize ( self , serializer)
1023+ }
1024+ }
1025+ impl < ' de , Args : ' static , Output : ' static > serde:: de:: Deserialize < ' de >
1026+ for boxed:: Box < dyn Fn < Args , Output = Output > + Send + ' static >
1027+ {
1028+ fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
1029+ where
1030+ D : serde:: Deserializer < ' de > ,
1031+ {
1032+ <Box < dyn Fn < Args , Output = Output > + Send + ' static > >:: deserialize ( deserializer)
1033+ . map ( |x| x. 0 )
1034+ }
1035+ }
1036+ }
0 commit comments