Crates.io | to_that |
lib.rs | to_that |
version | 1.0.1 |
source | src |
created_at | 2023-10-27 16:19:08.394833 |
updated_at | 2023-10-27 16:25:15.051143 |
description | Declarative compile safe explict type conversion. Useful for chaining. |
homepage | |
repository | https://github.com/mcmah309/to_that |
max_upload_size | |
id | 1016183 |
size | 3,382 |
Declarative compile safe explict type conversion. Useful for chaining.
For
#[derive(Debug, PartialEq)]
struct A(i32);
#[derive(Debug, PartialEq)]
struct B(i32);
impl From<A> for B {
fn from(a: A) -> Self {
B(a.0)
}
}
Instead of
fn main() {
let result = B::from(A(1));
assert_eq!(result, B(1));
}
You can now do
fn main() {
let result = A(1).to::<B>();
assert_eq!(result, B(1));
}