#single #iterator #once #only

deprecated no-std single

Deprecated poor-man's version of Itertools::at_most_one

6 releases (2 stable)

Uses old Rust 2015

1.0.1 Jul 8, 2022
1.0.0 Aug 21, 2018
0.3.0 Dec 16, 2017
0.2.1 Jun 11, 2017
0.1.0 Jun 8, 2017

#26 in #single

Download history 223/week @ 2024-12-16 95/week @ 2024-12-23 96/week @ 2024-12-30 375/week @ 2025-01-06 533/week @ 2025-01-13 360/week @ 2025-01-20 301/week @ 2025-01-27 472/week @ 2025-02-03 416/week @ 2025-02-10 318/week @ 2025-02-17 395/week @ 2025-02-24 567/week @ 2025-03-03 838/week @ 2025-03-10 380/week @ 2025-03-17 305/week @ 2025-03-24 272/week @ 2025-03-31

1,802 downloads per month
Used in 7 crates (4 directly)

MIT/Apache

7KB
66 lines

This crate is deprecated.

Use Itertools::at_most_one instead, which provides equivalent functionality in a better fashion.


Single

Build Status crates.io downloads version downloads issues open

This crate provides the Single trait for extracting the element from a single-element iterator.

License

You may use this crate under the MIT license or the Apache License 2.0 at your discretion.

Trait single::Single

pub trait Single: Iterator {
    fn single(self) -> Result<Self::Item, Error>;
}

Required Methods

fn single(self) -> Result<Self::Item, Error>

Get the single element from a single-element iterator.

Examples

assert_eq!(iter::empty::<i32>().single(), Err(single::Error::NoElements));
assert_eq!(iter::once(0).single(), Ok(0));
assert_eq!(iter::repeat(0).single(), Err(single::Error::MultipleElements));

Implementors

impl<I: Iterator> Single for I {}

Dependencies

~1.5–7MB
~51K SLoC