/development/std/json/index.nct
index.nct
//! Owning JSON values, exact number tokens, and strict whole-text parsing.
use /io.Writer
use /map.Map
use /mem.TryAllocator
use /string.String
use /vec.Vec
see ./cursor.nct
see ./escaping.nct
see ./errors.nct
see ./failure.nct
see ./generation.nct
see ./generation_failure.nct
see ./number.nct
see ./parsing.nct
see ./string_decoding.nct
/// One exact, validated JSON number token.
pub struct Number
construct Number {
/// Validates and copies exactly one JSON number token.
pub func parse(text: &str): Self!
/// Validates and copies exactly one JSON number token with recoverable allocation.
pub func try_parse(allocator: &+TryAllocator, text: &str): Self! from allocator
}
instance Number {
/// Returns the exact validated token spelling retained by this value.
pub method &self.text(): &str
/// Returns the mathematical value when it is exactly representable as i64.
pub method &self.as_i64(): i64?
/// Returns the mathematical value when it is exactly representable as u64.
pub method &self.as_u64(): u64?
}
/// One owning JSON value.
pub enum Value {
null
boolean(value: bool)
number(value: Number)
string(value: String)
array(value: Vec<Value>)
object(value: Map<String, Value>)
}
/// Parses one complete JSON text using the current allocation context.
pub func parse(text: &str): Value!
/// Parses one complete JSON text with recoverable allocation.
pub func try_parse(allocator: &+TryAllocator, text: &str): Value! from allocator
/// Generates one compact JSON text using the current allocation context.
pub func stringify(value: &Value): String
/// Generates one compact JSON text with recoverable allocation.
pub func try_stringify(
allocator: &+TryAllocator,
value: &Value,
): String! from allocator
/// Writes one compact JSON text without constructing a complete intermediate String.
pub func write<W>(destination: &+W, value: &Value): void! where W impl Writer
/// Writes one compact JSON text with recoverable traversal-stack allocation.
pub func try_write<W>(
allocator: &+TryAllocator,
destination: &+W,
value: &Value,
): void! where W impl Writer