pub enum Object {
}Expand description
A Python value.
Variants§
None
None.
NotImplemented
The answer an operator gives when it does not know how, which is what lets Python try the reflected one before giving up.
Ellipsis
..., which is a value as well as a piece of syntax.
Bool(bool)
True or False, which is an int in Python and is kept apart here
because repr and type both need to know which one it is.
Int(Int)
An int, of any size.
Float(f64)
A float, which is an IEEE double and nothing more.
Str(Rc<Str>)
A str, which is a sequence of code points.
Bytes(Rc<[u8]>)
A bytes, which is a sequence of bytes and never equal to a str.
Tuple(Rc<[Object]>)
A tuple, which cannot change and so holds its elements inline.
List(Rc<RefCell<Vec<Object>>>)
A list, which can.
Dict(Rc<RefCell<Dict>>)
A dict, which remembers the order things were put into it.
Set(Rc<RefCell<Set>>)
A set, which does not.
Slice(Rc<Slice>)
A slice, which is what a:b:c inside a subscript builds. It holds
three objects rather than three integers, because the numbers only have
to be numbers at the point a sequence uses them.
Native(Rc<dyn Native>)
A value whose type is defined above this crate, which is how the runtime
gets functions, iterators and exceptions without this crate having to
know what any of those are. See Native.
Implementations§
Source§impl Object
impl Object
Sourcepub fn native(value: impl Native + 'static) -> Self
pub fn native(value: impl Native + 'static) -> Self
A value of a type defined above this crate.
Sourcepub fn downcast<T: Native + 'static>(&self) -> Option<&T>
pub fn downcast<T: Native + 'static>(&self) -> Option<&T>
The native value inside this object, if that is what it is and if it is the type asked for.
This is the downcast the runtime uses to find out whether the thing in a register is the kind of object it can call or step.
Sourcepub fn exception(&self) -> Option<&Exception>
pub fn exception(&self) -> Option<&Exception>
This value as the exception it is, or None if it is not one.
The one downcast common enough to be worth a name, since raise,
except and the traceback printer all ask the same question.
Sourcepub fn type_name(&self) -> &str
pub fn type_name(&self) -> &str
What type(x).__name__ says, which is what every error message needs.
Borrowed rather than &'static str, because a class defined in Python
names itself and that name is owned by the class object. Everything
built in still hands back a literal.
Sourcepub fn truthy(&self) -> bool
pub fn truthy(&self) -> bool
Python’s truth protocol for the types that have no __bool__ to run.
Zero of any numeric type is false, an empty container is false, None
is false, and everything else is true. When user-defined types arrive
this becomes the thing that calls __bool__ and then __len__, and the
answers below become what the builtin types answer with.
Sourcepub fn is(&self, other: &Self) -> bool
pub fn is(&self, other: &Self) -> bool
Whether these are the same object, which is what is asks.
For a heap value it is the pointer. For an immediate it is the value,
which is the one place this differs from CPython in a way a program
could see: x = 1000; y = 1000; x is y is False in CPython because
there are two objects, and is True here because there are none. The
tagged representation makes that true for real, and the language does
not promise either answer.
The loudest case of it is the NaN, since identity is what decides
nan in [nan] and whether a NaN can be found in a dict again. Two
separately made ones are two objects in CPython and one value here.
Sourcepub fn equals(&self, other: &Self) -> bool
pub fn equals(&self, other: &Self) -> bool
What == answers.
Numbers compare across their types, so 1 == 1.0 == True, and an
integer too large for a float still gets an exact answer. Everything
else compares only within its own type: a str is never equal to the
bytes that spell it and a tuple is never equal to a list, however
alike either pair looks.
A container holding itself sends this into a recursion CPython turns
into a RecursionError. There is no recursion limit here yet, because
there are no frames to count, and it arrives with them.
Sourcepub fn same_value(&self, other: &Self) -> bool
pub fn same_value(&self, other: &Self) -> bool
What a container asks about its elements, and what a dict asks about a
key, which is x is y or x == y rather than plain ==.
The identity half is not an optimization. x == x is false for a NaN,
so [nan] == [nan] would be false without it where CPython says true
for the same NaN in both, and a NaN stored in a dict could never be
found again.