Re: [PATCH v4 7/7] rust: workqueue: add examples

From: Trevor Gross
Date: Thu Oct 05 2023 - 10:16:49 EST


On Tue, Oct 3, 2023 at 6:30 PM Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:
> On Tue, Oct 3, 2023 at 10:13PM Konstantin Shelekhin <k.shelekhin@xxxxxxxx> wrote:
> > +//! #[pin_data]
> > +//! struct MyStruct {
> > +//! value: i32,
> > +//! #[pin]
> > +//! work: Work<MyStruct>,
> > +//! }
> > +//!
> > +//! impl_has_work! {
> > +//! impl HasWork<Self> for MyStruct { self.work }
> > +//! }
> > +//!
> > +//! impl MyStruct {
> > +//! fn new(value: i32) -> Result<Arc<Self>> {
> > +//! Arc::pin_init(pin_init!(MyStruct {
> > +//! value,
> > +//! work <- new_work!("MyStruct::work"),
> > +//! }))
> > +//! }
> > +//! }
> > +//!

For what it's worth, I think that using a binding for return items
usually looks ever so slightly more clear than passing a multiline
argument

fn new(value: i32) -> Result<Arc<Self>> {
let tmp = pin_init!(MyStruct {
value,
work <- new_work!("MyStruct::work")
});
Arc::pin_init(tmp)
}