|
1 | 1 | //-
|
2 |
| -// Copyright 2017, 2018 Jason Lingle |
| 2 | +// Copyright 2017, 2018 The proptest developers |
3 | 3 | //
|
4 | 4 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
5 | 5 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
12 | 12 | //! You do not normally need to access things in this module directly except
|
13 | 13 | //! when implementing new low-level strategies.
|
14 | 14 |
|
15 |
| -use std::borrow::Cow; |
| 15 | +use std::borrow::{Borrow, Cow}; |
16 | 16 | use std::collections::BTreeMap;
|
17 | 17 | use std::env;
|
18 | 18 | use std::ffi::OsString;
|
19 | 19 | use std::fmt;
|
20 | 20 | use std::fs;
|
21 | 21 | use std::io::{self, BufRead, Write};
|
| 22 | +use std::ops; |
22 | 23 | use std::panic::{self, AssertUnwindSafe};
|
23 | 24 | use std::path::{Path, PathBuf};
|
24 | 25 | use std::sync::{Arc, RwLock};
|
@@ -284,6 +285,47 @@ impl FailurePersistence {
|
284 | 285 | }
|
285 | 286 | }
|
286 | 287 |
|
| 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 | + |
287 | 329 | /// Errors which can be returned from test cases to indicate non-successful
|
288 | 330 | /// completion.
|
289 | 331 | ///
|
|
0 commit comments