#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

#75 in #once

Download history 364/week @ 2024-03-31 231/week @ 2024-04-07 333/week @ 2024-04-14 313/week @ 2024-04-21 153/week @ 2024-04-28 166/week @ 2024-05-05 200/week @ 2024-05-12 162/week @ 2024-05-19 168/week @ 2024-05-26 163/week @ 2024-06-02 131/week @ 2024-06-09 200/week @ 2024-06-16 174/week @ 2024-06-23 83/week @ 2024-06-30 144/week @ 2024-07-07 201/week @ 2024-07-14

625 downloads per month
Used in 6 crates (3 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.4–2.2MB
~50K SLoC