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:
Async | Takes | Returns | Type |
---|---|---|---|
False | Owned | Owned | Specializer |
False | Owned | Borrowed | SpecializerBorrowedReturn |
False | Borrowed | Owned | SpecializerBorrowedParam |
False | Borrowed | Borrowed | SpecializerBorrowed |
True | Owned | Owned | AsyncSpecializer |
True | Owned | Borrowed | AsyncSpecializerBorrowedReturn |
True | Borrowed | Owned | AsyncSpecializerBorrowedParam |
True | Borrowed | Borrowed | AsyncSpecializerBorrowed |
§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§
- Async
Specializer - Async specialized behavior runner (Owned -> Owned)
- Async
Specializer Borrowed - Async specialized behavior runner (Borrowed -> Borrowed)
- Async
Specializer Borrowed Param - Async specialized behavior runner (Borrowed -> Owned)
- Async
Specializer Borrowed Return - Async specialized behavior runner (Owned -> Borrowed)
- Specializer
- Specialized behavior runner (Owned -> Owned)
- Specializer
Borrowed - Specialized behavior runner (Borrowed -> Borrowed)
- Specializer
Borrowed Param - Specialized behavior runner (Borrowed -> Owned)
- Specializer
Borrowed Return - Specialized behavior runner (Owned -> Borrowed)
Traits§
- Cast
Identity Borrowed - Identity cast on a borrowed type
Functions§
- cast_
identity - Attempt to cast owned
T
toU
. - cast_
identity_ borrowed - Attempt to cast borrowed
T
toU
. - cast_
identity_ mut - Attempt to cast
&mut T
to&mut U
. - cast_
identity_ ref - Attempt to cast
&T
to&U
.