Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Error for ExactlyOneError, change interals of it a bit #484

Merged
merged 4 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move test to right spot, and fix conditional compilation
  • Loading branch information
Xaeroxe committed Sep 29, 2020
commit 4850993569a308d284b0db498d82aa33de7b73cd
16 changes: 0 additions & 16 deletions src/exactly_one_err.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#[cfg(feature = "use_std")]
use std::error::Error;
#[cfg(feature = "use_std")]
use std::fmt::{Debug, Display, Formatter, Result as FmtResult};

use std::iter::ExactSizeIterator;
Expand Down Expand Up @@ -73,7 +72,6 @@ where

impl<I> ExactSizeIterator for ExactlyOneError<I> where I: ExactSizeIterator {}

#[cfg(feature = "use_std")]
impl<I> Display for ExactlyOneError<I>
where I: Iterator
{
Expand All @@ -87,7 +85,6 @@ impl<I> Display for ExactlyOneError<I>
}
}

#[cfg(feature = "use_std")]
impl<I> Debug for ExactlyOneError<I>
where I: Iterator,
I::Item: Debug,
Expand All @@ -110,17 +107,4 @@ impl<I> Debug for ExactlyOneError<I>
#[cfg(feature = "use_std")]
impl<I> Error for ExactlyOneError<I> where I: Iterator, I::Item: Debug, {}

#[cfg(all(test, feature = "use_std"))]
mod tests {
use super::*;

#[test]
fn question_mark_syntax_works() {
question_mark_return().unwrap_err()
}

fn question_mark_return() -> Result<(), impl Error> {
let x = Err(ExactlyOneError::new(None, []))?;
Ok(())
}
}
11 changes: 11 additions & 0 deletions tests/test_std.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use permutohedron;
use itertools as it;
use crate::it::Itertools;
use crate::it::ExactlyOneError;
use crate::it::multizip;
use crate::it::multipeek;
use crate::it::peek_nth;
Expand Down Expand Up @@ -913,3 +914,13 @@ fn tree_fold1() {
assert_eq!(actual, expected);
}
}

#[test]
fn exactly_one_question_mark_syntax_works() {
exactly_one_question_mark_return().unwrap_err();
}

fn exactly_one_question_mark_return() -> Result<(), ExactlyOneError<std::slice::Iter<'static, ()>>> {
[].iter().exactly_one()?;
Ok(())
}