#[inline]
applies to the caller:
#[inline]
fn foo() {
}
fn bar() {
foo()
}
so an #[inline]
struct should just be a form of reverse monomorphization:
#[inline] struct Foo(...);
struct Bar(Foo);
one way to "desugar" inline structs is like so:
trait Foo {
fn get_field_0();
fn get_field_1();
...
}
impl<T: Foo> T { // this would be "given methods", similar to provided methods but not overridable
...
}
in fact, we'd even argue inline structs should actually use a mix of struct/enum and trait syntax:
trait struct Foo(i32, u64);
trait enum Bar<T> {
Some(T),
None
}
struct Baz(Foo);
fn do_foo<T: Foo>(...) {
}
impl<T: Foo> T {
...
}
this clearly shows the monomorphization cost involved, and is likely easier to deal with in the compiler.
still would prefer to have repr(binned) but this trait-struct-as-inline-struct stuff is also exciting.
(also note the lack of dyn
! this requires 2021 edition obviously.) cc @comex
sorry, we know this one isn't as clear as the OP, but it's mostly a vague idea of how inline types could work. obviously the compiler would implicitly create types and stuff based on these, so something like:
trait struct Foo(u64, u32);
struct Bar(Foo, u32);
fn foo<T: Foo>(x: &mut T) {
}
fn bar(x: &mut Bar) {
foo(&mut x.0);
}
would implicitly create an
struct MutFooInBar<'a> {
a: &'a mut u64,
b: &'a mut u32,
}
and use it for the &mut x.0
.