Extension trait to chunk iterators into const-length arrays.

Overview

const-chunks

This crate provides an extension trait that lets you chunk iterators into constant-length arrays using const generics.

See the docs for more info.

use const_chunks::IteratorConstChunks;

let mut iter = vec![1, 2, 3, 4, 5].into_iter().const_chunks::<2>();
assert_eq!(iter.next(), Some([1,2]));
assert_eq!(iter.next(), Some([3,4]));
assert_eq!(iter.next(), None);

let mut remainder = iter.into_remainder().unwrap();
assert_eq!(remainder.next(), Some(5));
assert_eq!(remainder.next(), None);

Safety

This crate uses unsafe to manipulate uninitialized memory.

To prevent undefined behaviour, the code runs MIRI in CI, and is both very short and easy to audit.

Nevertheless, you should still consider this fact if you're trying to minimize unsafe dependencies.

MSRV

This crate requires rustc version 1.65 or newer.

This crate's MSRV is enforced through the manifest's rust-version key.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

You might also like...
Plain Rust wrapper of Ableton Link's C 11 extension

rusty_link rusty_link is a Rust wrapper of abl_link, which is a C 11 extension for Ableton Link, provided by Ableton. This library attempts to be most

Extension to `thiserror` that helps reduce the amount of handwriting

justerror This macro piggybacks on thiserror crate and is supposed to reduce the amount of handwriting when you want errors in your app to be describe

Experimental extension that brings OpenAI API to your PostgreSQL to run queries in human language.

Postgres ChatGPT Experimental PostgreSQL extension that enables the use of OpenAI GPT API inside PostgreSQL, allowing for queries to be written usi

GitHub CLI extension to search some repos interactively.
GitHub CLI extension to search some repos interactively.

gh activity GitHub CLI extension to search some repos interactively. It's wrapper to build gh command provided by GitHub CLI, it could search more eas

Cross-platform GameMaker extension for getting system information and resource usage
Cross-platform GameMaker extension for getting system information and resource usage

GM Sysinfo Cross-platform GameMaker extension for getting system information and resource usage Table of Contents Table of Contents Examples Display m

A PostgreSQL extension for rendering the Tera HTML templating language.

PGTera PGTera is a PostgreSQL extension that provides functions for using Tera to render HTML templates. When used with a tool like Postgrest, you can

Turn static CLI commands into TUIs with ease
Turn static CLI commands into TUIs with ease

lazycli Turn static CLI commands into TUIs with ease Demo: Usage Pick a command that spits out either a list or table of content, like ls, docker ps,

📜🔁🎶 A CLI which converts morse code into sound

morse2sound 🎵 A CLI which converts morse code to sound Big shoutout to Br1ght0ne for guiding me how to use Rust on stream

parse command-line arguments into a hashmap and vec of positional args

parse command-line arguments into a hashmap and vec of positional args This library doesn't populate custom structs, format help messages, or convert types.

Comments
  • Memory leak if underlying `Iterator::next` panics.

    Memory leak if underlying `Iterator::next` panics.

    Panics prevent the cleanup code from running. This is problematic when under a catch_unwind or similar mechanism (common in multi-threaded applications).

    This could be fixed by using a guard similar to https://github.com/rust-lang/rust/blob/19ca5692f69d20643656bf501fd171f1907ef875/library/core/src/array/mod.rs#L888-L899. If no panic is detected, we can std::mem::forget the guard. If there is a panic, then the guard's Drop impl will cleanup any remaining memory.

    Thanks to ScottMCM and Elomatreb for pointing this out.

    opened by LouisGariepy 0
Owner
Louis Gariépy
Physics graduate. Interested in dev tools and systems programming.
Louis Gariépy
Vim plugin to quickly parse strings into arrays.

butcher Vim plugin to quickly parse strings into arrays. It is painful to write arrays in any programming language, so butcher makes it easy for you.

null 5 Dec 31, 2021
decode a byte stream of varint length-encoded messages into a stream of chunks

length-prefixed-stream decode a byte stream of varint length-encoded messages into a stream of chunks This crate is similar to and compatible with the

James Halliday 4 Feb 26, 2022
Allows processing of iterators of Result types

try-continue try-continue provides one method, try_continue, which allows you to work with iterators of type Result<T, _>, as if they were simply iter

Nick Krichevsky 3 Dec 26, 2021
An alternative to `qcell` and `ghost-cell` that instead uses const generics

Purpose This crate is another attempt at the ghost-cell / qcell saga of cell crates. This provides an alternative to std::cell::RefCell that can allow

SpencerBeige 5 Feb 9, 2023
Asserts const generic expressions at build-time.

build_assert build_assert allows you to make assertions at build-time. Unlike assert and some implementations of compile-time assertions, such as stat

MaxXing 4 Nov 23, 2023
FileSorterX is an automatic file sorting application that sorts your files into folders based on their file extension

FileSorterX is an automatic file sorting application that sorts your files into folders based on their file extension. With FileSorterX, you can easily keep your files organized and find what you need quickly.

Xanthus 22 Apr 4, 2023
A simple trait-based framework for the annual Advent of Code programming challenge.

lib_aoc lib_aoc is a simple trait-based framework for the annual Advent of Code programming challenge. Focus less on the boilerplate and more on the p

null 2 Dec 8, 2022
This library provides a convenient derive macro for the standard library's std::error::Error trait.

derive(Error) This library provides a convenient derive macro for the standard library's std::error::Error trait. [dependencies] therror = "1.0" Compi

Sebastian Thiel 5 Oct 23, 2023
Jupyter extension for Rust.

rustdef Jupyter extension for jupyter notebook and rust user. You can define functions in rust and run them as python functions. This extension is bui

Ryosuke Kamesawa 20 Dec 14, 2022
This automatically patches the RoPro extension for you, allowing you to have pro_tier for free.

RoPro Patcher This automatically patches the RoPro extension for you, allowing you to have pro_tier for free. NOTE Chrome, Brave (and possibly other b

Stefan 10 Jan 1, 2023