Skip to main content

ObjectRef

Struct ObjectRef 

Source
pub struct ObjectRef<'a> { /* private fields */ }
Expand description

A borrowed Python value, for inspecting results, arguments and inputs without copying.

Implementations§

Source§

impl<'a> ObjectRef<'a>

Source

pub fn type_name(&self) -> &'a str

The Python type name of the value, e.g. "list".

Source

pub fn to_owned(&self) -> MontyObject

Copies into an owned value, preserving sharing within the value.

Source

pub fn items(&self) -> Option<Vec<Self>>

The items of a list, tuple, set, frozenset or namedtuple; None for any other value.

Source

pub fn pairs(&self) -> Option<Vec<(Self, Self)>>

The (key, value) pairs of a dict, or the attrs of a class instance, class type object or module; None for any other value.

Source

pub fn as_int(&self) -> Option<i64>

The value as an int, if it fits in 64 bits.

Source

pub fn as_str(&self) -> Option<&'a str>

The value as a str.

Source

pub fn as_bool(&self) -> Option<bool>

The value as a bool.

Source

pub fn as_float(&self) -> Option<f64>

The value as a float; an int converts as Python’s float() does, with one too large for a float giving None where Python overflows.

Source

pub fn as_decimal(&self) -> Option<&str>

The string form of a decimal.Decimal, as str(d) prints it.

Source

pub fn as_complex(&self) -> Option<MontyComplex>

The value as a complex; an int or float converts as Python’s complex() does, with a zero imaginary part (see as_float for an int too large to convert).

Source

pub fn py_repr(&self) -> String

The Python repr() of the value.

§Panics

Could panic if out of memory.

Source

pub fn is_truthy(&self) -> bool

Whether the value is truthy under Python’s rules: None, False, zero and empty containers are falsy; everything else is truthy.

Trait Implementations§

Source§

impl<'a> Clone for ObjectRef<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for ObjectRef<'a>

Source§

impl<'a> Debug for ObjectRef<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ObjectRef<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

The Python str() of the value: text as is, everything else its repr().

Source§

impl PartialEq for ObjectRef<'_>

Source§

fn eq(&self, other: &Self) -> bool

Structural equality as Python values: an int equals the same BigInt, a namedtuple equals a tuple of its values, floats compare bit-for-bit (so NaN round-trips equal), and a sub-object shared in one arena equals its copies in another. Linear in the arenas: each pair of nodes is compared once.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<MontyObject> for ObjectRef<'_>

Source§

fn eq(&self, other: &MontyObject) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<ObjectRef<'_>> for MontyObject

Source§

fn eq(&self, other: &ObjectRef<'_>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PushValue for ObjectRef<'_>

Source§

fn push_into(self, graph: &mut MontyGraph) -> NodeId

Copies the reachable nodes; a sub-object shared inside the value stays shared. Linear sweeps over the value’s index span, no recursion, so a deep value from an untrusted worker costs heap rather than native stack.

Source§

impl TryFrom<ObjectRef<'_>> for i64

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(value: ObjectRef<'_>) -> Result<Self, ConversionError>

Performs the conversion.
Source§

impl TryFrom<ObjectRef<'_>> for f64

An int converts as Python’s float() does.

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(value: ObjectRef<'_>) -> Result<Self, ConversionError>

Performs the conversion.
Source§

impl TryFrom<ObjectRef<'_>> for String

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(value: ObjectRef<'_>) -> Result<Self, ConversionError>

Performs the conversion.
Source§

impl TryFrom<ObjectRef<'_>> for bool

Only True/False convert; this is not Python truthiness (see ObjectRef::is_truthy).

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(value: ObjectRef<'_>) -> Result<Self, ConversionError>

Performs the conversion.

Auto Trait Implementations§

§

impl<'a> Freeze for ObjectRef<'a>

§

impl<'a> RefUnwindSafe for ObjectRef<'a>

§

impl<'a> Send for ObjectRef<'a>

§

impl<'a> Sync for ObjectRef<'a>

§

impl<'a> Unpin for ObjectRef<'a>

§

impl<'a> UnsafeUnpin for ObjectRef<'a>

§

impl<'a> UnwindSafe for ObjectRef<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.