Module bigint
Expand description
BigInt, the schema’s 64-bit signed integer scalar (ADR 0019).
It is a Copy newtype over i64, not an arbitrary-precision integer;
the name is the schema type’s (totalE8 BigInt) and is namespaced as
cratestack::BigInt, so it does not collide with num_bigint::BigInt
unless one file imports both.
§Wire form
On every codec the value is a canonical decimal string: 0, or an
optional -, a non-zero digit and at most 18 more digits, inside i64
(JSON Schema pattern ^(0|-?[1-9][0-9]{0,18})$). In JSON that is a JSON
string; in CBOR it is a text string (major type 3), never an integer or a
bignum tag. One form on every codec means a value that crosses
serde_json::Value (the /rpc/batch frames) and then CBOR keeps the same
bytes, and no JavaScript number ever holds it.
Serialize writes that string. Deserialize
accepts nothing else: a JSON number, a CBOR integer, a CBOR tag 2 or 3,
+5, 007, -0, " 1" and anything outside i64 are all refused,
because a number above 2^53 may already have been rounded by the
JavaScript that produced it and the server cannot tell.
§Arithmetic
Checked methods only (BigInt::checked_add, BigInt::checked_sub,
BigInt::checked_mul). There are no operator impls, because an operator
on a 64-bit money value must panic, wrap or invent an error path, and no
Deref, because with one a call site nobody updated would keep compiling
against i64 methods. A missed call site is a compile error.
§Database support
The sqlx-postgres and rusqlite Cargo features add the driver trait
impls (Type, Encode, Decode, PgHasArrayType; ToSql, FromSql) so
a BigInt primary or foreign key can be bound and read directly. Each
delegates to i64 (INT8 / SQLite integer). Neither is on by default and
cratestack-core takes no non-optional dependency on either driver; the
backend runtimes enable the one they need.
Structs§
- BigInt
- A signed 64-bit integer that travels as a canonical decimal string on every codec. See the module documentation for the wire form.
- Parse
BigInt Error - Why a string is not a canonical
BigInt.