pub struct Object<T> {
pub class: Option<String>,
pub value: T,
}Expand description
A value with the class of a PHP object.
When deserialized the class of the value (if there is one) is captured, when serialized the value is written as an object of the class:
use std::collections::BTreeMap;
use deser_php::Object;
let input = br#"O:4:"User":1:{s:4:"name";s:4:"Jane";}"#;
let user: Object<BTreeMap<String, String>> = deser_php::from_slice(input).unwrap();
assert_eq!(user.class.as_deref(), Some("User"));
assert_eq!(user.value["name"], "Jane");
assert_eq!(deser_php::to_vec(&user).unwrap(), input);Maps are written as objects, strings as enum cases (E:) and bytes as
custom serialized objects (C:). Other formats do not have classes.
When deserializing from such formats, the class is None, when
serializing it’s ignored.
Fields§
§class: Option<String>The class of the value.
value: TThe value.
Implementations§
Trait Implementations§
Source§impl<'de, T: Deserialize<'de>> Deserialize<'de> for Object<T>
impl<'de, T: Deserialize<'de>> Deserialize<'de> for Object<T>
Source§fn deserialize_into<'out>(
out: &'out mut Option<Self>,
state: &mut State,
) -> SinkHandle<'out, 'de>
fn deserialize_into<'out>( out: &'out mut Option<Self>, state: &mut State, ) -> SinkHandle<'out, 'de>
Creates a sink that deserializes the value into the given slot. Read more
Source§fn expecting() -> Cow<'static, str>
fn expecting() -> Cow<'static, str>
Returns what the value expects, for error messages. Read more
Source§fn describe_type(d: &mut dyn Describe)
fn describe_type(d: &mut dyn Describe)
Describes the Rust shape of the type. Read more
Source§fn deserialize_atom(
slot: &mut Slot<T, Self>,
atom: Atom<'_>,
state: &mut State,
) -> Result<(), Error>
fn deserialize_atom( slot: &mut Slot<T, Self>, atom: Atom<'_>, state: &mut State, ) -> Result<(), Error>
Deserializes an atom into the slot. Read more
Source§fn deserialize_borrowed_atom(
slot: &mut Slot<T, Self>,
atom: Atom<'de>,
state: &mut State,
) -> Result<(), Error>
fn deserialize_borrowed_atom( slot: &mut Slot<T, Self>, atom: Atom<'de>, state: &mut State, ) -> Result<(), Error>
Deserializes an atom that borrows from the data being deserialized
into the slot. Read more
Source§fn initial_value() -> Option<T>
fn initial_value() -> Option<T>
Provides the value of a missing struct field. Read more
Source§fn deserialize_update<'out>(
value: &'out mut T,
state: &mut State,
) -> SinkHandle<'out, 'de>
fn deserialize_update<'out>( value: &'out mut T, state: &mut State, ) -> SinkHandle<'out, 'de>
Creates a sink that updates an existing value. Read more
impl<T: Eq> Eq for Object<T>
Source§impl<T: Ord> Ord for Object<T>
impl<T: Ord> Ord for Object<T>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl<T: PartialOrd> PartialOrd for Object<T>
impl<T: PartialOrd> PartialOrd for Object<T>
Source§impl<T: Serialize> Serialize for Object<T>
impl<T: Serialize> Serialize for Object<T>
Source§fn serialize<'a>(this: &'a Self, state: &mut State) -> Result<Emit<'a>, Error>
fn serialize<'a>(this: &'a Self, state: &mut State) -> Result<Emit<'a>, Error>
Serializes the value.
Source§fn finish(this: &Self, state: &mut State) -> Result<(), Error>
fn finish(this: &Self, state: &mut State) -> Result<(), Error>
Invoked after the serialization finished. Read more
Source§fn is_optional(this: &Self) -> bool
fn is_optional(this: &Self) -> bool
Checks if the value represents an optional value. Read more
Source§fn container_shape(this: &Self) -> ContainerShape
fn container_shape(this: &Self) -> ContainerShape
Returns the shape of the value if it’s a map or sequence. Read more
impl<T: PartialEq> StructuralPartialEq for Object<T>
Auto Trait Implementations§
impl<T> Freeze for Object<T>where
T: Freeze,
impl<T> RefUnwindSafe for Object<T>where
T: RefUnwindSafe,
impl<T> Send for Object<T>where
T: Send,
impl<T> Sync for Object<T>where
T: Sync,
impl<T> Unpin for Object<T>where
T: Unpin,
impl<T> UnsafeUnpin for Object<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Object<T>where
T: UnwindSafe,
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