pub struct Object<T> {
pub class: Option<Global>,
pub form: Option<Form>,
pub value: T,
}Expand description
A value with the class of a Python 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_pickle::{Global, Object};
// a `Point(x=1, y=2)` of a module `geometry`
let input = b"\x80\x04\x95*\x00\x00\x00\x00\x00\x00\x00\x8c\x08geometry\x94\x8c\x05Point\x94\x93\x94)\x81\x94}\x94(\x8c\x01x\x94K\x01\x8c\x01y\x94K\x02ub.";
let point: Object<BTreeMap<String, i32>> = deser_pickle::from_slice(input).unwrap();
assert_eq!(point.class, Some(Global::new("geometry", "Point")));
assert_eq!(point.value["y"], 2);Other formats do not have classes. When deserializing from such
formats, the class is None, when serializing it’s ignored.
Fields§
§class: Option<Global>The class of the value.
form: Option<Form>How the object is created from the value (see Form).
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