sark-http 0.29.4

HTTP wire types, semantics, codecs, and ownership invariants for Sark
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use std::num::NonZero;

/// Encoded-length arithmetic exceeded the representable domain.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Overflow {
    pub current: usize,
    pub added: NonZero<usize>,
}

impl Overflow {
    pub fn try_add(current: usize, added: usize) -> Result<usize, Self> {
        current.checked_add(added).ok_or_else(|| Self {
            current,
            added: NonZero::<usize>::MIN.saturating_add(added - 1),
        })
    }
}