Skip to content

Commit c81a728

Browse files
committed
Move Rejection alongside the types that use it.
1 parent cbb3029 commit c81a728

File tree

7 files changed

+45
-65
lines changed

7 files changed

+45
-65
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
### New Additions
1313

14-
- Added `proptest::strategy::Rejection` which allows you to avoid heap
14+
- Added `proptest::test_runner::Rejection` which allows you to avoid heap
1515
allocation in some places or share allocation with string-interning.
1616

1717
- Added a type alias `proptest::strategy::NewTree<S>` where `S: Strategy`

src/strategy/filter.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use std::fmt;
1111
use std::sync::Arc;
1212

1313
use strategy::traits::*;
14-
use strategy::rejection::Rejection;
1514
use test_runner::*;
1615

1716
/// `Strategy` and `ValueTree` filter adaptor.

src/strategy/flatten.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use std::sync::Arc;
1313

1414
use strategy::fuse::Fuse;
1515
use strategy::traits::*;
16-
use strategy::Rejection;
1716
use test_runner::*;
1817

1918
/// Adaptor that flattens a `Strategy` which produces other `Strategy`s into a

src/strategy/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
//! Defines the core traits used by Proptest.
1111
12-
mod rejection;
1312
mod traits;
1413
mod map;
1514
mod filter;
@@ -19,7 +18,6 @@ mod recursive;
1918
mod shuffle;
2019
mod fuse;
2120

22-
pub use self::rejection::*;
2321
pub use self::traits::*;
2422
pub use self::map::*;
2523
pub use self::filter::*;

src/strategy/rejection.rs

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/strategy/statics.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
use std::fmt;
2828

2929
use strategy::traits::*;
30-
use strategy::Rejection;
3130
use test_runner::*;
3231

3332
/// Essentially `Fn (&T) -> bool`.

src/test_runner.rs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//-
2-
// Copyright 2017, 2018 Jason Lingle
2+
// Copyright 2017, 2018 The proptest developers
33
//
44
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
55
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
@@ -12,13 +12,14 @@
1212
//! You do not normally need to access things in this module directly except
1313
//! when implementing new low-level strategies.
1414
15-
use std::borrow::Cow;
15+
use std::borrow::{Borrow, Cow};
1616
use std::collections::BTreeMap;
1717
use std::env;
1818
use std::ffi::OsString;
1919
use std::fmt;
2020
use std::fs;
2121
use std::io::{self, BufRead, Write};
22+
use std::ops;
2223
use std::panic::{self, AssertUnwindSafe};
2324
use std::path::{Path, PathBuf};
2425
use std::sync::{Arc, RwLock};
@@ -284,6 +285,47 @@ impl FailurePersistence {
284285
}
285286
}
286287

288+
/// The reason for why something, such as a generated value, was rejected.
289+
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
290+
pub struct Rejection(Cow<'static, str>);
291+
292+
impl From<&'static str> for Rejection {
293+
fn from(s: &'static str) -> Self {
294+
Rejection(s.into())
295+
}
296+
}
297+
298+
impl From<String> for Rejection {
299+
fn from(s: String) -> Self {
300+
Rejection(s.into())
301+
}
302+
}
303+
304+
impl From<Box<str>> for Rejection {
305+
fn from(s: Box<str>) -> Self {
306+
Rejection(String::from(s).into())
307+
}
308+
}
309+
310+
impl ops::Deref for Rejection {
311+
type Target = str;
312+
fn deref(&self) -> &Self::Target { self.0.deref() }
313+
}
314+
315+
impl AsRef<str> for Rejection {
316+
fn as_ref(&self) -> &str { &*self }
317+
}
318+
319+
impl Borrow<str> for Rejection {
320+
fn borrow(&self) -> &str { &*self }
321+
}
322+
323+
impl fmt::Display for Rejection {
324+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
325+
fmt::Display::fmt(self.as_ref(), f)
326+
}
327+
}
328+
287329
/// Errors which can be returned from test cases to indicate non-successful
288330
/// completion.
289331
///

0 commit comments

Comments
 (0)