macro_rules! share {
($data:expr) => { ... };
}Expand description
Macro for creating ThreadShare with automatic type inference
This macro creates a ThreadShare<T> instance with automatic type inference.
It’s the most commonly used macro for creating thread-safe shared data.
§Syntax
share!(expression)
§Arguments
expression- The data to wrap in ThreadShare
§Returns
A new ThreadShare<T> instance where T is inferred from the expression.
§Example
use thread_share::share;
// Basic types
let counter = share!(0); // ThreadShare<i32>
let message = share!("Hello"); // ThreadShare<&str>
let flag = share!(true); // ThreadShare<bool>
// Complex types
let data = share!(vec![1, 2, 3]); // ThreadShare<Vec<i32>>
// let user = share!(User { id: 1, name: "Alice" }); // ThreadShare<User>
// Expressions
let result = share!(10 + 20); // ThreadShare<i32>
let computed = share!(vec![1, 2, 3].len()); // ThreadShare<usize>§Type Inference
The macro automatically infers the generic type T from the expression:
use thread_share::share;
// No need to specify types explicitly
let counter: thread_share::ThreadShare<i32> = share!(0);
let data: thread_share::ThreadShare<Vec<String>> = share!(vec![String::new()]);