pub struct BudgetConfig {
pub default_run_max_cost_usd: Option<Decimal>,
pub monthly_cost_limit_usd: Option<Decimal>,
}Expand description
Server-level cost guardrails.
Both fields default to None, which disables the corresponding check and
preserves the pre-existing behaviour exactly.
§Examples
use ironflow_engine::budget::BudgetConfig;
let config = BudgetConfig::new();
assert!(config.default_run_max_cost_usd.is_none());
assert!(config.monthly_cost_limit_usd.is_none());Fields§
§default_run_max_cost_usd: Option<Decimal>Default cost cap applied to a run when neither the creation request nor
the handler declares one. None means no default cap.
monthly_cost_limit_usd: Option<Decimal>Global quota for the current calendar month (UTC). None disables the
monthly check.
Implementations§
Source§impl BudgetConfig
impl BudgetConfig
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a configuration with both guardrails disabled.
§Examples
use ironflow_engine::budget::BudgetConfig;
assert_eq!(BudgetConfig::new(), BudgetConfig::default());Sourcepub fn default_run_max_cost_usd(self, cap: Decimal) -> Self
pub fn default_run_max_cost_usd(self, cap: Decimal) -> Self
Set the server-wide default per-run cost cap.
§Examples
use ironflow_engine::budget::BudgetConfig;
use rust_decimal::Decimal;
let config = BudgetConfig::new().default_run_max_cost_usd(Decimal::new(150, 2));
assert_eq!(config.default_run_max_cost_usd, Some(Decimal::new(150, 2)));Sourcepub fn monthly_cost_limit_usd(self, limit: Decimal) -> Self
pub fn monthly_cost_limit_usd(self, limit: Decimal) -> Self
Set the global monthly cost quota.
§Examples
use ironflow_engine::budget::BudgetConfig;
use rust_decimal::Decimal;
let config = BudgetConfig::new().monthly_cost_limit_usd(Decimal::new(10000, 2));
assert_eq!(config.monthly_cost_limit_usd, Some(Decimal::new(10000, 2)));Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
Load the configuration from the environment.
Reads DEFAULT_RUN_MAX_COST_ENV and MONTHLY_COST_LIMIT_ENV. A
variable that is unset, empty, unparseable, or negative is ignored (the
corresponding guardrail stays disabled) and logged at WARN. Loading
never fails, so a malformed value can never prevent the server from
starting.
§Examples
use ironflow_engine::budget::BudgetConfig;
let config = BudgetConfig::from_env();Sourcepub fn resolve_run_cap(
&self,
requested: Option<Decimal>,
handler_default: Option<Decimal>,
) -> Option<Decimal>
pub fn resolve_run_cap( &self, requested: Option<Decimal>, handler_default: Option<Decimal>, ) -> Option<Decimal>
Resolve the cost cap of a run being created.
Priority, strongest first: the value supplied at creation time, then the
handler default, then the server default. None at every level means
the run has no cap.
§Examples
use ironflow_engine::budget::BudgetConfig;
use rust_decimal::Decimal;
let server = Decimal::new(100, 2);
let handler = Decimal::new(200, 2);
let requested = Decimal::new(300, 2);
let config = BudgetConfig::new().default_run_max_cost_usd(server);
assert_eq!(config.resolve_run_cap(Some(requested), Some(handler)), Some(requested));
assert_eq!(config.resolve_run_cap(None, Some(handler)), Some(handler));
assert_eq!(config.resolve_run_cap(None, None), Some(server));Trait Implementations§
Source§impl Clone for BudgetConfig
impl Clone for BudgetConfig
Source§fn clone(&self) -> BudgetConfig
fn clone(&self) -> BudgetConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BudgetConfig
impl Debug for BudgetConfig
Source§impl Default for BudgetConfig
impl Default for BudgetConfig
Source§fn default() -> BudgetConfig
fn default() -> BudgetConfig
impl Eq for BudgetConfig
Source§impl PartialEq for BudgetConfig
impl PartialEq for BudgetConfig
impl StructuralPartialEq for BudgetConfig
Auto Trait Implementations§
impl Freeze for BudgetConfig
impl RefUnwindSafe for BudgetConfig
impl Send for BudgetConfig
impl Sync for BudgetConfig
impl Unpin for BudgetConfig
impl UnsafeUnpin for BudgetConfig
impl UnwindSafe for BudgetConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.