Skip to content

Commit 97cfaa8

Browse files
authored
Merge pull request #47 from kammitama5/removePredicateImplementations
Remove predicate implementations
2 parents 70ce862 + 16b1f05 commit 97cfaa8

File tree

1 file changed

+105
-9
lines changed

1 file changed

+105
-9
lines changed

src/assert.rs

+105-9
Original file line numberDiff line numberDiff line change
@@ -404,27 +404,123 @@ where
404404
}
405405
}
406406

407-
impl IntoCodePredicate<predicates::ord::EqPredicate<i32>> for i32 {
408-
type Predicate = predicates::ord::EqPredicate<i32>;
407+
// Keep `predicates` concrete Predicates out of our public API.
408+
/// [Predicate] used by [`IntoCodePredicate`] for bytes.
409+
///
410+
/// [`IntoCodePredicate`]: trait.IntoCodePredicate.html
411+
/// [Predicate]: https://docs.rs/predicates-core/0.9.0/predicates_core/trait.Predicate.html
412+
#[derive(Debug)]
413+
pub struct EqCodePredicate(predicates::ord::EqPredicate<i32>);
414+
415+
impl EqCodePredicate {
416+
pub(crate) fn new(value: i32) -> Self {
417+
let pred = predicates::ord::eq(value);
418+
EqCodePredicate(pred)
419+
}
420+
}
421+
422+
impl predicates_core::reflection::PredicateReflection for EqCodePredicate {
423+
fn parameters<'a>(
424+
&'a self,
425+
) -> Box<Iterator<Item = predicates_core::reflection::Parameter<'a>> + 'a> {
426+
self.0.parameters()
427+
}
428+
429+
/// Nested `Predicate`s of the current `Predicate`.
430+
fn children<'a>(&'a self) -> Box<Iterator<Item = predicates_core::reflection::Child<'a>> + 'a> {
431+
self.0.children()
432+
}
433+
}
434+
435+
impl predicates_core::Predicate<i32> for EqCodePredicate {
436+
fn eval(&self, item: &i32) -> bool {
437+
self.0.eval(item)
438+
}
439+
440+
fn find_case<'a>(
441+
&'a self,
442+
expected: bool,
443+
variable: &i32,
444+
) -> Option<predicates_core::reflection::Case<'a>> {
445+
self.0.find_case(expected, variable)
446+
}
447+
}
448+
449+
impl fmt::Display for EqCodePredicate {
450+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
451+
self.0.fmt(f)
452+
}
453+
}
454+
455+
impl IntoCodePredicate<EqCodePredicate> for i32 {
456+
type Predicate = EqCodePredicate;
409457

410458
fn into_code(self) -> Self::Predicate {
411-
predicates::ord::eq(self)
459+
Self::Predicate::new(self)
412460
}
413461
}
414462

415-
impl IntoCodePredicate<predicates::iter::InPredicate<i32>> for Vec<i32> {
416-
type Predicate = predicates::iter::InPredicate<i32>;
463+
// Keep `predicates` concrete Predicates out of our public API.
464+
/// [Predicate] used by [`IntoCodePredicate`] for bytes.
465+
///
466+
/// [`IntoCodePredicate`]: trait.IntoCodePredicate.html
467+
/// [Predicate]: https://docs.rs/predicates-core/0.9.0/predicates_core/trait.Predicate.html
468+
#[derive(Debug)]
469+
pub struct InCodePredicate(predicates::iter::InPredicate<i32>);
470+
471+
impl InCodePredicate {
472+
pub(crate) fn new<I:IntoIterator<Item=i32>>(value: I) -> Self {
473+
let pred = predicates::iter::in_iter(value);
474+
InCodePredicate(pred)
475+
}
476+
}
477+
478+
impl predicates_core::reflection::PredicateReflection for InCodePredicate {
479+
fn parameters<'a>(
480+
&'a self,
481+
) -> Box<Iterator<Item = predicates_core::reflection::Parameter<'a>> + 'a> {
482+
self.0.parameters()
483+
}
484+
485+
/// Nested `Predicate`s of the current `Predicate`.
486+
fn children<'a>(&'a self) -> Box<Iterator<Item = predicates_core::reflection::Child<'a>> + 'a> {
487+
self.0.children()
488+
}
489+
}
490+
491+
impl predicates_core::Predicate<i32> for InCodePredicate {
492+
fn eval(&self, item: &i32) -> bool {
493+
self.0.eval(item)
494+
}
495+
496+
fn find_case<'a>(
497+
&'a self,
498+
expected: bool,
499+
variable: &i32,
500+
) -> Option<predicates_core::reflection::Case<'a>> {
501+
self.0.find_case(expected, variable)
502+
}
503+
}
504+
505+
impl fmt::Display for InCodePredicate {
506+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
507+
self.0.fmt(f)
508+
}
509+
}
510+
511+
impl IntoCodePredicate<InCodePredicate> for Vec<i32> {
512+
type Predicate = InCodePredicate;
417513

418514
fn into_code(self) -> Self::Predicate {
419-
predicates::iter::in_iter(self)
515+
Self::Predicate::new(self)
420516
}
421517
}
422518

423-
impl IntoCodePredicate<predicates::iter::InPredicate<i32>> for &'static [i32] {
424-
type Predicate = predicates::iter::InPredicate<i32>;
519+
impl IntoCodePredicate<InCodePredicate> for &'static [i32] {
520+
type Predicate = InCodePredicate;
425521

426522
fn into_code(self) -> Self::Predicate {
427-
predicates::iter::in_iter(self.iter().cloned())
523+
Self::Predicate::new(self.iter().cloned())
428524
}
429525
}
430526

0 commit comments

Comments
 (0)