use std::fmt;
pub type NetcodeResult<T> = std::result::Result<T, NetcodeError>;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum NetcodeError {
InvalidConfig(&'static str),
InvalidSample(&'static str),
InvalidInput(&'static str),
InputHistoryFull,
SequenceExhausted,
InvalidAcknowledgement,
PredictionHistoryFull,
ReplayLimitExceeded,
InterpolationBufferEmpty,
PredictedEntityLimit,
}
impl fmt::Display for NetcodeError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidConfig(message) => write!(formatter, "invalid netcode config: {message}"),
Self::InvalidSample(message) => write!(formatter, "invalid Tick sample: {message}"),
Self::InvalidInput(message) => write!(formatter, "invalid input: {message}"),
Self::InputHistoryFull => formatter.write_str("unacknowledged input history is full"),
Self::SequenceExhausted => formatter.write_str("input sequence is exhausted"),
Self::InvalidAcknowledgement => {
formatter.write_str("peer acknowledged an input sequence that was never issued")
}
Self::PredictionHistoryFull => {
formatter.write_str("unconfirmed prediction history is full")
}
Self::ReplayLimitExceeded => formatter.write_str("prediction replay limit exceeded"),
Self::InterpolationBufferEmpty => {
formatter.write_str("remote interpolation buffer is empty")
}
Self::PredictedEntityLimit => {
formatter.write_str("pending predicted entity limit exceeded")
}
}
}
}
impl std::error::Error for NetcodeError {}