Re: [libgpiod][PATCH 16/16] bindings: rust: provide line_config.set_output_values()

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

 



On 13-01-23, 22:52, Bartosz Golaszewski wrote:
> diff --git a/bindings/rust/libgpiod/src/line_config.rs b/bindings/rust/libgpiod/src/line_config.rs
>  
> +    /// Set output values for a number of lines.
> +    pub fn set_output_values(&mut self, values: &[Value]) -> Result<&mut Self> {
> +        let mut mapped_values = Vec::new();
> +        for value in values {
> +            mapped_values.push(value.value());
> +        }

Can be rewritten as this too:

        let values: Vec<gpiod::gpiod_line_value> = values.iter().map(|val| val.value()).collect();

> +
> +        let ret = unsafe {
> +            gpiod::gpiod_line_config_set_output_values(self.config, mapped_values.as_ptr(),
> +                                                       values.len() as u64)
> +        };
> +
> +        if ret == -1 {
> +            Err(Error::OperationFailed(
> +                OperationType::LineConfigSetOutputValues,
> +                errno::errno(),
> +            ))
> +        } else {
> +            Ok(self)
> +        }
> +    }
-- 
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