-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
future: provide infrastructure to print shared-ownership types in a way that reflects the shared graph structure #6187
Comments
(bug triage) Still open. Far-future seems right. |
Visiting for triage. cc @alexcrichton |
This would definitely be pretty cool, and the relevant stuff you'd have to change would be mostly in repr/reflect. The ifmt changes don't look like they'll conflict with this other than just changing what the output of |
As a minor consideration, this means that |
Triage, no change that I know of. |
I wonder what @aturon thinks about this in the light of the new Show/String changes |
This was originally talking about reflection infrastructure which has since been removed. I think it should be moved to the RFCs issue tracker as a wishlist item. |
I'm pulling a massive triage effort to get us ready for 1.0. As part of this, I'm moving stuff that's wishlist-like to the RFCs repo, as that's where major new things should get discussed/prioritized. This issue has been moved to the RFCs repo: rust-lang/rfcs#781 |
Old title: future: extend %? printing to reflect shared graph structure of @-referenced objects
Previously this bug was just covering
@mut T
(nowGc<RefCell<T>>
) and described overriding the reflection-based{:?}
printer. Old text below.Some types like
Rc
andGc
provide the ability to share state, it would be neat if we could print values that reflected this (see below for some examples). Providing a general interface that types can use to get equivalent printing would be optimal, but, if necessary, we can restrict it to just being implemented forRc
andGc
(although of course others would be welcome to borrow/adjust the implementation for their use case).This may end up requiring some special formatting traits (or something like
~[Rc<T>]
will not be printed properly), and so may be better suited to an external library.Old text.
Discussions on Issue #3768 made me wonder about how we might extend Rust to precisely (and succinctly) print out structure with shared state.
Consider for example this code:
the print out you get is:
It might be nice if we extended the notation for @-references so that if there is shared substructure, it is annotated to reflect the shared objects' identities. As inspired by say Lisp/Scheme, many dialects of which use
#n=<foo>
as a binder and#n#
as a reference, we might print:Caveat: I'm not wedded to any particular notation, and perhaps this job is better left to an end-user library to handle, rather than coupling it to
%?
.But since some people do want
%?
to be robust in the face of cycles, we might consider also keeping it honest? Just a thought.The text was updated successfully, but these errors were encountered: