glib_macros::downgrade_derive::fields

Function derive_downgrade_fields

source
pub fn derive_downgrade_fields(fields: Fields) -> DowngradeStructParts
Expand description

This function generates parts needed to derive Downgrade and Upgrade implementations.

§Example

Let’s assume following types are declared.

struct Unnamed(X, Y);

struct Named {
    x: X,
    y: Y,
}

enum Choice {
    This(X, Y),
    That { x: X, y: Y },
}

§weak_fields

For the struct Unnamed and for a enum’s variant Choice::This it will be (<X as Downgrade>::Weak, <Y as Downgrade>::Weak). For the struct Named and for a enum’s variant Choice::That it will be { x: <X as Downgrade>::Weak, y: <Y as Downgrade>::Weak, }.

§end_of_struct

It is a semicolon (;) for an Unnamed and is blank for the rest.

§destruct

For the struct Unnamed and for a enum’s variant Choice::This it will be (ref _0, ref _1). For the struct Named and for a enum’s variant Choice::That it will be { ref x, ref y }. So it can be used as a destructuring pattern for values of both types, strong and weak.

let Unnamed (ref _0, ref _1) = <expression>;
let Named { ref x, ref y } = <expression>;

match <expression> {
    Choice::This (ref _0, ref _1) => ... ,
    Choice::That { ref x, ref y } => ... ,
}

§downgrade

(
    glib::clone::Downgrade::downgrade(_0),
    glib::clone::Downgrade::downgrade(_1),
)

{
    x: glib::clone::Downgrade::downgrade(x),
    y: glib::clone::Downgrade::downgrade(y),
}

§upgrade

(
    glib::clone::Upgrade::upgrade(_0)?,
    glib::clone::Upgrade::upgrade(_1)?,
)

{
    x: glib::clone::Upgrade::upgrade(x)?,
    y: glib::clone::Upgrade::upgrade(y)?,
}