Skip to content

Commit

Permalink
feat!: seal all assertion traits to prevent accidental breaking chang…
Browse files Browse the repository at this point in the history
…es downstream

BREAKING CHANGE: making traits sealed breaks all existing implementations
  • Loading branch information
open-schnick committed Dec 23, 2024
1 parent 691b868 commit ebc05c4
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/assertions/boolean.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::{implementation, AssertionConnector, BasicAsserter};
use crate::{implementation, private, AssertionConnector, BasicAsserter};

/// Specifies various assertions on values that can be converted to a boolean. Implemented on [`BasicAsserter`]
pub trait BooleanAssertion<IntoBoolean>
///
/// This trait is sealed and cannot be implemented outside Smoothy.
pub trait BooleanAssertion<IntoBoolean>: private::Sealed
where
IntoBoolean: Into<bool>,
{
Expand Down
6 changes: 4 additions & 2 deletions src/assertions/equality.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::{implementation, AssertionConnector, BasicAsserter};
use crate::{implementation, private, AssertionConnector, BasicAsserter};
use std::fmt::Debug;

/// Specifies various equality assertions. Implemented on [`BasicAsserter`]
pub trait EqualityAssertion<AssertedType>
///
/// This trait is sealed and cannot be implemented outside Smoothy.
pub trait EqualityAssertion<AssertedType>: private::Sealed
where
AssertedType: PartialEq + Debug,
{
Expand Down
6 changes: 4 additions & 2 deletions src/assertions/iter.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::{implementation, implementation::assert, AssertionConnector, BasicAsserter};
use crate::{implementation, implementation::assert, private, AssertionConnector, BasicAsserter};
use std::fmt::Debug;

/// Specifies various assertions on [`IntoIterator`]. Implemented on [`BasicAsserter`]
pub trait IteratorAssertion<Iterable, Item>
///
/// This trait is sealed and cannot be implemented outside Smoothy.
pub trait IteratorAssertion<Iterable, Item>: private::Sealed
where
Iterable: IntoIterator<Item = Item>,
Item: Debug,
Expand Down
6 changes: 4 additions & 2 deletions src/assertions/option.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::{implementation, BasicAsserter};
use crate::{implementation, private, BasicAsserter};
use std::fmt::Debug;

/// Specifies various assertions on [`Option`]. Implemented on [`BasicAsserter`]
pub trait OptionAssertion<OptionValue>
///
/// This trait is sealed and cannot be implemented outside Smoothy.
pub trait OptionAssertion<OptionValue>: private::Sealed
where
OptionValue: Debug,
{
Expand Down
6 changes: 4 additions & 2 deletions src/assertions/result.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::{implementation, BasicAsserter};
use crate::{implementation, private, BasicAsserter};
use std::fmt::Debug;

/// Specifies various assertions on [`Result`]. Implemented on [`BasicAsserter`]
pub trait ResultAssertion<OkValue, ErrValue>
///
/// This trait is sealed and cannot be implemented outside Smoothy.
pub trait ResultAssertion<OkValue, ErrValue>: private::Sealed
where
OkValue: Debug,
ErrValue: Debug,
Expand Down
6 changes: 4 additions & 2 deletions src/assertions/string.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::{implementation, AssertionConnector, BasicAsserter};
use crate::{implementation, private, AssertionConnector, BasicAsserter};
use regex::Regex;

/// Specifies various assertions on [`String`]. Implemented on [`BasicAsserter`]
pub trait StringAssertion<StringLike>
///
/// This trait is sealed and cannot be implemented outside Smoothy.
pub trait StringAssertion<StringLike>: private::Sealed
where
StringLike: AsRef<str>,
{
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,10 @@ pub const fn assert_that<AssertedType>(value: AssertedType) -> BasicAsserter<Ass
pub struct BasicAsserter<AssertedType> {
pub(crate) value: AssertedType,
}

/// Helper construct to prevent implementation of the assertion extension traits outside the crate
mod private {
pub trait Sealed {}

impl<AssertedType> Sealed for crate::BasicAsserter<AssertedType> {}
}

0 comments on commit ebc05c4

Please sign in to comment.