Skip to content

Commit

Permalink
Merge pull request #11 from rodrimati1992/1_9
Browse files Browse the repository at this point in the history
1.9.0 release
  • Loading branch information
rodrimati1992 authored Jan 6, 2024
2 parents 3195ff8 + e703910 commit 2d79ba0
Show file tree
Hide file tree
Showing 19 changed files with 285 additions and 171 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "typewit"
version = "1.8.0"
version = "1.9.0"
authors = ["rodrimati1992 <[email protected]>"]
rust-version = "1.57.0"
edition = "2021"
Expand Down
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ This is the changelog, summarising changes in each version(some minor changes ma

# 1.0

### 1.9.0

Deprecated `{TypeCmp, TypeNe}::with_any` due to unsoundness: both constructors rely on `TypeId::of::<L>() != TypeId::of::<R>()` implying `L != R`, which is not true in the general case.

### 1.8.0

Added `"rust_1_65"` feature
Expand Down
29 changes: 21 additions & 8 deletions src/methods/zipping_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,14 @@ declare_zip_items!{
/// This example shows all permutations of argument and return types.
///
/// ```rust
/// use typewit::{TypeCmp, TypeEq, TypeNe};
/// use typewit::{TypeCmp, TypeEq, TypeNe, type_ne};
/// use typewit::methods::zip2;
///
/// with::<u8, u8, bool, u16, u32>(TypeEq::NEW, TypeNe::with_any().unwrap(), TypeCmp::with_any());
/// with::<u8, u8, bool, u16, u32>(
/// TypeEq::NEW,
/// type_ne!(u8, bool),
/// TypeCmp::Ne(type_ne!(u16, u32)),
/// );
///
/// const fn with<A, B, C, D, E>(eq: TypeEq<A, B>, ne: TypeNe<B, C>, cmp: TypeCmp<D, E>) {
/// let _: TypeEq<(A, B), (B, A)> = zip2(eq, eq.flip());
Expand Down Expand Up @@ -346,10 +350,14 @@ declare_zip_items!{
/// This example shows basic usage.
///
/// ```rust
/// use typewit::{TypeCmp, TypeEq, TypeNe, type_eq};
/// use typewit::{TypeCmp, TypeEq, TypeNe, type_eq, type_ne};
/// use typewit::methods::zip3;
///
/// with::<u8, u8, bool, u16, u32>(TypeEq::NEW, TypeNe::with_any().unwrap(), TypeCmp::with_any());
/// with::<u8, u8, bool, u16, u32>(
/// TypeEq::NEW,
/// type_ne!(u8, bool),
/// TypeCmp::Ne(type_ne!(u16, u32)),
/// );
///
/// const fn with<A, B, C, D, E>(eq: TypeEq<A, B>, ne: TypeNe<B, C>, cmp: TypeCmp<D, E>) {
/// let _: TypeEq<(A, B, i64), (B, A, i64)> = zip3(eq, eq.flip(), type_eq::<i64>());
Expand Down Expand Up @@ -391,10 +399,14 @@ declare_zip_items!{
/// This example shows basic usage.
///
/// ```rust
/// use typewit::{TypeCmp, TypeEq, TypeNe, type_eq};
/// use typewit::{TypeCmp, TypeEq, TypeNe, type_eq, type_ne};
/// use typewit::methods::zip4;
///
/// with::<u8, u8, bool, u16, u32>(TypeEq::NEW, TypeNe::with_any().unwrap(), TypeCmp::with_any());
/// with::<u8, u8, bool, u16, u32>(
/// TypeEq::NEW,
/// type_ne!(u8, bool),
/// TypeCmp::Ne(type_ne!(u16, u32)),
/// );
///
/// const fn with<A, B, C, D, E>(eq: TypeEq<A, B>, ne: TypeNe<B, C>, cmp: TypeCmp<D, E>) {
/// let _: TypeEq<(A, u64, B, i64), (B, u64, A, i64)> =
Expand Down Expand Up @@ -458,11 +470,12 @@ mod with_const_marker {
/// methods::in_array,
/// const_marker::Usize,
/// TypeCmp, TypeEq, TypeNe,
/// type_ne,
/// };
///
/// let eq_ty: TypeEq<i16, i16> = TypeEq::NEW;
/// let ne_ty: TypeNe<i16, u16> = TypeNe::with_any().unwrap();
/// let cmp_ty: TypeCmp<i16, u16> = TypeCmp::with_any();
/// let ne_ty: TypeNe<i16, u16> = type_ne!(i16, u16);
/// let cmp_ty: TypeCmp<i16, u16> = TypeCmp::Ne(type_ne!(i16, u16));
///
/// let eq_len: TypeEq<Usize<0>, Usize<0>> = TypeEq::NEW;
/// let ne_len: TypeNe<Usize<1>, Usize<2>> = Usize.equals(Usize).unwrap_ne();
Expand Down
23 changes: 14 additions & 9 deletions src/type_cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,16 @@ impl<L: ?Sized, R: ?Sized> TypeCmp<L, R> {
/// let ne = TypeCmp::<u8, i8>::with_any();
/// assert!(matches!(ne, TypeCmp::Ne(_)));
/// ```
#[deprecated = concat!(
"fallout of `https://github.com/rust-lang/rust/issues/97156`,",
"`TypeId::of::<L>() != TypeId::of::<R>()` does not imply `L != R`"
)]
pub fn with_any() -> Self
where
L: Sized + Any,
R: Sized + Any,
{
#[allow(deprecated)]
if let Some(equal) = TypeEq::with_any() {
TypeCmp::Eq(equal)
} else if let Some(unequal) = TypeNe::with_any() {
Expand Down Expand Up @@ -179,12 +184,12 @@ impl<L: ?Sized, R: ?Sized> TypeCmp<L, R> {
/// # Example
///
/// ```rust
/// use typewit::{TypeCmp, TypeEq, TypeNe};
/// use typewit::{TypeCmp, TypeEq, type_ne};
///
/// let eq: TypeCmp<u8, u8> = TypeCmp::with_any();
/// let eq: TypeCmp<u8, u8> = TypeCmp::Eq(TypeEq::NEW);
/// assert!(matches!(eq.eq(), Some(TypeEq::<u8, u8>{..})));
///
/// let ne = TypeCmp::<u8, i8>::with_any();
/// let ne = TypeCmp::Ne(type_ne!(u8, i8));
/// assert!(matches!(ne.eq(), None::<TypeEq<u8, i8>>));
/// ```
pub const fn eq(self) -> Option<TypeEq<L, R>> {
Expand All @@ -199,12 +204,12 @@ impl<L: ?Sized, R: ?Sized> TypeCmp<L, R> {
/// # Example
///
/// ```rust
/// use typewit::{TypeCmp, TypeEq, TypeNe};
/// use typewit::{TypeCmp, TypeEq, TypeNe, type_ne};
///
/// let eq: TypeCmp<u8, u8> = TypeCmp::with_any();
/// let eq: TypeCmp<u8, u8> = TypeCmp::Eq(TypeEq::NEW);
/// assert!(matches!(eq.ne(), None::<TypeNe<u8, u8>>));
///
/// let ne = TypeCmp::<u8, i8>::with_any();
/// let ne = TypeCmp::Ne(type_ne!(u8, i8));
/// assert!(matches!(ne.ne(), Some(TypeNe::<u8, i8>{..})));
/// ```
pub const fn ne(self) -> Option<TypeNe<L, R>> {
Expand Down Expand Up @@ -259,7 +264,7 @@ impl<L: ?Sized, R: ?Sized> TypeCmp<L, R> {
/// ```rust
/// use typewit::{TypeCmp, TypeEq};
///
/// let eq: TypeCmp<u8, u8> = TypeCmp::with_any();
/// let eq: TypeCmp<u8, u8> = TypeCmp::Eq(TypeEq::NEW);
/// assert!(matches!(eq.unwrap_eq(), TypeEq::<u8, u8>{..}));
/// ```
#[track_caller]
Expand All @@ -279,9 +284,9 @@ impl<L: ?Sized, R: ?Sized> TypeCmp<L, R> {
/// # Example
///
/// ```rust
/// use typewit::{TypeCmp, TypeNe};
/// use typewit::{TypeCmp, TypeNe, type_ne};
///
/// let ne = TypeCmp::<u8, i8>::with_any();
/// let ne = TypeCmp::Ne(type_ne!(u8, i8));
/// assert!(matches!(ne.unwrap_ne(), TypeNe::<u8, i8>{..}));
/// ```
#[track_caller]
Expand Down
5 changes: 3 additions & 2 deletions src/type_cmp/extra_type_cmp_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,11 @@ impl<L, R> TypeCmp<L, R> {
/// use typewit::{
/// const_marker::Usize,
/// TypeCmp, TypeEq, TypeNe,
/// type_ne,
/// };
///
/// let cmp_eq_ty: TypeCmp<i32, i32> = TypeCmp::with_any();
/// let cmp_ne_ty: TypeCmp<i64, u64> = TypeCmp::with_any();
/// let cmp_eq_ty: TypeCmp<i32, i32> = TypeCmp::Eq(TypeEq::NEW);
/// let cmp_ne_ty: TypeCmp<i64, u64> = TypeCmp::Ne(type_ne!(i64, u64));
///
/// let eq_len: TypeEq<Usize<0>, Usize<0>> = TypeEq::NEW;
/// let ne_len: TypeNe<Usize<1>, Usize<2>> = Usize.equals(Usize).unwrap_ne();
Expand Down
4 changes: 2 additions & 2 deletions src/type_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,11 @@ mod type_eq_ {
///
///
/// fn sum_u32s<T: Clone + Any>(foo: &[T]) -> Option<u32> {
/// downcast_slice::<T, u32>(foo)
/// typecast_slice::<T, u32>(foo)
/// .map(|foo: &[u32]| foo.iter().copied().sum())
/// }
///
/// fn downcast_slice<T: Any, U: Any>(foo: &[T]) -> Option<&[U]> {
/// fn typecast_slice<T: Any, U: Any>(foo: &[T]) -> Option<&[U]> {
/// struct SliceFn;
/// impl<T> typewit::TypeFn<T> for SliceFn {
/// type Output = [T];
Expand Down
6 changes: 5 additions & 1 deletion src/type_ne_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,17 @@ impl<L: ?Sized, R: ?Sized> TypeNe<L, R> {
/// assert!(TypeNe::<u8, u8>::with_any().is_none());
///
/// ```
#[deprecated = concat!(
"fallout of `https://github.com/rust-lang/rust/issues/97156`,",
"`TypeId::of::<L>() != TypeId::of::<R>()` does not imply `L != R`"
)]
pub fn with_any() -> Option<Self>
where
L: Sized + Any,
R: Sized + Any,
{
if TypeId::of::<L>() != TypeId::of::<R>() {
// SAFETY: the two TypeIds compare unequal, so L != R
// SAFETY: unsound for the deprecated reason
unsafe { Some(TypeNe::new_unchecked()) }
} else {
None
Expand Down
24 changes: 14 additions & 10 deletions tests/misc_tests/generic_fns_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use typewit::{
TypeCmp,
TypeEq,
TypeNe,
type_eq,
type_eq, type_ne,
};

use crate::misc_tests::test_utils::assertm;
Expand Down Expand Up @@ -50,9 +50,9 @@ fn zip2_test() {

constness::<u8, u8, bool, u32, u32, u64>(
TypeEq::NEW,
TypeNe::with_any().unwrap(),
TypeCmp::with_any(),
TypeCmp::with_any(),
type_ne!(u8, bool),
TypeCmp::Eq(TypeEq::NEW),
TypeCmp::Ne(type_ne!(u32, u64)),
);
}

Expand Down Expand Up @@ -101,9 +101,9 @@ fn zip3_test() {
constness::<u8, u8, u8, bool, u32, u32, u64>(
TypeEq::NEW,
TypeEq::NEW,
TypeNe::with_any().unwrap(),
TypeCmp::with_any(),
TypeCmp::with_any(),
type_ne!(u8, bool),
TypeCmp::Eq(TypeEq::NEW),
TypeCmp::Ne(type_ne!(u32, u64)),
);
}

Expand All @@ -117,7 +117,11 @@ fn test_zip4() {
let _: TypeCmp<(D, A, B, A), (E, B, A, B)> = zip4(cmp, eq, eq.flip(), eq);
}

with::<u8, u8, bool, u16, u32>(TypeEq::NEW, TypeNe::with_any().unwrap(), TypeCmp::with_any());
with::<u8, u8, bool, u16, u32>(
TypeEq::NEW,
type_ne!(u8, bool),
TypeCmp::Ne(type_ne!(u16, u32)),
);
}

#[test]
Expand All @@ -128,8 +132,8 @@ fn test_in_array() {
};

let eq_ty: TypeEq<i16, i16> = TypeEq::NEW;
let ne_ty: TypeNe<i16, u16> = TypeNe::with_any().unwrap();
let cmp_ty: TypeCmp<i16, u16> = TypeCmp::with_any();
let ne_ty: TypeNe<i16, u16> = type_ne!(i16, u16);
let cmp_ty: TypeCmp<i16, u16> = TypeCmp::Ne(type_ne!(i16, u16));

let eq_len: TypeEq<Usize<0>, Usize<0>> = TypeEq::NEW;
let ne_len: TypeNe<Usize<1>, Usize<2>> = Usize.equals(Usize).unwrap_ne();
Expand Down
Loading

0 comments on commit 2d79ba0

Please sign in to comment.