Message ID | 490e4efc900d8173fb3e2f1373c97e1a20cb9ac3.1657279685.git.viresh.kumar@linaro.org |
---|---|
State | New |
Headers | show |
Series | libgpiod: Add Rust bindings | expand |
On Fri, Jul 08, 2022 at 05:04:59PM +0530, Viresh Kumar wrote: > These are required for tests, which will be added by a later commit. > Squash this patch into patch 4, as you know you will need them eventually. All public types should implement Debug[1]. They should also implement Clone, Eq, PartialEq and Default where that makes sense. And Copy if you are sure you wont add something non-Copyable to them in the future. Cheers, Kent. [1] https://rust-lang.github.io/api-guidelines/debuggability.html > Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> > --- > bindings/rust/src/chip.rs | 5 +++++ > bindings/rust/src/chip_info.rs | 1 + > bindings/rust/src/lib.rs | 8 +++++++- > bindings/rust/src/line_info.rs | 1 + > 4 files changed, 14 insertions(+), 1 deletion(-) > > diff --git a/bindings/rust/src/chip.rs b/bindings/rust/src/chip.rs > index 50b5d6102f96..ecff4b003cd9 100644 > --- a/bindings/rust/src/chip.rs > +++ b/bindings/rust/src/chip.rs > @@ -21,6 +21,7 @@ use super::{ > /// character device. It exposes basic information about the chip and allows > /// callers to retrieve information about each line, watch lines for state > /// changes and make line requests. > +#[derive(Debug)] > pub(crate) struct ChipInternal { > chip: *mut bindings::gpiod_chip, > } > @@ -52,11 +53,15 @@ impl Drop for ChipInternal { > } > } > > +#[derive(Debug)] > pub struct Chip { > ichip: Arc<ChipInternal>, > info: ChipInfo, > } > > +unsafe impl Send for Chip {} > +unsafe impl Sync for Chip {} > + > impl Chip { > /// Find a chip by path. > pub fn open(path: &str) -> Result<Self> { > diff --git a/bindings/rust/src/chip_info.rs b/bindings/rust/src/chip_info.rs > index 950368b54c6f..7188f91a92a6 100644 > --- a/bindings/rust/src/chip_info.rs > +++ b/bindings/rust/src/chip_info.rs > @@ -11,6 +11,7 @@ use vmm_sys_util::errno::Error as IoError; > use super::{bindings, ChipInternal, Error, Result}; > > /// GPIO chip Information > +#[derive(Debug)] > pub struct ChipInfo { > info: *mut bindings::gpiod_chip_info, > } > diff --git a/bindings/rust/src/lib.rs b/bindings/rust/src/lib.rs > index 2f2ac515d353..63b0b82281b7 100644 > --- a/bindings/rust/src/lib.rs > +++ b/bindings/rust/src/lib.rs > @@ -59,6 +59,7 @@ pub enum Error { > } > > /// Direction settings. > +#[derive(Debug, PartialEq)] > pub enum Direction { > /// Request the line(s), but don't change direction. > AsIs, > @@ -88,6 +89,7 @@ impl Direction { > } > > /// Internal bias settings. > +#[derive(Debug, PartialEq)] > pub enum Bias { > /// Don't change the bias setting when applying line config. > AsIs, > @@ -125,6 +127,7 @@ impl Bias { > } > > /// Drive settings. > +#[derive(Debug, PartialEq)] > pub enum Drive { > /// Drive setting is push-pull. > PushPull, > @@ -154,6 +157,7 @@ impl Drive { > } > > /// Edge detection settings. > +#[derive(Debug, PartialEq)] > pub enum Edge { > /// Line edge detection is disabled. > None, > @@ -223,6 +227,7 @@ impl Config { > } > > /// Event clock settings. > +#[derive(Debug, PartialEq)] > pub enum EventClock { > /// Line uses the monotonic clock for edge event timestamps. > Monotonic, > @@ -248,6 +253,7 @@ impl EventClock { > } > > /// Line status change event types. > +#[derive(Debug, PartialEq)] > pub enum Event { > /// Line has been requested. > LineRequested, > @@ -268,7 +274,7 @@ impl Event { > } > } > > -#[derive(Copy, Clone)] > +#[derive(Copy, Clone, Debug, PartialEq)] > /// Edge event types. > pub enum LineEdgeEvent { > /// Rising edge event. > diff --git a/bindings/rust/src/line_info.rs b/bindings/rust/src/line_info.rs > index 70b6bd6a84bb..426bd16aa616 100644 > --- a/bindings/rust/src/line_info.rs > +++ b/bindings/rust/src/line_info.rs > @@ -23,6 +23,7 @@ use super::{ > /// line, which does not include the line value. The line must be requested > /// to access the line value. > > +#[derive(Debug)] > pub struct LineInfo { > info: *mut bindings::gpiod_line_info, > ichip: Option<Arc<ChipInternal>>, > -- > 2.31.1.272.g89b43f80a514 >
On 27-07-22, 10:58, Kent Gibson wrote: > On Fri, Jul 08, 2022 at 05:04:59PM +0530, Viresh Kumar wrote: > > These are required for tests, which will be added by a later commit. > > > > Squash this patch into patch 4, as you know you will need them > eventually. All public types should implement Debug[1]. > > They should also implement Clone, Eq, PartialEq and Default where > that makes sense. And Copy if you are sure you wont add something > non-Copyable to them in the future. Sure, will define few more for all public structures.
diff --git a/bindings/rust/src/chip.rs b/bindings/rust/src/chip.rs index 50b5d6102f96..ecff4b003cd9 100644 --- a/bindings/rust/src/chip.rs +++ b/bindings/rust/src/chip.rs @@ -21,6 +21,7 @@ use super::{ /// character device. It exposes basic information about the chip and allows /// callers to retrieve information about each line, watch lines for state /// changes and make line requests. +#[derive(Debug)] pub(crate) struct ChipInternal { chip: *mut bindings::gpiod_chip, } @@ -52,11 +53,15 @@ impl Drop for ChipInternal { } } +#[derive(Debug)] pub struct Chip { ichip: Arc<ChipInternal>, info: ChipInfo, } +unsafe impl Send for Chip {} +unsafe impl Sync for Chip {} + impl Chip { /// Find a chip by path. pub fn open(path: &str) -> Result<Self> { diff --git a/bindings/rust/src/chip_info.rs b/bindings/rust/src/chip_info.rs index 950368b54c6f..7188f91a92a6 100644 --- a/bindings/rust/src/chip_info.rs +++ b/bindings/rust/src/chip_info.rs @@ -11,6 +11,7 @@ use vmm_sys_util::errno::Error as IoError; use super::{bindings, ChipInternal, Error, Result}; /// GPIO chip Information +#[derive(Debug)] pub struct ChipInfo { info: *mut bindings::gpiod_chip_info, } diff --git a/bindings/rust/src/lib.rs b/bindings/rust/src/lib.rs index 2f2ac515d353..63b0b82281b7 100644 --- a/bindings/rust/src/lib.rs +++ b/bindings/rust/src/lib.rs @@ -59,6 +59,7 @@ pub enum Error { } /// Direction settings. +#[derive(Debug, PartialEq)] pub enum Direction { /// Request the line(s), but don't change direction. AsIs, @@ -88,6 +89,7 @@ impl Direction { } /// Internal bias settings. +#[derive(Debug, PartialEq)] pub enum Bias { /// Don't change the bias setting when applying line config. AsIs, @@ -125,6 +127,7 @@ impl Bias { } /// Drive settings. +#[derive(Debug, PartialEq)] pub enum Drive { /// Drive setting is push-pull. PushPull, @@ -154,6 +157,7 @@ impl Drive { } /// Edge detection settings. +#[derive(Debug, PartialEq)] pub enum Edge { /// Line edge detection is disabled. None, @@ -223,6 +227,7 @@ impl Config { } /// Event clock settings. +#[derive(Debug, PartialEq)] pub enum EventClock { /// Line uses the monotonic clock for edge event timestamps. Monotonic, @@ -248,6 +253,7 @@ impl EventClock { } /// Line status change event types. +#[derive(Debug, PartialEq)] pub enum Event { /// Line has been requested. LineRequested, @@ -268,7 +274,7 @@ impl Event { } } -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug, PartialEq)] /// Edge event types. pub enum LineEdgeEvent { /// Rising edge event. diff --git a/bindings/rust/src/line_info.rs b/bindings/rust/src/line_info.rs index 70b6bd6a84bb..426bd16aa616 100644 --- a/bindings/rust/src/line_info.rs +++ b/bindings/rust/src/line_info.rs @@ -23,6 +23,7 @@ use super::{ /// line, which does not include the line value. The line must be requested /// to access the line value. +#[derive(Debug)] pub struct LineInfo { info: *mut bindings::gpiod_line_info, ichip: Option<Arc<ChipInternal>>,
These are required for tests, which will be added by a later commit. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> --- bindings/rust/src/chip.rs | 5 +++++ bindings/rust/src/chip_info.rs | 1 + bindings/rust/src/lib.rs | 8 +++++++- bindings/rust/src/line_info.rs | 1 + 4 files changed, 14 insertions(+), 1 deletion(-)