Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field offsets #175

Closed
wants to merge 1 commit into from

Conversation

Projects
None yet
5 participants
@Zoxc
Copy link

Zoxc commented Jul 21, 2014

struct FieldOffset<Obj, Field>;
impl FieldOffset<Obj, Field> {
pub fn get(obj: &T) -> &FieldType;

This comment has been minimized.

@huonw

huonw Jul 21, 2014

Member

Where is the FieldType type introduced? (typo?)

This comment has been minimized.

@lilyball

lilyball Jul 22, 2014

Contributor

I'm assuming the Field parameter is supposed to be FieldType.

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.

@huonw

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.

@lilyball

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.

@huonw

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.

@lilyball

This comment has been minimized.

Copy link
Contributor

lilyball commented Jul 22, 2014

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.

@bgamari

This comment has been minimized.

Copy link

bgamari commented Jul 22, 2014

@Zoxc for what it's worth here is a possible implementation of an intrusive linked list without needing field offsets. It does require a helper trait, but I think this trick should work for many cases where field offsets would be useful.

@huonw

This comment has been minimized.

Copy link
Member

huonw commented Jul 22, 2014

BTW, RFCs should not be rebased or amended; any changes should be made with new commits.

@Zoxc

This comment has been minimized.

Copy link
Author

Zoxc commented Jul 29, 2014

This should probably be postponed until #56 or something like that lands in order to provide greater motivation.

@brson

This comment has been minimized.

Copy link
Contributor

brson commented Aug 1, 2014

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.

offsetof is certainly a potentially useful operator, and for that the keyword is already reserved.

Closing. Thank you.

@brson brson closed this Aug 1, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.