leyline/core/response/
prefix.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2#[non_exhaustive]
3pub enum StopReason {
4 PredicateMatched,
5 LimitReached,
6 EndOfBody,
7}
8
9#[derive(Debug, Clone, PartialEq, Eq)]
10#[non_exhaustive]
11pub struct PrefixRead {
12 pub bytes: Vec<u8>,
13 pub stopped_by: StopReason,
14}
15
16pub(super) fn stop_reason<F>(
17 out: &[u8],
18 from: usize,
19 limit: usize,
20 done: &mut F,
21) -> Option<StopReason>
22where
23 F: FnMut(&[u8], usize) -> bool,
24{
25 if out.len() > from && done(out, from) {
26 return Some(StopReason::PredicateMatched);
27 }
28 (out.len() >= limit).then_some(StopReason::LimitReached)
29}