You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The main point of the intrusive examples is as a teaching tool. That means that they should have as many bits added to them to them to make understanding and debugging as easy as possible for people learning what's going on. So, develop nice debug output for {:#?}. E.g., the singly-linked list might output an ordered list that includes the pointer information, trees might have tree output (using the unicode tree characters to make it obvious that its a tree), etc.
The tricky part will be when collections are composed into new, higher-level collections. E.g., the doubly-linked list might present slightly differently than the singly-linked list, or when a tree and a list are composed a different form might be needed. Need to think about this more.
Just one note: This may be unsafe because it may require dereferencing next or parent pointers. Even though this is meant to be a learning resource I think we should still add this, but with big bold letters that it may be unsafe (if that does happen to be the case). If you find a nice way to safely do this, that's even better!
You're right! Actually, I think that all of the docs should have a section about safety, to explain why something is safe or unsafe. That also implies that deriving these traits is actually a bad idea... unless there is a way of adding docs for derived traits???
The derives are safe, because they only print out the pointers without dereferencing them (which is safe), and pointer comparison is well defined in Rust.
Yes, but, walking the tree (or the list) is unsafe. So the Debug implementation prints out a complete list by walking the pointers, then Debug becomes unsafe to call.
The main point of the intrusive examples is as a teaching tool. That means that they should have as many bits added to them to them to make understanding and debugging as easy as possible for people learning what's going on. So, develop nice debug output for
{:#?}
. E.g., the singly-linked list might output an ordered list that includes the pointer information, trees might have tree output (using the unicode tree characters to make it obvious that its a tree), etc.The tricky part will be when collections are composed into new, higher-level collections. E.g., the doubly-linked list might present slightly differently than the singly-linked list, or when a tree and a list are composed a different form might be needed. Need to think about this more.
Originally posted by @ckaran in #54 (comment)
The text was updated successfully, but these errors were encountered: