pub struct TypedReflectSerializer<'a, P = ()> { /* private fields */ }
Expand description
A serializer for reflected types whose type will be known during deserialization.
This is the serializer counterpart to TypedReflectDeserializer
.
See ReflectSerializer
for a serializer that serializes an unknown type.
§Output
Since the type is expected to be known during deserialization, this serializer will not output any additional type information, such as the type path.
Instead, it will output just 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 = TypedReflectSerializer::new(&input, ®istry);
let output = ron::to_string(&reflect_serializer).unwrap();
assert_eq!(output, r#"(value:123)"#);
Implementations§
Source§impl<'a> TypedReflectSerializer<'a, ()>
impl<'a> TypedReflectSerializer<'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> TypedReflectSerializer<'a, P>
impl<'a, P> TypedReflectSerializer<'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 TypedReflectSerializer<'_, P>
impl<P: ReflectSerializerProcessor> Serialize for TypedReflectSerializer<'_, P>
Auto Trait Implementations§
impl<'a, P> Freeze for TypedReflectSerializer<'a, P>
impl<'a, P = ()> !RefUnwindSafe for TypedReflectSerializer<'a, P>
impl<'a, P> Send for TypedReflectSerializer<'a, P>where
P: Sync,
impl<'a, P> Sync for TypedReflectSerializer<'a, P>where
P: Sync,
impl<'a, P> Unpin for TypedReflectSerializer<'a, P>
impl<'a, P = ()> !UnwindSafe for TypedReflectSerializer<'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.