Crates.io | arc-trait |
lib.rs | arc-trait |
version | 0.1.2 |
source | src |
created_at | 2024-07-22 10:06:31.830918 |
updated_at | 2024-07-22 11:50:10.619291 |
description | Automagically implement any trait for Arc |
homepage | |
repository | |
max_upload_size | |
id | 1311023 |
size | 8,137 |
arc_trait
is a procedural macro that simplifies the process of implementing traits for std::sync::Arc<T>
. By
applying this macro to a trait, you enable Arc<T>
to implement it whenever the inner type T
implements the trait,
saving you from writing repetitive boilerplate code.
std::sync::Arc<T>
types.Add this to your Cargo.toml
:
[dependencies]
arc_trait = "0.1.0"
And this to your crate root:
extern crate arc_trait;
use arc_trait::arc_trait;
Apply the arc_trait attribute to your traits as shown in the example:
extern crate arc_trait;
use arc_trait::arc_trait;
use std::sync::Arc;
#[arc_trait]
trait ExampleTrait {
fn example_method(&self, value: i32) -> i32;
}
struct Example;
impl ExampleTrait for Example {
fn example_method(&self, value: i32) -> i32 {
value + 1
}
}
fn main() {
let example = Arc::new(Example);
assert_eq!(example.example_method(1), 2);
}
arc_trait works by:
std::sync::Arc<T>
that forwards method calls to the inner value
wrapped by the Arc
.Contributions are welcome! Feel free to open issues or submit pull requests on GitHub.
This project is licensed under the MIT License. See the LICENSE file for details.