pub struct Serializer { /* private fields */ }Expand description
Serializes values into PHP’s serialization format.
The values are appended to the output one after another (they can be
read back with Deserializer::iter).
use deser_php::Serializer;
let mut serializer = Serializer::new();
serializer.serialize(&true).unwrap();
serializer.serialize(&"hi").unwrap();
assert_eq!(serializer.output(), b"b:1;s:2:\"hi\";");The serializer is also the stream serializer of the format (see
StreamSerializer). Values are written once
they are complete as the lengths of arrays are written in front of
them. To write to a Write use
SerializerConfig::writer.
Implementations§
Source§impl Serializer
impl Serializer
Sourcepub fn new() -> Serializer
pub fn new() -> Serializer
Creates a serializer.
Sourcepub fn with_config(config: SerializerConfig) -> Serializer
pub fn with_config(config: SerializerConfig) -> Serializer
Creates a serializer with the given configuration.
Sourcepub fn config(&self) -> &SerializerConfig
pub fn config(&self) -> &SerializerConfig
Returns the configuration.
Sourcepub fn serialize<T: Serialize + ?Sized>(
&mut self,
value: &T,
) -> Result<(), Error>
pub fn serialize<T: Serialize + ?Sized>( &mut self, value: &T, ) -> Result<(), Error>
Serializes a value and appends it to the output.
Trait Implementations§
Source§impl Clone for Serializer
impl Clone for Serializer
Source§impl Debug for Serializer
impl Debug for Serializer
Source§impl Default for Serializer
impl Default for Serializer
Source§impl Serializer for Serializer
impl Serializer for Serializer
Source§fn drive(&mut self, driver: &mut SerializeDriver<'_>) -> Result<(), Error>
fn drive(&mut self, driver: &mut SerializeDriver<'_>) -> Result<(), Error>
Receives the events of a value from the driver and writes them into
the output.
Source§fn serialize_with<T, F>(&mut self, value: &T, setup: F) -> Result<(), Error>
fn serialize_with<T, F>(&mut self, value: &T, setup: F) -> Result<(), Error>
Serializes a value with a configured driver. Read more
Source§fn serialize_ref(&mut self, value: SerializeRef<'_>) -> Result<(), Error>
fn serialize_ref(&mut self, value: SerializeRef<'_>) -> Result<(), Error>
Serializes the value of a reference. Read more
Source§impl StreamSerializer for Serializer
impl StreamSerializer for Serializer
Source§fn output(&self) -> &[u8] ⓘ
fn output(&self) -> &[u8] ⓘ
Returns the bytes serialized so far which were not cleared yet. Read more
Source§fn clear_output(&mut self)
fn clear_output(&mut self)
Discards the bytes returned by
output, for
instance because they were written.Source§fn supports_partial(&self) -> bool
fn supports_partial(&self) -> bool
Source§fn drive_partial(
&mut self,
driver: &mut SerializeDriver<'_>,
limit: usize,
) -> Result<bool, Error>
fn drive_partial( &mut self, driver: &mut SerializeDriver<'_>, limit: usize, ) -> Result<bool, Error>
Serializes a value, or a part of it, and appends its bytes to the
output. Read more
Source§fn in_progress(&self) -> bool
fn in_progress(&self) -> bool
Returns
true if a value is partially serialized. Read moreAuto Trait Implementations§
impl Freeze for Serializer
impl RefUnwindSafe for Serializer
impl Send for Serializer
impl Sync for Serializer
impl Unpin for Serializer
impl UnsafeUnpin for Serializer
impl UnwindSafe for Serializer
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
Mutably borrows from an owned value. Read more