From: Kent Gibson <warthog618@gmail.com>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: "Linus Walleij" <linus.walleij@linaro.org>,
"Bartosz Golaszewski" <brgl@bgdev.pl>,
"Vincent Guittot" <vincent.guittot@linaro.org>,
linux-gpio@vger.kernel.org,
"Miguel Ojeda" <miguel.ojeda.sandonis@gmail.com>,
"Wedson Almeida Filho" <wedsonaf@gmail.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
stratos-dev@op-lists.linaro.org,
"Gerard Ryan" <g.m0n3y.2503@gmail.com>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
y86-dev <y86-dev@protonmail.com>
Subject: Re: [libgpiod v2][PATCH V8 9/9] bindings: rust: Implement iterator for edge events
Date: Fri, 4 Nov 2022 20:33:03 +0800 [thread overview]
Message-ID: <Y2UGf7UkNuCtjpBN@sol> (raw)
In-Reply-To: <20221104113147.rm6psaajhj73k45k@vireshk-i7>
On Fri, Nov 04, 2022 at 05:01:47PM +0530, Viresh Kumar wrote:
> On 02-11-22, 21:16, Kent Gibson wrote:
> > It is generally frowned upon to patch your own patch within the same
> > series, so drop the Suggested-by and squash this into patch 5.
> > In this instance it is very handy for reviewing though, as the other
> > patches look pretty clean to me...
>
> I kept it separately for exactly this reason, I was planning to merge it
> eventually with the other commits.
>
> > > +pub struct Events<'a> {
> > > + buffer: &'a mut Buffer,
> > > + events: Vec<&'a Event>,
> > > + index: usize,
> > > +}
> > > +
> >
> > Events is pub but not documented.
> >
> > The events attribute is expensive - requiring a dynamic allocation for
> > each snapshot. And you create it unsized and push into it, which could
> > require resizing and reallocation.
> > And it is unnecessary - just have Events iterate over the appropriate
> > indicies and get the ref from the buffer.
>
> I had to do it this way as I wasn't able to get around an error I think. I
> updated the code now based on suggestions, in my v9 branch, and I get it again:
>
> error: lifetime may not live long enough
> --> libgpiod/src/event_buffer.rs:51:9
> |
> 45 | impl<'a> Iterator for Events<'a> {
> | -- lifetime `'a` defined here
> ...
> 48 | fn next(&mut self) -> Option<Self::Item> {
> | - let's call the lifetime of this reference `'1`
> ...
> 51 | event
> | ^^^^^ associated function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'1`
>
> error: could not compile `libgpiod` due to previous error
>
> I will try to fix this on Monday now, unless you have an answer for me by then
> :)
/// Read an event stored in the buffer.
- fn event(&mut self, index: usize) -> Result<&Event> {
+ fn event<'a>(&mut self, index: usize) -> Result<&'a Event> {
if self.events[index].is_null() {
// SAFETY: The `gpiod_edge_event` returned by libgpiod is guaranteed to live as long
// as the `struct Event`.
There are still other things that need to be fixed after that, but that
fixes that particular problem.
Cheers,
Kent.
next prev parent reply other threads:[~2022-11-04 12:33 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-31 11:47 [libgpiod v2][PATCH V8 0/9] bindings: rust: Add libgpiod-sys rust crate Viresh Kumar
2022-10-31 11:47 ` [libgpiod v2][PATCH V8 1/9] " Viresh Kumar
2022-10-31 11:47 ` [libgpiod v2][PATCH V8 2/9] bindings: rust: Add pre generated bindings for libgpiod-sys Viresh Kumar
2022-10-31 11:47 ` [libgpiod v2][PATCH V8 3/9] bindings: rust: Add gpiosim crate Viresh Kumar
2022-10-31 11:47 ` [libgpiod v2][PATCH V8 4/9] bindings: rust: Add pre generated bindings for gpiosim Viresh Kumar
2022-10-31 11:47 ` [libgpiod v2][PATCH V8 5/9] bindings: rust: Add libgpiod crate Viresh Kumar
2022-11-02 13:14 ` Kent Gibson
2022-11-04 5:57 ` Viresh Kumar
2022-10-31 11:47 ` [libgpiod v2][PATCH V8 6/9] bindings: rust: Add examples to " Viresh Kumar
2022-10-31 11:47 ` [libgpiod v2][PATCH V8 7/9] bindings: rust: Add tests for " Viresh Kumar
2022-11-02 13:15 ` Kent Gibson
2022-11-04 5:52 ` Viresh Kumar
2022-10-31 11:47 ` [libgpiod v2][PATCH V8 8/9] bindings: rust: Integrate building of bindings with make Viresh Kumar
2022-10-31 11:47 ` [libgpiod v2][PATCH V8 9/9] bindings: rust: Implement iterator for edge events Viresh Kumar
2022-11-02 13:16 ` Kent Gibson
2022-11-04 11:31 ` Viresh Kumar
2022-11-04 12:33 ` Kent Gibson [this message]
2022-11-05 1:20 ` Kent Gibson
2022-11-07 6:13 ` Viresh Kumar
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=Y2UGf7UkNuCtjpBN@sol \
--to=warthog618@gmail.com \
--cc=alex.bennee@linaro.org \
--cc=alex.gaynor@gmail.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=brgl@bgdev.pl \
--cc=g.m0n3y.2503@gmail.com \
--cc=gary@garyguo.net \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=miguel.ojeda.sandonis@gmail.com \
--cc=stratos-dev@op-lists.linaro.org \
--cc=vincent.guittot@linaro.org \
--cc=viresh.kumar@linaro.org \
--cc=wedsonaf@gmail.com \
--cc=y86-dev@protonmail.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 NNTP newsgroup(s).