use std::collections::TryReserveError;
use std::fmt::Debug;
use std::fmt::Display;
use std::string::FromUtf8Error;
use thiserror::Error;
use crate::resource::InsufficientBudgetError;
use crate::resource::QuantityConversionError;
#[derive(Debug, Error)]
pub enum BudgetedStringError<R, E, Q = u64>
where
R: Debug,
E: Debug + Display,
Q: Copy + Debug,
{
#[error(transparent)]
Budget(InsufficientBudgetError<R, Q>),
#[error("string output allocation failed: {0}")]
Allocation(#[source] TryReserveError),
#[error("string byte measurement cannot be represented: {source}")]
Quantity {
resource: R,
#[source]
source: QuantityConversionError,
},
#[error("string renderer failed: {0}")]
Render(E),
#[error("rendered bytes are not valid UTF-8")]
InvalidUtf8(#[source] FromUtf8Error),
#[error("rendered string length overflowed usize")]
LengthOverflow,
}