11use std:: cell:: Cell ;
2- use std:: mem:: ManuallyDrop ;
32
43use serde:: ser;
54
@@ -39,30 +38,6 @@ impl AnnotatedSerializer {
3938 }
4039 }
4140
42- /// Try to convert a generic `Serializer` into `Self`.
43- pub fn try_specialize < S : serde:: Serializer > (
44- serializer : S ,
45- ok : impl FnOnce ( & mut AnnotatedSerializer ) -> Result < Document , Error > ,
46- err : impl FnOnce ( S ) -> Result < S :: Ok , S :: Error > ,
47- ) -> Result < S :: Ok , S :: Error > {
48- if typeid:: of :: < S > ( ) == typeid:: of :: < & mut AnnotatedSerializer > ( ) {
49- // SAFETY: If `serializer` is the correct type, then we can transmute the
50- // reference into `&mut AnnotatedSerializer`.
51- //
52- // For the lifetime, we observe that the lifetime on `ok` works for any lifetime.
53- // So the exact lifetime would not matter for the soundness.
54- let serializer: & mut AnnotatedSerializer =
55- unsafe { std:: mem:: transmute_copy ( & ManuallyDrop :: new ( serializer) ) } ;
56-
57- let r = ok ( serializer) ;
58-
59- // SAFETY: Similarly, we can transmute the return value.
60- unsafe { std:: mem:: transmute_copy ( & ManuallyDrop :: new ( r) ) }
61- } else {
62- err ( serializer)
63- }
64- }
65-
6641 /// Provide an annotator to inform how to annotate the serialization of the current object.
6742 pub fn with < T > ( value : Option < & dyn Annotate > , f : impl FnOnce ( Option < & dyn Annotate > ) -> T ) -> T {
6843 ANNOTATE . with ( |annotate| {
@@ -77,19 +52,6 @@ impl AnnotatedSerializer {
7752 } )
7853 }
7954
80- /// Convert a generic `Serializer` into `Self`, panic on failure.
81- pub fn specialize < S : serde:: Serializer > (
82- serializer : S ,
83- f : impl FnOnce ( & mut AnnotatedSerializer ) -> Result < Document , Error > ,
84- ) -> Result < S :: Ok , S :: Error > {
85- Self :: try_specialize ( serializer, f, |_| {
86- panic ! (
87- "Expected to be called by AnnotatedSerializer, not {:?}" ,
88- std:: any:: type_name:: <S >( ) ,
89- ) ;
90- } )
91- }
92-
9355 fn with_base ( & self , b : Base ) -> Self {
9456 let mut x = self . clone ( ) ;
9557 x. base = b;
0 commit comments