try_clone_derive

Crates.iotry_clone_derive
lib.rstry_clone_derive
version0.1.1
sourcesrc
created_at2019-10-28 12:38:02.601269
updated_at2020-06-20 21:55:21.37417
descriptiona crate wich add a derive TryClone macro for the TryClone Trait of the fallible_allocation crate
homepage
repositoryhttps://github.com/vcombey/try_clone_derive.git
max_upload_size
id176367
size21,194
vcombey (vcombey)

documentation

README

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.

Commit count: 7

cargo fmt