I'm trying to write a Rust function that casts an input from one lifetime constraint to a same-typed output with a global lifetime constraint (conceptually something like unsafe fn foo<'a, T1, T2>(x: T1) -> T2 where T1: 'a, T2 = T1 + 'static
), but I can't quite figure out how to write it without adding indirection layers like Box
. Any ideas?
More generally, I'm trying to implement an unsafe thread::scoped
in terms of mem::transmute
and thread::spawn
. spawn
requires 'static
bounds on its T
and F
parameters, but scoped
does/should not.
unsafe fn foo<'a, T>(x: T + 'a) -> T + 'static
doesn’t make sense—it’s not syntactically valid. What are you actually writing? – Chris Morganmem::transmute
. – bfopsBox<Any + 'static>
? Those only make sense for trait objects. Or do you mean bounds such asfn no_borrows<T: 'static>(x: T) -> T { x }
? – user395760T2
to exist,T1
must be'static
already. What you seem to be trying to implement is flatly impossible and always will be. – Chris Morgan