[−][src]Function fuckit::summon_clones
pub fn summon_clones<T: Clone>(value: &T, len: usize) -> &'static mut [T]
Allocates space for a slice of len
clones/copies of value
, which will
never be freed, so they can have unbounded 'static
lifetimes. This
leaks memory.
Example
Returning a reference to a locally-created slice of clones without manually making it owned by some longer-lived value.
fn inner_function() -> &'static mut [Vec<usize>] { let on_stack = vec![1, 2, 3]; let on_heap = fuckit::summon_clones(&on_stack, 32); on_heap } let vs = inner_function(); // Ensure the value was actually cloned: for v in vs.iter() { assert_eq!(*v, vec![1, 2, 3]); } // Ensure the value wasn't just aliased: modifying one vec shouldn't // affect the others: vs[0][0] = 99; vs[1].clear(); assert_eq!(1, vs[2][0]); assert_eq!(1, vs[31][0]);