pbx
pbx is a Rust crate that provides convenient macros for creating various types of boxed and atomic reference-counted values, along with default and zeroed instances.
The crate is named in honor of its most notable member, the Pbx type.
Additionally, this crate can be used as a shorthand to access the following common types: Pin, Arc, Mutex, Rc, RefCell via the following toplevel lib.rs exports:
pub use Pin;
pub use ;
pub use Rc;
pub use RefCell;
If you find yourself using these types frequently, this crate can be used to simplify things:
use *;
Features
- Pbx: A type alias for
Pin<Box<T>>. - Macros: Several macros for creating
Pin<Box<T>>,Arc<Mutex<T>>,Arc<T>, default instances, and zeroed instances.
Usage
Add pbx to your Cargo.toml:
[]
= "0.1.0"
Examples
extern crate pbx;
use *;
Macros
pbx!
Creates a Pin<Box> from a given expression.
let pinned_boxed_value = pbx!;
arcmut!
Creates an Arc<Mutex> from a given expression.
let arc_mutex_value = arcmut!;
arcmut_with!
Creates an Arc<Mutex> with an initializer function.
let arc_mutex_value = arcmut_with!;
arc!
Creates an Arc from a given expression.
let arc_value = arc!;
rc!
Creates an Rc from a given expression.
let rc_value = rc!;
rcmut!
Creates an Rc<RefCell> from a given expression.
let rc_mut_value = rcmut!;
default!
Creates a default instance of a type.
let default_instance: T = default!;
zeroed!
Creates a zeroed instance of a type. This is typically used when interacting with wrappers around C APIs which do not have or need default constructors.
let zeroed_instance: T = zeroed!;
Utilities
pin_box
Converts a Box to a Pbx.
let boxed_value: = Boxnew;
let pinned_boxed_value = pin_box;
pin_arc
Converts an Arc to a Pin<Arc>.
let arc_value: = new;
let pinned_arc_value = pin_arc;
License
This project is licensed under the MIT License.