#fallible #collections #clone #try-clone

macro try_clone_derive

a crate wich add a derive TryClone macro for the TryClone Trait of the fallible_allocation crate

2 releases

0.1.1 Jun 20, 2020
0.1.0 Oct 28, 2019

#1254 in Rust patterns

MIT/Apache

8KB
81 lines

Try Clone Derive.rs

A crate wich add a derive TryClone macro for the TryClone Trait of the fallible_allocation crate

Limitation

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 !

Getting Started

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.

Example

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);
}

License

Licensed under either of

at your option.

Contribution

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.

Dependencies

~1.1–1.5MB
~33K SLoC