Re: [PATCH V7 0/8] libgpiod: Add Rust bindings

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

 



On 21-10-22, 14:34, Björn Roy Baron wrote:
> > impl<'b> Event<'b> {
> > 
> > /// Get an event stored in the buffer.
> > - pub(crate) fn new(buffer: &'b Buffer, index: usize) -> Result<Self> {
> > 
> > + pub(crate) fn new(buffer: &'b Buffer, index: usize) -> Result<Event<'b>> {
> 
> This looks good to me.
 
> > +impl<'e, 'b> Event<'e> {
> > 
> > + pub fn event_clone(event: &Event<'b>) -> Result<Event<'e>>
> > 
> > + where
> > + 'e: 'b,
> 
> Using `Event<'b>` on both sides should work fine. `Event` is
> covariant in it's lifetime parameter, so `Event<'b>` can be turned
> into `Event<'e>` with `'e` being a shorter lifetime than `'b`. What
> you wrote here is not incorrect, so if you prefer keeping it this
> way that is fine with me.

That doesn't let the cloned event to live past read_edge_events().

error[E0502]: cannot borrow `buffer` as mutable because it is also borrowed as immutable
  --> libgpiod/examples/gpio_events.rs:70:50
   |
64 |             let event = buffer.event(0)?;
   |                         --------------- immutable borrow occurs here
...
70 |             let count = request.read_edge_events(&mut buffer)?;
   |                                                  ^^^^^^^^^^^ mutable borrow occurs here
...
86 |         }
   |         - immutable borrow might be used here, when `cloned_event` is dropped and runs the `Drop` code for type `libgpiod::request::Event`

-- 
viresh



[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