Skip to main content

Module json

Module json 

Source
Expand description

The bundled JSON contract front-end: loading, lookup, and conversion.

Three embedded JSON assets provide out-of-the-box contracts: std function requires contracts (std-api-requires.json), std type invariants (std-type-invariants.json), and std auto-trait ensures obligations (std-trait-ensures.json). Lookup uses exact, path-stripped, and wildcard fallback so trait-method impls and re-exported paths resolve correctly. Entries are then converted into Property values via entry_to_property.

StructsΒ§

JsonProperty πŸ”’
Structure of JSON entries.
TypeInvariantEntry πŸ”’
Serialisation-friendly struct for the type-invariants JSON.

EnumsΒ§

AnyItem πŸ”’
One disjunct inside a JSON any entry.

FunctionsΒ§

any_entry_to_property πŸ”’
Parse an any disjunction entry from JSON into a Property::Or property.
entry_to_property πŸ”’
Convert a single JsonProperty from JSON into the properties it denotes.
get_std_contracts_from_json πŸ”’
Looks up backup contracts for a standard-library function by its normalized path. For trait-method impls, resolves to the trait method’s path first so that all impls share the same contracts.
get_std_type_invariants πŸ”’
Returns the std-type-invariants database, mapping a type path key (e.g. "core::num::nonzero::NonZero") to its invariant entries.
is_contract_token_char πŸ”’
load_std_contracts_json πŸ”’
Lazily loads the backup contract database for standard-library APIs.
load_trait_ensures_json πŸ”’
Lazily loads the std auto-trait ensures obligation database.
normalize_json_contract_arg πŸ”’
Convert explicit JSON contract tokens into the expression syntax accepted by the existing property parser.
query_json_contracts πŸ”’
Query contracts for a function from the bundled JSON backup database.
query_trait_ensures πŸ”’
Returns the ensures obligation template for a marker trait such as Send/Sync, keyed by the trait’s def path (e.g. "core::marker::Send").
resolve_entry_group πŸ”’
Resolve a single JSON any entry into its property group (empty on error).
resolve_json_args πŸ”’
Resolve JSON contract argument strings to parsed syn::Expr values.
resolve_json_param_name πŸ”’
Resolve a simple parameter-name reference in a JSON contract arg string to the arg:N positional form. Complex expressions (containing function calls, field access, etc.) are left unchanged β€” they are handled later by the expression parser which already knows how to resolve named parameters.
resolve_trait_method πŸ”’
If def_id is a trait-method implementation, returns the corresponding trait method’s [DefId]; otherwise returns def_id unchanged.
scan_while πŸ”’
std_contracts_has_entry πŸ”’
Whether the JSON contract database has an entry for def_id β€” including an empty one, which means β€œno safety contract is needed” (e.g. fmt::new, whose arguments are all references).