-
-
Notifications
You must be signed in to change notification settings - Fork 58
Closed
Labels
Description
rust-lang/rust#15191 (comment)
To fix this issue and make Rust-Graphics work with Rust nightlies, the Field is redesigned.
- This introduces an assumption that all fields are
Copykind - The emitted assembly seems to be equivalent Check if compiler optimizes fields by value #555
- Relies on the compiler to optimize sequential copy-by-value instead of reference to stack value
- The external look-and-feel of the API remains unchanged
- No extra generic constraints are required on the impls
- Can be changed back when Rust solves the issue above - within one day of work
- Side effect is that
let a = b.foo(...).bar(...);is allowed. Will not break future API to change back if the better temporary lifetime RFC is implemented RFC: Better temporary lifetimes (so e.g. .as_slice() works) rust-lang/rfcs#66
The old Field:
pub enum Field<'a, T> {
Value(T),
Borrowed(&'a T),
}
impl<'a, T> Field<'a, T> {
#[inline(always)]
pub fn get(&'a self) -> &'a T {
match *self {
Value(val) => val,
}
}
}The new Field:
pub enum Field<T> {
Value(T),
}
impl<T: Copy> Field<T> {
#[inline(always)]
pub fn get(&self) -> T {
match *self {
Value(val) => val,
}
}
}