From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Received: by 2002:a6b:bc06:: with SMTP id m6mr2010610iof.18.1553734110796; Wed, 27 Mar 2019 17:48:30 -0700 (PDT) X-Received: by 2002:a9d:7602:: with SMTP id k2mr28868419otl.357.1553734110526; Wed, 27 Mar 2019 17:48:30 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.uzoreto.com!feeder1.cambriumusenet.nl!feed.tweak.nl!209.85.166.215.MISMATCH!78no95003itl.0!news-out.google.com!l81ni79itl.0!nntp.google.com!136no95096itk.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 27 Mar 2019 17:48:30 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=70.109.61.2; posting-account=QF6XPQoAAABce2NyPxxDAaKdAkN6RgAf NNTP-Posting-Host: 70.109.61.2 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <5869cc6b-dd17-47dd-bdfb-f6987cff6402@googlegroups.com> Subject: Re: Intervention needed? From: Jere Injection-Date: Thu, 28 Mar 2019 00:48:30 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader01.eternal-september.org comp.lang.ada:55983 Date: 2019-03-27T17:48:30-07:00 List-Id: On Monday, March 25, 2019 at 3:14:38 PM UTC-4, Randy Brukardt wrote: > "Jere" wrote in message > > On Saturday, March 23, 2019 at 3:53:34 AM UTC-4, Randy Brukardt wrote: > ... > > If you were instead referring to indexing the container, for things > > like vector, Rust looks to see if the container implements the Index > > trait, and, if so, allows for the user to use the index operation > > on the container. It's very similar to making a cursor and setting the > > variable_indexing aspect and constant_indexing aspect, except rust doesn't > > expose the underlying equivalent cursor type. So you either work > > with Indexes or Iterators depending on your need. > > I was specifically asking about the common need to have connections between > containers. It's not likely that a single container is all one needs to > solve a problem, so one needs ways to refer to elements of one container > from another. > > For instance, one might need a index for another container. (For instance, > to allow lookups by some internal characteristic.) If the main container is > structured (as in an internal representation of HTML or XML, or a compiler > symbol table), the index has to be a separate container. Ada provides > cursors to represent those sorts of interconnections. How does Rust do it?? > (If it does it at all.) > > This sort of thing comes up any time that one has two separate data > structures that are inter-related. Sometimes you can use composition for > combining structures (and that's preferable when possible), but if there are > potentially multiple references to a single item or if the element is just > part of a larger data structure, composition doesn't work and some sort of > reference is needed. > > Randy. > > P.S. Sorry about breaking the thread; the message wouldn't post because of > header limits (too many replies). I generally don't come across situations that require this, so I don't know how useful my answer will be. Plus I've only programmed in Rust off and on for fun on some side projects. I mostly do either C or Ada as the platform allows. Generally, Rust looks at potential memory erroneous access as a 100% no no, so the same method used in Ada with Cursors wouldn't be allowed. They have really really low chance, but there still is a chance. From what I could find on the topic, the general first suggestion is to rethink your approach and pick a better solution that doesn't involve potentially dangling references (similar to the mentality we often suggest to new comers trying to port ideas from C/C++ into Ada directly without considering the Ada way). Aside from that, if you can't approach it very differently, there are different options available. For more temporary type situations (say wanting to delete a subset of elements from a container), they provide various map(), filter(), and collect() operations that interact with the iterators to get the configuration you want. For more long term containers (This sounds more like what you are asking for), the methods I came across were to take a step back and determine which of the 2 (or more) containers really needs to be the owner of the data (it isn't always the one that common sense initially indicates), have it own the data using an owning reference, and have the other containers use non-owning references (which you can promote to owning references temporarily as needed). That would be more along the lines of the idiomatic "safe" approach. This allows Rust to keep track of who can use the reference when (using temporal rules) and doesn't involve any unsafe code. That isn't a silver bullet for all situations though. In some cases, you might have to use one standard container and another that you make from scratch and have the standard container integrate into the other one under the hood. I'm not a very seasoned Rust programmer, so I am probably missing some other solutions. I'm more comfortable in Ada and like to use it more anyways. I'm also sure you could come up with some situation where the above suggestions wouldn't work. I don't generally have a better answer due to lack of experience. And the answer may at some point indeed involve unsafe programming. You are still required to maintain the 100% memory safety, even in the case of using the "unsafe" keyword, so something too similar to the Ada cursors method in its current form would not be allowed. Sorry for the long wait on the reply. I wanted to do some test programming to make sure the stuff I mentioned above would actually work and also do some research on it since, in my problem domains, I don't ever run into situations where container shadowing/interacting is required.