Crate specializer

Source
Expand description

Limited safe specialization on stable Rust with builder-like pattern

§Types of Specialization

There are two types of specialization:

  • Specializing on types (example: special behavior for a generic when the generic type is Arc<str> or some other type) - what’s implemented in this crate
  • Specializing on traits (example: special behavior if the generic type implements ToString or some other trait) - requires nightly specialization feature

§Getting Started

For the simplest example see Specializer::specialize_param().

The other types may be required depending on your use case:

AsyncTakesReturnsType
FalseOwnedOwnedSpecializer
FalseOwnedBorrowedSpecializerBorrowedReturn
FalseBorrowedOwnedSpecializerBorrowedParam
FalseBorrowedBorrowedSpecializerBorrowed
TrueOwnedOwnedAsyncSpecializer
TrueOwnedBorrowedAsyncSpecializerBorrowedReturn
TrueBorrowedOwnedAsyncSpecializerBorrowedParam
TrueBorrowedBorrowedAsyncSpecializerBorrowed

§Borrowing

You can specialize on borrowed types using the *SpecializerBorrowed* specializers as long as the borrowed types implement CastIdentityBorrowed, which is automatically implemented for &T and &mut T, where T: 'static.

Structs§

AsyncSpecializer
Async specialized behavior runner (Owned -> Owned)
AsyncSpecializerBorrowed
Async specialized behavior runner (Borrowed -> Borrowed)
AsyncSpecializerBorrowedParam
Async specialized behavior runner (Borrowed -> Owned)
AsyncSpecializerBorrowedReturn
Async specialized behavior runner (Owned -> Borrowed)
Specializer
Specialized behavior runner (Owned -> Owned)
SpecializerBorrowed
Specialized behavior runner (Borrowed -> Borrowed)
SpecializerBorrowedParam
Specialized behavior runner (Borrowed -> Owned)
SpecializerBorrowedReturn
Specialized behavior runner (Owned -> Borrowed)

Traits§

CastIdentityBorrowed
Identity cast on a borrowed type

Functions§

cast_identity
Attempt to cast owned T to U.
cast_identity_borrowed
Attempt to cast borrowed T to U.
cast_identity_mut
Attempt to cast &mut T to &mut U.
cast_identity_ref
Attempt to cast &T to &U.