Crates.io | try_clone_derive |
lib.rs | try_clone_derive |
version | 0.1.1 |
source | src |
created_at | 2019-10-28 12:38:02.601269 |
updated_at | 2020-06-20 21:55:21.37417 |
description | a crate wich add a derive TryClone macro for the TryClone Trait of the fallible_allocation crate |
homepage | |
repository | https://github.com/vcombey/try_clone_derive.git |
max_upload_size | |
id | 176367 |
size | 21,194 |
A crate wich add a derive TryClone macro for the TryClone Trait of the fallible_allocation crate
This is my first proc macro, the code is very dummy and works only on the simplest cases, without Generic types, etc But contributions are welcome !
try clone derive is available on crates.io. It is recommended to look there for the newest released version, as well as links to the newest builds of the docs.
At the point of the last update of this README, the latest published version could be used like this:
Add the following dependency to your Cargo manifest...
[dependencies]
try_clone_derive = "0.1.1"
...and see the docs for how to use it.
use fallible_collections::TryClone;
use try_clone_derive::TryClone;
#[derive(Debug, TryClone)]
pub struct MyStruct{
a: u32,
b: Vec<u8>,
c: Arc<u8>,
}
fn main() {
// this crate an Ordinary box but return an error on allocation failure
let my_struct = MyStruct {
a: 42,
b: vec![42; 42],
c: Arc::new(42),
};
assert_eq!(my_struct.try_clone().unwrap(), my_struct);
}
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.