1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//! Values this crate does not know the shape of.
//!
//! A Python program needs objects that are not data: the function `print` is
//! bound to, the iterator a `for` loop walks, the exception a `raise` throws.
//! None of them can be built here. There are no classes yet, so there is no way
//! to define a type from inside Python, and the ones the runtime needs depend
//! on the runtime rather than on the object model. `print` has to know where the
//! output goes and an iterator has to know how the interpreter steps it.
//!
//! Growing an [`Object`](crate::Object) variant for each of them would put every
//! one of those decisions in this crate, which is the wrong place for them and
//! is the sort of thing that is easy to add and hard to take back out. So the
//! layer above defines the type, implements [`Native`], and this crate asks it
//! the same handful of questions it asks any other value.
//!
//! Getting the concrete type back out is [`Native::as_any`] and a downcast.
//! That is the cost of the arrangement and it is paid only by the runtime, at
//! the two or three places that have to know whether the thing in a register is
//! the kind of object they can call or step.
//!
//! ## Identity, equality and hashing
//!
//! All three are the address, and none of them can be overridden. A function is
//! equal to itself and to nothing else, and that is what CPython says for one
//! too. When classes arrive and `__eq__` becomes user code the question moves
//! to the class rather than to this trait, so there is no point in an
//! overridable answer here that would have to be taken away again.
use Any;
use fmt;
/// A value whose type lives above this crate.
///
/// Implementors are runtime objects: builtin functions, iterators, exception
/// instances. They answer the questions any value has to answer and keep the
/// rest to themselves.