3 ms·
> - Raw-pointer equivalent to lifetime parameters (`GenericStruct<*>`, converts `&'a T` into `*const T` and `&'a mut T` into `*mut T`) How would that work? Ref
by proto_lambda 4y ago
> - Raw-pointer equivalent to lifetime parameters (`GenericStruct<*>`, converts `&'a T` into `*const T` and `&'a mut T` into `*mut T`)
How would that work? References and pointers are fundamentally different types, and the primary operation on references (`Deref`) isn't available for pointers. Any methods implemented on the struct wouldn't be able to do anything with the "reference" field, since it might actually be a pointer instead - it would be like having a `struct Foo<T>(Vec<T>);`, and then specifying `Foo<boxed T>` (imaginary syntax) if you actually want a `Box<T>` instead of a `Vec<T>`. You can't just treat a `Box` like a `Vec` (or a pointer like a reference).
> - `impl Trait` for associated types. This lets you workaround async trait functions without boxing the returned futures and also return anonymous closures from traits
You're probably already aware, but for the bystanders, that seems to be close to happening: https://github.com/rust-lang/rust/issues/63063 https://github.com/rust-lang/rust/issues/63063
> - Mutability variance: e.g. write `fn index<&a>(&a self, idx: Idx) -> &a T`, instead of needing to write `fn index(&self, idx: Idx) -> &T` and `fn index_mut(&mut self, idx: Idx) -> &mut T`)
I think that's something the Keyword Generics (aka "totally not effects") Initiative[1] is looking into.
> - Built-in unit types (e.g. write `#[unit(ms)] pub struct Milliseconds(usize)`, and then you can write `128ms` => `Milliseconds(128)`)
Making sure that doesn't turn into a name collision nightmare would probably needs some work. It might also make it very hard to figure out what type you're actually dealing with just by looking at such a number. The current solution to this problem, defining an extension trait on integers, produces only moderately more verbose code, with the benefit of not requiring any additional syntax: `128.ms()`.
[1]: https://blog.rust-lang.org/inside-rust/2022/07/27/keyword-generics.html https://blog.rust-lang.org/inside-rust/2022/07/27/keyword-ge...