Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upField offsets #175
Conversation
huonw
reviewed
Jul 21, 2014
| struct FieldOffset<Obj, Field>; | ||
| impl FieldOffset<Obj, Field> { | ||
| pub fn get(obj: &T) -> &FieldType; |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
huonw
reviewed
Jul 21, 2014
| fn main() { | ||
| let obj = Object { list_a: ListData::new(), list_b: ListData::new() } | ||
| let mut a = List::new(offsetof Object.list_a); |
This comment has been minimized.
This comment has been minimized.
huonw
Jul 21, 2014
Member
I don't understand this example. What is new doing with an FieldOffset object, and how does add work?
Can't this currently be achieved equally well with
let mut a = List::new();
let mut b = List::new();
a.add(&obj.list_a);
b.add(&obj.list_b);?
This comment has been minimized.
This comment has been minimized.
lilyball
Jul 22, 2014
Contributor
My understanding is @Zoxc's primary motivation here is to be able to build a linked list using internal storage instead of the more common external storage. The need for field offsets is so that way a single type can participate in multiple lists simultaneously (by providing multiple node-ptr fields).
This comment has been minimized.
This comment has been minimized.
huonw
Jul 22, 2014
Member
Ah, so this is using the list_... fields as the backing pointers/information for the linked lists. This example would be very very much improved with more explanation.
This comment has been minimized.
This comment has been minimized.
|
I just wrote a long comment on #174 about associated values in conjunction with field offsets that I think provides a potentially-compelling reason to have field offsets. |
This comment has been minimized.
This comment has been minimized.
bgamari
commented
Jul 22, 2014
This comment has been minimized.
This comment has been minimized.
|
BTW, RFCs should not be rebased or amended; any changes should be made with new commits. |
This comment has been minimized.
This comment has been minimized.
|
This should probably be postponed until #56 or something like that lands in order to provide greater motivation. |
This comment has been minimized.
This comment has been minimized.
|
I believe that the broad goal here is to provide better support for 'intrusive' data structures, which Rust is currently weak at. It's not clear that this is the design to solve that problem, and @pcwalton has some ideas for designing intrusive data structures without changing the language.
Closing. Thank you. |
Zoxc commentedJul 21, 2014
Rendered view