diff --git a/src/lib.rs b/src/lib.rs index d6898c8..b338e28 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -255,11 +255,7 @@ impl Chunker { pub fn max_size(self, max: usize) -> Chunker> { assert!(max > 0); Chunker { - inner: SizeLimited { - inner: self.inner, - pos: 0, - max_size: max, - }, + inner: SizeLimited::new(self.inner, max), } } } @@ -445,6 +441,17 @@ pub struct SizeLimited { max_size: usize, } +impl SizeLimited { + /// Wraps the given chunker implementation to limit the size of produced chunks. + pub fn new(inner: I, max_size: usize) -> Self { + SizeLimited { + inner, + pos: 0, + max_size, + } + } +} + impl ChunkerImpl for SizeLimited { fn find_boundary(&mut self, data: &[u8]) -> Option { assert!(self.max_size > self.pos);