Crates.io | single |
lib.rs | single |
version | 1.0.1 |
source | src |
created_at | 2017-06-08 05:18:36.999911 |
updated_at | 2022-07-08 18:23:33.052871 |
description | Deprecated poor-man's version of Itertools::at_most_one |
homepage | |
repository | https://github.com/CAD97/rust-single |
max_upload_size | |
id | 18196 |
size | 10,254 |
Use Itertools::at_most_one
instead, which provides equivalent functionality in a better fashion.
This crate provides the Single
trait for extracting the element from a single-element iterator.
You may use this crate under the MIT license or the Apache License 2.0 at your discretion.
pub trait Single: Iterator {
fn single(self) -> Result<Self::Item, Error>;
}
fn single(self) -> Result<Self::Item, Error>
Get the single element from a single-element iterator.
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));
impl<I: Iterator> Single for I {}