pub struct ReflectSerializer<'a, P = ()> { /* private fields */ }
Expand description
A general purpose serializer for reflected types.
This is the serializer counterpart to ReflectDeserializer
.
See TypedReflectSerializer
for a serializer that serializes a known type.
§Output
This serializer will output a map with a single entry, where the key is the full type path of the reflected type and the value is the serialized data.
If you want to override serialization for specific values, you can pass in
a reference to a ReflectSerializerProcessor
which will take priority
over all other serialization methods - see with_processor
.
§Example
#[derive(Reflect, PartialEq, Debug)]
#[type_path = "my_crate"]
struct MyStruct {
value: i32
}
let mut registry = TypeRegistry::default();
registry.register::<MyStruct>();
let input = MyStruct { value: 123 };
let reflect_serializer = ReflectSerializer::new(&input, ®istry);
let output = ron::to_string(&reflect_serializer).unwrap();
assert_eq!(output, r#"{"my_crate::MyStruct":(value:123)}"#);
Implementations§
source§impl<'a> ReflectSerializer<'a, ()>
impl<'a> ReflectSerializer<'a, ()>
sourcepub fn new(value: &'a dyn PartialReflect, registry: &'a TypeRegistry) -> Self
pub fn new(value: &'a dyn PartialReflect, registry: &'a TypeRegistry) -> Self
Creates a serializer with no processor.
If you want to add custom logic for serializing certain values, use
with_processor
.
source§impl<'a, P: ReflectSerializerProcessor> ReflectSerializer<'a, P>
impl<'a, P: ReflectSerializerProcessor> ReflectSerializer<'a, P>
sourcepub fn with_processor(
value: &'a dyn PartialReflect,
registry: &'a TypeRegistry,
processor: &'a P,
) -> Self
pub fn with_processor( value: &'a dyn PartialReflect, registry: &'a TypeRegistry, processor: &'a P, ) -> Self
Creates a serializer with a processor.
If you do not need any custom logic for handling certain values, use
new
.
Trait Implementations§
source§impl<P: ReflectSerializerProcessor> Serialize for ReflectSerializer<'_, P>
impl<P: ReflectSerializerProcessor> Serialize for ReflectSerializer<'_, P>
Auto Trait Implementations§
impl<'a, P> Freeze for ReflectSerializer<'a, P>
impl<'a, P = ()> !RefUnwindSafe for ReflectSerializer<'a, P>
impl<'a, P> Send for ReflectSerializer<'a, P>where
P: Sync,
impl<'a, P> Sync for ReflectSerializer<'a, P>where
P: Sync,
impl<'a, P> Unpin for ReflectSerializer<'a, P>
impl<'a, P = ()> !UnwindSafe for ReflectSerializer<'a, P>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.