mirror of
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git
synced 2026-10-24 00:48:53 +03:00
bindings: rust: rename {event,settings}_clone to try_clone
What is getting cloned is already clear from the type. This also aligns a bit better with similar methods from the `std` crate [1]. [1] https://doc.rust-lang.org/std/index.html?search=try_clone Link: https://lore.kernel.org/r/CVUKC1HXG1P8.13XIUCCXN95F0@ablu-work Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Erik Schilling <erik.schilling@linaro.org> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
This commit is contained in:
committed by
Bartosz Golaszewski
parent
808d15ebff
commit
a29f3e6957
@@ -34,7 +34,7 @@ fn main() -> libgpiod::Result<()> {
|
||||
let event = events.next().unwrap()?;
|
||||
|
||||
// This will out live `event` and the next read_edge_events().
|
||||
let cloned_event = libgpiod::request::Event::event_clone(event)?;
|
||||
let cloned_event = libgpiod::request::Event::try_clone(event)?;
|
||||
|
||||
let events = request.read_edge_events(&mut buffer)?;
|
||||
for event in events {
|
||||
|
||||
@@ -29,7 +29,8 @@ pub struct Event(*mut gpiod::gpiod_edge_event);
|
||||
unsafe impl Send for Event {}
|
||||
|
||||
impl Event {
|
||||
pub fn event_clone(event: &Event) -> Result<Event> {
|
||||
/// Makes a copy of the event object.
|
||||
pub fn try_clone(event: &Event) -> Result<Event> {
|
||||
// SAFETY: `gpiod_edge_event` is guaranteed to be valid here.
|
||||
let event = unsafe { gpiod::gpiod_edge_event_copy(event.0) };
|
||||
if event.is_null() {
|
||||
|
||||
@@ -56,8 +56,8 @@ impl Settings {
|
||||
unsafe { gpiod::gpiod_line_settings_reset(self.settings) }
|
||||
}
|
||||
|
||||
/// Makes copy of the settings object.
|
||||
pub fn settings_clone(&self) -> Result<Self> {
|
||||
/// Makes a copy of the settings object.
|
||||
pub fn try_clone(&self) -> Result<Self> {
|
||||
// SAFETY: `gpiod_line_settings` is guaranteed to be valid here.
|
||||
let settings = unsafe { gpiod::gpiod_line_settings_copy(self.settings) };
|
||||
if settings.is_null() {
|
||||
|
||||
@@ -272,7 +272,7 @@ mod line_request {
|
||||
for offset in offsets {
|
||||
lsettings.set_debounce_period(Duration::from_millis((100 + offset).into()));
|
||||
lconfig
|
||||
.add_line_settings(&[offset as Offset], lsettings.settings_clone().unwrap())
|
||||
.add_line_settings(&[offset as Offset], lsettings.try_clone().unwrap())
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user