Rust-for-linux archive mirror
 help / color / mirror / Atom feed
From: Josh Stone <jistone@redhat.com>
To: Kent Overstreet <kent.overstreet@linux.dev>,
	Thomas Bertschinger <tahbertschinger@gmail.com>
Cc: Ariel Miculas <ariel.miculas@gmail.com>, rust-for-linux@vger.kernel.org
Subject: Re: rust traits in kernel
Date: Fri, 8 Mar 2024 09:43:34 -0800	[thread overview]
Message-ID: <89d92de1-52fd-4336-94e8-14d46adb50e6@redhat.com> (raw)
In-Reply-To: <np7mqkkrnpvi4stflwkrrw7uew4fgkt6iqynmoiirxg4sdsjpj@dwnx334lctpk>

On 3/7/24 6:04 PM, Kent Overstreet wrote:
> IntoIterator isn't the only way of getting an iterator. This comes up
> with vectors as well, where often you want to be able to iterate over a
> vector without consuming it.
> 
> So vectors have a .iter() method that returns an iterator that just
> takes a reference to the original vector. I don't think there's a
> standard trait for this "borrowed iterator" method, but it's a standard
> thing for container objects - that's what we'll want to do here.

There's also `impl<T> IntoIterator for &Vec<T>` that does the same thing
as the slice .iter(), and this lets `for x in &vec` work for borrowed
items. So there's not a separate trait, just IntoIterator taking
ownership of a reference instead of the actual container.


      reply	other threads:[~2024-03-08 17:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <hveywufltgcwqs6gciwuqyse7gv3k6fhvqftnjtc6no76ajdhb@6ro24ggp6qdp>
     [not found] ` <CAPDJoNunCinSA9Y=V5yEiFzTc7QU71Z=XKicJKNCQhDJEm0ROg@mail.gmail.com>
     [not found]   ` <20240308003235.GA66553@fedora-laptop>
     [not found]     ` <eqixbuwkcqmllbkoszgxxkyo6rj2izq3h5c4m7jtehbbyzqyt5@7upygcsju5ge>
     [not found]       ` <20240308014248.GB66553@fedora-laptop>
2024-03-08  2:04         ` rust traits in kernel (was: bcachefs meeting) Kent Overstreet
2024-03-08 17:43           ` Josh Stone [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=89d92de1-52fd-4336-94e8-14d46adb50e6@redhat.com \
    --to=jistone@redhat.com \
    --cc=ariel.miculas@gmail.com \
    --cc=kent.overstreet@linux.dev \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tahbertschinger@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).