Crates.io | transfer |
lib.rs | transfer |
version | 0.1.0 |
source | src |
created_at | 2019-10-13 20:31:03.665166 |
updated_at | 2019-10-13 20:31:03.665166 |
description | Crate that exposes a Transfer trait, that is to move what Clone is to copy |
homepage | |
repository | https://github.com/dureuill/transfer |
max_upload_size | |
id | 172280 |
size | 22,951 |
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++.
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.
Transfer
demonstrate a SecretU64
type, that attempt to erase itself securely when it gets out of scope.Transfer
is DynRef
, a type of reference that uses an external Lifetime
struct to represent the lifetime of DynRef
.