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

Make pretty-printed debug output of the basic types #58

Open
ckaran opened this issue Feb 8, 2021 · 4 comments
Open

Make pretty-printed debug output of the basic types #58

ckaran opened this issue Feb 8, 2021 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@ckaran
Copy link
Collaborator

ckaran commented Feb 8, 2021

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)

@ckaran ckaran self-assigned this Feb 8, 2021
@ckaran ckaran added the enhancement New feature or request label Feb 8, 2021
@RustyYato
Copy link
Owner

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!

@ckaran
Copy link
Collaborator Author

ckaran commented Feb 8, 2021

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???

@RustyYato
Copy link
Owner

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.

@ckaran
Copy link
Collaborator Author

ckaran commented Feb 8, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants