map_box_from 0.1.0

Adds `Box`-ed versions of `From` and `Into` traits - allowing implementations for unsized type parameters and following looser guidelines.
Documentation
  • Coverage
  • 100%
    6 out of 6 items documented1 out of 4 items with examples
  • Size
  • Source code size: 6.8 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.2 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ArsenalAlex108

map_box_from

Adds [Box]-ed versions of [From] and [Into] traits - allowing implementations for unsized type parameters and following looser guidelines.

Reasoning

Due to the invasiveness of the identity conversion implementation impl<T> From<T> for T and the lack of negative trait implementation, some conversion implementations like impl<T> From<T> for Unit or impl<T> From<T> for NewType<T> are currently impossible in stable Rust. Compromises will have to made to specify to the compiler that Self is not part of T, using one of the following methods:

  • Place an arbitrary bound on T and make Self not satisfy that bound, i.e. using a widely implemented trait like Debug or [Unpin] and unimplement them on Self
  • Define bespoke traits fitting the usecase

This crate chooses the second method and provide MapBoxFrom and MapBoxInto traits that instead operates on [Box] to allow the use of unsized type parameters. While this crate maps all existing [Into] implementations into MapBoxFrom implementations, unsized type parameters are untouched and users are free to add new blanket implementations while avoiding conflict with blanket implemetations in [Sized] land.

Note: TryMapBoxFrom and TryMapBoxInto have not been added due to some considerations about how their blanket implementations should be added.