@@ -221,7 +221,8 @@ impl DecodeBudgetTracker {
221221}
222222
223223/// Active nested decode-budget scope.
224- #[ derive( Debug , Eq , PartialEq ) ]
224+ #[ must_use = "the nesting guard must be held for the entire nested decode" ]
225+ #[ derive( Debug ) ]
225226pub struct NestedBudget < ' a > {
226227 tracker : & ' a mut DecodeBudgetTracker ,
227228}
@@ -288,8 +289,6 @@ fn error_for(field: BudgetField, max: usize, actual: usize) -> DecodeBudgetError
288289pub enum DecodeBudgetErrorCategory {
289290 /// The operation exceeded an explicit resource limit.
290291 ResourceExhaustion ,
291- /// The tracker was used in an invalid state.
292- InvalidState ,
293292}
294293
295294/// Decode-budget accounting failure.
@@ -338,16 +337,13 @@ pub enum DecodeBudgetError {
338337 /// Actual attempted total.
339338 actual : usize ,
340339 } ,
341- /// A caller attempted to leave nesting depth zero.
342- NestingUnderflow ,
343340}
344341
345342impl DecodeBudgetError {
346343 /// Returns the stable high-level error category.
347344 #[ must_use]
348345 pub const fn category ( self ) -> DecodeBudgetErrorCategory {
349346 match self {
350- Self :: NestingUnderflow => DecodeBudgetErrorCategory :: InvalidState ,
351347 Self :: InputTooLarge { .. }
352348 | Self :: NestingTooDeep { .. }
353349 | Self :: TooManyItems { .. }
@@ -367,7 +363,6 @@ impl DecodeBudgetError {
367363 Self :: TooManyMapEntries { .. } => "cardano.cbor.budget.too_many_map_entries" ,
368364 Self :: AllocationTooLarge { .. } => "cardano.cbor.budget.allocation_too_large" ,
369365 Self :: TooManyValues { .. } => "cardano.cbor.budget.too_many_values" ,
370- Self :: NestingUnderflow => "cardano.cbor.budget.nesting_underflow" ,
371366 }
372367 }
373368
@@ -381,7 +376,6 @@ impl DecodeBudgetError {
381376 Self :: TooManyMapEntries { .. } => "Cardano CBOR map-entry count exceeds decode budget" ,
382377 Self :: AllocationTooLarge { .. } => "Cardano CBOR allocation bytes exceed decode budget" ,
383378 Self :: TooManyValues { .. } => "Cardano CBOR value count exceeds decode budget" ,
384- Self :: NestingUnderflow => "Cardano CBOR nesting tracker underflow" ,
385379 }
386380 }
387381}
@@ -398,7 +392,6 @@ impl fmt::Display for DecodeBudgetError {
398392 | Self :: TooManyValues { max, actual } => {
399393 write ! ( f, " (max={max}, actual={actual})" )
400394 }
401- Self :: NestingUnderflow => Ok ( ( ) ) ,
402395 }
403396 }
404397}
0 commit comments