use core::fmt;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum SourceMapError {
SpaceExhausted {
needed: u64,
available: u64,
},
}
impl fmt::Display for SourceMapError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Self::SpaceExhausted { needed, available } => write!(
f,
"source of {needed} bytes does not fit in the {available} bytes \
remaining in the global position space",
),
}
}
}
impl core::error::Error for SourceMapError {}
#[cfg(test)]
mod tests {
extern crate alloc;
use alloc::string::ToString;
use super::*;
#[test]
fn test_space_exhausted_display_names_both_figures() {
let err = SourceMapError::SpaceExhausted {
needed: 10,
available: 4,
};
let text = err.to_string();
assert!(text.contains("10 bytes"), "{text}");
assert!(text.contains("4 bytes"), "{text}");
}
#[test]
fn test_error_is_copy_and_equatable() {
let a = SourceMapError::SpaceExhausted {
needed: 1,
available: 0,
};
let b = a;
assert_eq!(a, b);
}
}