transfer 0.1.0

Crate that exposes a Transfer trait, that is to move what Clone is to copy
Documentation
  • Coverage
  • 25%
    2 out of 8 items documented0 out of 6 items with examples
  • Size
  • Source code size: 22.42 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.49 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • dureuill/transfer
    12 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • dureuill

Transfer is to move what clone is to copy

Note: This crate, as well as stackpin is very much a work in progress, and is published in the hope that it will be of interest for further work.

The Transfer trait executes user code to take a value from an unmovable instance of a struct to another instance.

In this way, it is similar to the Clone trait, that allows to execute user code to clone a value that is not copiable.

The Transfer trait is also comparable to the move constructor of C++.

Hold on, what is an unmovable struct?

Rust does not natively expose the concept of "unmovable types". However, thanks to Pin and unsafe, it is possible to express this concept in the type system. Transfer leverages the stackpin crate (by the same author) to build type safe abstractions for Unmovable types.

Examples

  • The unit tests for Transfer demonstrate a SecretU64 type, that attempt to erase itself securely when it gets out of scope.
  • An example for Transfer is DynRef, a type of reference that uses an external Lifetime struct to represent the lifetime of DynRef.