macro_rules! unsize {
($gc:expr => $ty:ty) => { ... };
}Expand description
Unsizes a Gc or GcWeak pointer.
This macro is a aiscript_arena-specific replacement for the nightly-only CoerceUnsized trait.
§Usage
// Unsizing arrays to slices.
let mut slice;
slice = unsize!(Gc::new(mc, [1, 2]) => [u8]);
assert_eq!(slice.len(), 2);
slice = unsize!(Gc::new(mc, [42; 4]) => [u8]);
assert_eq!(slice.len(), 4);
// Unsizing values to trait objects.
let mut display;
display = unsize!(Gc::new(mc, "Hello world!".to_owned()) => dyn Display);
assert_eq!(display.to_string(), "Hello world!");
display = unsize!(Gc::new(mc, 123456) => dyn Display);
assert_eq!(display.to_string(), "123456");The unsize macro is safe, and will fail to compile when trying to coerce between
incompatible types.
ⓘ
// Error: `Option<char>` doesn't implement `Error`.
let _ = unsize!(Gc::new(mc, Some('💥')) => dyn Error);