Re: [PATCH V6 3/8] libgpiod: Add rust wrapper crate

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

 



On Wed, Sep 28, 2022 at 7:54 PM Bartosz Golaszewski <brgl@xxxxxxxx> wrote:
>
> I'm a Rust beginner but my understanding is that the whole idea of the
> language design is to *not* allow a situation where the program can
> crash. It should be detected at build-time. We must not rely on

More precisely, it needs to avoid UB (which is defined similarly as in
C++, and of course UB may lead to a crash if one is lucky).

> Is there a way to invalidate a reference in Rust? Have a small (cheap)
> object in the buffer which the event references and which would get
> dropped when reading into the buffer?

>From your C++ example above:

    const edge_event& ev = buffer.get_event(0);
    request.read_edge_event(buffer);
    std::cout << ev << std::endl;

It looks like a container whose elements get invalidated, so
`read_edge_event` could require an exclusive reference to `buffer` in
Rust, that way you cannot keep borrows to its elements like `ev` if
you want to call it. But of course this requires tying the lifetime of
the events to that of the buffer.

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