Re: [PATCH V2 2/4] libgpiod: Add rust wrappers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Dec 16, 2021 at 2:59 PM Bartosz Golaszewski <brgl@xxxxxxxx> wrote:
>
> The line from one of the examples: 'use libgpiod::chip::GpiodChip;'
> looks like it has a lot of redundancy in it. How about calling the
> crate gpiod and dropping the chip package entirely? Basically follow
> what C++ and python bindings do by having `use gpiod::Chip` etc.?

I agree on avoiding redundancy in names where possible (in particular,
the `Gpiod` in `GpiodChip` does not buy much); however, note that
modules in Rust are used a bit differently from C++ namespaces, so I
think it would be a bad idea to drop the modules.

For instance, in Rust, one can be fairly liberal with `use`, while in
C++ one has to worry about ADL and avoid them in global scope in
headers. More importantly, Rust modules are used for encapsulation,
while in C++ namespaces not really (except for the anonymous case or
the """internal""" namespace hack in headers) and in Python privacy is
even weaker. In particular, in Rust one can give each item (including
free functions, variables, etc. not just types) inside a module
different privacy, and importantly, they get special access privileges
within their module.

So while in C++ is indeed fairly typical (though not universal, e.g.
`boost::asio::ip::tcp::socket` comes to mind) to have a flatter layout
with something like `library::Type` with privacy within the `Type` and
hiding things in different TUs; in Rust it is fairly common to have a
`library::module::Item` layout (e.g. `std::vec::Vec` from the standard
library), where one puts everything related to the "module" concept
inside that module.

In any case, one can also re-export things more conveniently for
users, so that is an option too.

> Does it have to be an Error? It's pretty normal for an operation to
> time out, no?

Hmm... what do you mean? Timing out is considered an error in many
APIs, even if it is a frequent occurrence. After all, the request of
"doing something in X time" failed (even if the underlying operation
may even succeed).

Note that errors in Rust are normal control flow, i.e. they do not
involve exceptions (if that is the concern).

Cheers,
Miguel



[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux