Index: Cargo.toml ================================================================== --- Cargo.toml +++ Cargo.toml @@ -1,8 +1,8 @@ [package] name = "bndpresbufq" -version = "0.1.2" +version = "0.1.3" edition = "2021" license = "0BSD" # https://crates.io/category_slugs categories = [ "data-structures" ] keywords = [ "buffer", "queue", "bounded", "bounds-preserving" ] @@ -21,11 +21,11 @@ # https://doc.rust-lang.org/cargo/reference/manifest.html#the-badges-section [badges] maintenance = { status = "passively-maintained" } [dependencies] -limq = { version = "0.1.2" } +limq = { version = "0.1.3" } [package.metadata.docs.rs] rustdoc-args = ["--generate-link-to-definition"] [lints.clippy] Index: src/lib.rs ================================================================== --- src/lib.rs +++ src/lib.rs @@ -192,10 +192,39 @@ self.q.force_push(n); self.size += nlen; Ok(()) } + + /// Attempt to put a buffer back on to the queue so that it will be the next + /// one to be pulled off it. + /// + /// Intended to put a buffer back on the queue that was just taken off the + /// queue but can not currently be processed. + /// + /// # Errors + /// If the buffer would exceed the queues limits the buffer is returned. + pub fn try_return(&mut self, n: Vec) -> Result<(), Vec> { + let nlen = n.len(); + + // If a maximum size has been set for this queue .. + if let Some(max_size) = self.max_size { + // .. then bail if the input buffer size is larger than the maximum + // allowed total queue size. + if nlen > max_size { + return Err(n); + } + + // Make sure this node wouldn't exceed queue total capacity + if self.size + nlen > max_size { + return Err(n); + } + } + + self.size += nlen; + self.q.try_return(n) + } /// Take next buffer off queue. #[inline] pub fn pop(&mut self) -> Option> { let n = self.q.pop()?; Index: www/changelog.md ================================================================== --- www/changelog.md +++ www/changelog.md @@ -1,17 +1,28 @@ # Change Log ## [Unreleased] -[Details](/vdiff?from=bndpresbufq-0.1.2&to=trunk) +[Details](/vdiff?from=bndpresbufq-0.1.3&to=trunk) ### Added ### Changed ### Removed +--- + +## [0.1.3] + +[Details](/vdiff?from=bndpresbufq-0.1.2&to=bndpresbufq-0.1.3) + +### Added + +- `BndPresLimBufQ::try_return()` can be used to return a node that was just + taken off the queue back to it so it will be return next. + --- ## [0.1.2] - 2024-09-13 [Details](/vdiff?from=bndpresbufq-0.1.1&to=bndpresbufq-0.1.2)