linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kent Gibson <warthog618@gmail.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: "Viresh Kumar" <viresh.kumar@linaro.org>,
	"Miguel Ojeda" <miguel.ojeda.sandonis@gmail.com>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"Vincent Guittot" <vincent.guittot@linaro.org>,
	linux-gpio@vger.kernel.org,
	"Alex Bennée" <alex.bennee@linaro.org>,
	stratos-dev@op-lists.linaro.org,
	"Gerard Ryan" <g.m0n3y.2503@gmail.com>
Subject: Re: [PATCH V6 3/8] libgpiod: Add rust wrapper crate
Date: Sat, 15 Oct 2022 00:06:35 +0800	[thread overview]
Message-ID: <Y0mJC8lVM/cgBLyi@sol> (raw)
In-Reply-To: <CAMRc=Mc5qVJfcPoVit8zgnoAPKqWY3qb1MQwtfP7FNJ53O=UjA@mail.gmail.com>

On Fri, Oct 14, 2022 at 04:25:31PM +0200, Bartosz Golaszewski wrote:
> On Fri, Oct 14, 2022 at 11:57 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
> >
> > On 14-10-22, 11:45, Bartosz Golaszewski wrote:
> > > Maybe also add chained mutators everywhere? To be able to do
> > > settings.set_direction().set_edge() etc.?
> >
> > Based on Kent's suggestion earlier, what I have implemented is
> > set_prop(), to which one can pass all settings and it will apply them
> > in a loop.
> >
> >     pub fn set_prop(&mut self, values: &[SettingVal]) -> Result<()> {
> >         for value in values {
> >             match value {
> >                 SettingVal::Direction(val) => self.set_direction(*val)?,
> >                 SettingVal::EdgeDetection(val) => self.set_edge_detection(*val)?,
> >                 SettingVal::Bias(val) => self.set_bias(*val)?,
> >                 SettingVal::Drive(val) => self.set_drive(*val)?,
> >                 SettingVal::ActiveLow(val) => self.set_active_low(*val),
> >                 SettingVal::DebouncePeriod(val) => self.set_debounce_period(*val),
> >                 SettingVal::EventClock(val) => self.set_event_clock(*val)?,
> >                 SettingVal::OutputValue(val) => self.set_output_value(*val)?,
> >             }
> >         }
> >
> >         Ok(())
> >     }
> >
> > I think that replaces the need of nested ones ? And if we want to add
> > those later, we can always come back and add them. But I am not sure
> > it would be required.
> >
> 
> I cannot find Kent's comment on that - what was the reasoning behind this?
> 

The comment was:

    Add a Setting enum that has a variant for each setting.
    Then you only need 3 mutators total.
    And the user can define configs as a list of Settings.
    So perhaps the mutators should accept &[Setting].
    And &[offsets] rather than just offset.

    Similarly, gets can be consolidated into:

      get_prop_offset(self, offset, SettingKind) -> Result<Setting>

    and
      get_prop_default(self, SettingKind) -> Result<Setting>

    (simplified signatures)


Prior to the line_settings change there was a veritable forest of
mutators, so the idea was to consolidate them where possible, cos in Rust
you can.  But behind the scenes the implementation is just fanning them
out again, so I'm not sure I see the benefit if that is the case.

If the mutators for each field still exist they may as well be pub.

And they should return Result<&mut Self> so they can be chained, as you
suggest.

Wrt the values param (which I would prefer was called props), the idea
was that the config could be built and passed around as pure Rust
objects.  The set_prop() applied that list to the C line config, at the
time using one of the default/offset/subset mutators.  So it decoupled
the settings from the scope they were to be applied to.  Not such an
issue now - the scope is always line.
Might still be useful, might not.

> > > And I would still love a thorough API review from someone who actually
> > > knows rust too. :(
> >
> > Well, Kent did a very good job earlier. I am not sure if he has extra
> > cycles to review this once again, though not a lot has changed since
> > last time.
> >
> 
> Yeah sorry Kent, I forgot we're at v6 already and you did review the
> previous iterations. :)
> 

My review was of v4.  Things have changed a bit since then.
And I agree with your original point - it would be good to get a review
from someone that actually uses Rust in anger - I only toy with it.

Cheers,
Kent.

  reply	other threads:[~2022-10-14 16:06 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-26 11:08 [PATCH V6 0/8] libgpiod: Add Rust bindings Viresh Kumar
2022-09-26 11:08 ` [PATCH V6 1/8] libgpiod: Add libgpiod-sys rust crate Viresh Kumar
2022-09-26 11:08 ` [PATCH V6 2/8] libgpiod-sys: Add pre generated rust bindings Viresh Kumar
2022-09-26 11:08 ` [PATCH V6 3/8] libgpiod: Add rust wrapper crate Viresh Kumar
2022-09-26 13:29   ` Bartosz Golaszewski
2022-09-26 15:26     ` Viresh Kumar
2022-09-27 13:18       ` Bartosz Golaszewski
2022-09-27 13:57         ` Viresh Kumar
2022-09-27 15:25           ` Bartosz Golaszewski
2022-09-28 11:10             ` Viresh Kumar
2022-09-28 12:20               ` Bartosz Golaszewski
2022-09-28 15:17                 ` Viresh Kumar
2022-09-28 17:54                   ` Bartosz Golaszewski
2022-09-29  6:54                     ` Viresh Kumar
2022-09-29  7:37                       ` Bartosz Golaszewski
2022-09-29  8:58                         ` Viresh Kumar
2022-09-29 11:16                           ` Bartosz Golaszewski
2022-09-29 11:43                         ` Kent Gibson
2022-09-29 13:55                     ` Miguel Ojeda
2022-10-11  4:16                       ` Viresh Kumar
2022-10-11  4:25                         ` Kent Gibson
2022-10-11  4:37                           ` Viresh Kumar
2022-10-11  4:46                             ` Viresh Kumar
2022-10-13  6:12                         ` Viresh Kumar
2022-10-14  9:45                           ` Bartosz Golaszewski
2022-10-14  9:57                             ` Viresh Kumar
2022-10-14 14:25                               ` Bartosz Golaszewski
2022-10-14 16:06                                 ` Kent Gibson [this message]
2022-10-17 11:26                                   ` Viresh Kumar
2022-10-17 11:34                                     ` Kent Gibson
2022-10-17 11:37                                       ` Viresh Kumar
2022-09-26 11:08 ` [PATCH V6 4/8] libgpiod: Add rust examples Viresh Kumar
2022-09-26 11:08 ` [PATCH V6 5/8] libgpiod: Add gpiosim rust crate Viresh Kumar
2022-09-26 11:08 ` [PATCH V6 6/8] gpiosim: Add pre generated rust bindings Viresh Kumar
2022-09-26 11:08 ` [PATCH V6 7/8] libgpiod: Add rust tests Viresh Kumar
2022-09-26 11:08 ` [PATCH V6 8/8] libgpiod: Integrate building of rust bindings with make Viresh Kumar
2022-09-26 15:57 ` [PATCH V6 0/8] libgpiod: Add Rust bindings 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=Y0mJC8lVM/cgBLyi@sol \
    --to=warthog618@gmail.com \
    --cc=alex.bennee@linaro.org \
    --cc=brgl@bgdev.pl \
    --cc=g.m0n3y.2503@gmail.com \
    --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 \
    /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).