Skip to main content

qubit_budget/
lib.rs

1// =============================================================================
2//    Copyright (c) 2025 - 2026 Haixing Hu.
3//
4//    SPDX-License-Identifier: Apache-2.0
5//
6//    Licensed under the Apache License, Version 2.0.
7// =============================================================================
8#![cfg_attr(docsrs, feature(doc_cfg))]
9//! Dependency-light finite resource limits, budgets and pools.
10//!
11//! A budget object always represents a configured finite constraint. When a
12//! dimension is unconfigured, callers use `Option::None` and do not create a
13//! no-op or unlimited budget object. Resource quantities use an exact unsigned
14//! integer type. High-level limits remain generic so callers can preserve their
15//! native measurements; conversions from machine-sized measurements are checked
16//! and reported as resource-accounting errors.
17//!
18//! A failed single-budget operation is non-mutating, and
19//! [`ResourceBudget::try_consume_group`] checks every member before charging
20//! any member. Higher-level sessions may deliberately retain charges for work
21//! already attempted. Generic [`StructureBudget`] measurements are consumed
22//! immediately, while JSON value measurements are staged and commit only after
23//! the complete value succeeds. JSON raw and normalized input bytes, plus
24//! accepted output prefixes, are charged immediately. These are separate
25//! guarantees; an I/O failure does not itself poison a JSON value transaction,
26//! and output transactionality does not imply whole-operation rollback.
27
28mod resource;
29pub mod string;
30pub mod structure;
31pub mod time;
32mod value;
33
34#[cfg(feature = "json")]
35#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
36pub mod json;
37pub use resource::BudgetError;
38pub use resource::BudgetGroupError;
39pub use resource::InsufficientBudgetError;
40pub use resource::LimitExceededError;
41pub use resource::ManagedResourcePermit;
42pub use resource::ManagedResourcePool;
43pub use resource::MeasuredBudgetError;
44pub use resource::Observation;
45pub use resource::QuantityConversionError;
46pub use resource::QuantityMeasurement;
47pub use resource::ResourceBudget;
48pub use resource::ResourceLimit;
49pub use resource::ResourcePool;
50pub use resource::ResourceQuantity;
51pub use resource::ResourceReleaseError;
52pub use string::BudgetedStringError;
53pub use string::BudgetedStringWriter;
54pub use structure::StructureBudget;
55pub use structure::StructureLimits;
56pub use structure::StructureLimitsBuilder;
57pub use structure::StructureResource;
58pub use time::DurationBudget;
59#[cfg(feature = "time")]
60#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
61pub use time::TimeBudget;
62#[cfg(feature = "time")]
63#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
64pub use time::TimeBudgetError;
65#[cfg(feature = "big-decimal")]
66#[cfg_attr(docsrs, doc(cfg(feature = "big-decimal")))]
67pub use value::BigDecimalLimits;
68#[cfg(feature = "big-decimal")]
69#[cfg_attr(docsrs, doc(cfg(feature = "big-decimal")))]
70pub use value::BigDecimalLimitsBuilder;
71#[cfg(feature = "big-integer")]
72#[cfg_attr(docsrs, doc(cfg(feature = "big-integer")))]
73pub use value::BigIntegerLimits;
74#[cfg(feature = "big-integer")]
75#[cfg_attr(docsrs, doc(cfg(feature = "big-integer")))]
76pub use value::BigIntegerLimitsBuilder;
77pub use value::StringLimits;
78pub use value::StringLimitsBuilder;