diwic / dbus-rs

D-Bus binding for the Rust language
Other
592 stars 133 forks source link

Codegen: structs with more than 12 items #488

Open bachrc opened 4 weeks ago

bachrc commented 4 weeks ago

I have a method that exceeds 12 args in a XML file.

I used the codegen to generate a file that uses crossroads.

Though, my method has 18 args, and tells that is does not implement AppendAll.

This is quite similar though to the closed issue here : https://github.com/diwic/dbus-rs/issues/310 but I saw in the dbus@0.9.7 that this is fixed until 26 args, why doesn't it work?

I saw that crossroads uses the version 0.9.3 of dbus, and it makes my code break. Could you update the dependency?

Thank you for your hard work, please have a great day

bachrc commented 4 weeks ago

Because I am actually not sure of the issue origin, here is the error I have

error[E0277]: the trait bound `(u8, u16, u64, u64, u16, u64, u16, u64, u16, u64, u16, std::string::String, u16, u16, u16, u16, u64): Arg` is not satisfied
  --> crates/dbus-api/src/managet.rs:59:11
   |
59 |         b.method("GetDetails", (), ("details",), |_, t: &mut T, ()| {
   |           ^^^^^^ the trait `Arg` is not implemented for `(u8, u16, u64, u64, u16, u64, u16, u64, u16, u64, u16, std::string::String, u16, u16, u16, u16, u64)`, which is required by `((u8, u16, u64, u64, u16, u64, u16, u64, u16, u64, u16, std::string::String, u16, u16, u16, u16, u64),): ArgAll`
   |
   = help: the following other types implement trait `Arg`:
             (A, B)
             (A, B, C)
             (A, B, C, D)
             (A, B, C, D, E)
             (A, B, C, D, E, F)
             (A, B, C, D, E, F, G)
             (A, B, C, D, E, F, G, H)
             (A, B, C, D, E, F, G, H, I)
           and 4 others
   = note: required for `((u8, u16, u64, u64, u16, u64, u16, u64, u16, u64, u16, std::string::String, u16, u16, u16, u16, u64),)` to implement `ArgAll`
bachrc commented 4 weeks ago

I changed the subject of the issue because after a cargo tree, it seems that I have the version 0.9.7 of dbus used by crossroads.. 12 arguments are okay, but 13 are not.

bachrc commented 4 weeks ago

Okay found it : https://github.com/diwic/dbus-rs/blob/master/dbus/src/arg/variantstruct_impl.rs

We should have as well more arguments here. I tried to repeat some more struct_impl, but it seems stucked:

error[E0277]: `(A, B, C, D, E, F, G, H, I, J, K, L, M)` doesn't implement `Debug`
   --> /home/wudi/.local/cargo/registry/src/proxy-repositoi.zca.enedis.fr-c600039f8bc00812/dbus-0.9.7/src/arg/variantstruct_impl.rs:131:34
    |
131 | impl<$($t: RefArg),*> RefArg for ($($t,)*) {
    |                                  ^^^^^^^^^ `(A, B, C, D, E, F, G, H, I, J, K, L, M)` cannot be formatted using `{:?}` because it doesn't implement `Debug`
...
182 | struct_impl!(a A, b B, c C, d D, e E, f F, g G, h H, i I, j J, k K, l L, m M,);
    | ------------------------------------------------------------------------------ in this macro invocation
    |
    = help: the trait `Debug` is not implemented for `(A, B, C, D, E, F, G, H, I, J, K, L, M)`
    = help: the following other types implement trait `Debug`:
              ()
              (A, Z, Y, X, W, V, U, T)
              (B, A, Z, Y, X, W, V, U, T)
              (C, B, A, Z, Y, X, W, V, U, T)
              (D, C, B, A, Z, Y, X, W, V, U, T)
              (E, D, C, B, A, Z, Y, X, W, V, U, T)
              (T,)
              (U, T)
            and 5 others
note: required by a bound in `msgarg::RefArg`
   --> /home/wudi/.local/cargo/registry/src/proxy-repositoi.zca.enedis.fr-c600039f8bc00812/dbus-0.9.7/src/arg/msgarg.rs:59:19
    |
59  | pub trait RefArg: fmt::Debug + Send + Sync {
    |                   ^^^^^^^^^^ required by this bound in `RefArg`
    = note: this error originates in the macro `struct_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
diwic commented 4 weeks ago

It is indeed a limit in std that Debug is only able to do up to twelve items: https://doc.rust-lang.org/std/fmt/trait.Debug.html

diwic commented 4 weeks ago

I've added a commit in dbus-codegen causing us not to try to return invalid rust types but to fall back to VecDeque<Box<RefArg>> instead. Could you test it and see if it resolves your issue?

If not, could you supply the xml file to test with?

diwic commented 3 weeks ago

Related commit that might help: https://github.com/diwic/dbus-rs/commit/cabf790b909582e9c75cd5f4ff57e22b4d25fb23

bachrc commented 3 weeks ago

Thank you for your quick answer! I have to compile dbus-codegen from main branch right? I'll give you a feedback on Monday

diwic commented 3 weeks ago

I have to compile dbus-codegen from main branch right?

Both dbus and dbus-codegen need to be the version from the master branch since I added two commits to dbus as well.

bachrc commented 3 weeks ago

Thank you for your time ! I just made some and have still some bugs:

I have the following error message:

the trait bound `VecDeque<Box<dyn RefArg>>: Arg` is not satisfied
the following other types implement trait `Arg`:
  &'a CStr
  &'a T
  &'a [T]
  &'a str
  (A, B)
  (A, B, C)
  (A, B, C, D)
  (A, B, C, D, E)
and 33 others
required for `(VecDeque<Box<dyn RefArg>>,)` to implement `ArgAll`rustc[Click for full compiler diagnostic](rust-analyzer-diagnostics-view:/diagnostic message [3]?3#file:///workspaces/i2r/crates/dbus-api/src/modem_manager.rs)
the trait bound `VecDeque<Box<dyn RefArg>>: Append` is not satisfied
the following other types implement trait `Append`:
  &'a T
  &'a [T]
  &'a str
  (A, B)
  (A, B, C)
  (A, B, C, D)
  (A, B, C, D, E)
  (A, B, C, D, E, F)
and 38 others
required for `(VecDeque<Box<dyn RefArg>>,)` to implement `AppendAll`

Here is a minimal XML example

<?xml version="1.0" encoding="UTF-8"?>
<node xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
    <interface name="com.dbus.example">
        <method name="GetTrucDetails">
            <arg type="(yqttqtqtqtqsqqqqt)" direction="out" name="trucDetails">
                <doc:doc>
                    <doc:summary>
                        <doc:para>Type de donnée.</doc:para>
                        <doc:list>
                            <doc:item>
                                <doc:term>techno</doc:term>
                                <doc:definition>BYTE
                                    <doc:para>Les valeurs possibles sont les suivantes :
                                        <doc:list>
                                            <doc:item>
                                                <doc:term>1</doc:term>
                                                <doc:definition>UN</doc:definition>
                                            </doc:item>
                                            <doc:item>
                                                <doc:term>2</doc:term>
                                                <doc:definition>DEUX</doc:definition>
                                            </doc:item>
                                            <doc:item>
                                                <doc:term>3</doc:term>
                                                <doc:definition>TROIS</doc:definition>
                                            </doc:item>
                                            <doc:item>
                                                <doc:term>4</doc:term>
                                                <doc:definition>QUATRE</doc:definition>
                                            </doc:item>
                                            <doc:item>
                                                <doc:term>5</doc:term>
                                                <doc:definition>CINQ</doc:definition>
                                            </doc:item>
                                            <doc:item>
                                                <doc:term>6</doc:term>
                                                <doc:definition>SIX</doc:definition>
                                            </doc:item>
                                            <doc:item>
                                                <doc:term>7</doc:term>
                                                <doc:definition>SEPT</doc:definition>
                                            </doc:item>
                                            <doc:item>
                                                <doc:term>8</doc:term>
                                                <doc:definition>HUIT</doc:definition>
                                            </doc:item>
                                            <doc:item>
                                                <doc:term>9</doc:term>
                                                <doc:definition>NEUF</doc:definition>
                                            </doc:item>
                                            <doc:item>
                                                <doc:term>10</doc:term>
                                                <doc:definition>DIX</doc:definition>
                                            </doc:item>
                                        </doc:list>
                                    </doc:para>
                                </doc:definition>
                            </doc:item>
                            <doc:item>
                                <doc:term>TEST</doc:term>
                                <doc:definition>UINT16 : numero.</doc:definition>
                            </doc:item>
                            <doc:item>
                                <doc:term>ahqueoui</doc:term>
                                <doc:definition>BYTE
                                    <doc:para>Niveau de truc :
                                        <doc:list>
                                            <doc:item>
                                                <doc:term>0</doc:term>
                                                <doc:definition>Quelque chose</doc:definition>
                                            </doc:item>
                                            <doc:item>
                                                <doc:term>1</doc:term>
                                                <doc:definition>Quelque chose</doc:definition>
                                            </doc:item>
                                            <doc:item>
                                                <doc:term>2 à 30</doc:term>
                                                <doc:definition>Quelque chose</doc:definition>
                                            </doc:item>
                                            <doc:item>
                                                <doc:term>31</doc:term>
                                                <doc:definition>Quelque chose</doc:definition>
                                            </doc:item>
                                            <doc:item>
                                                <doc:term>99</doc:term>
                                                <doc:definition>Quelque chose</doc:definition>
                                            </doc:item>
                                        </doc:list>
                                    </doc:para>
                                </doc:definition>
                            </doc:item>
                            <doc:item>
                                <doc:term>bahouient</doc:term>
                                <doc:definition>BYTE
                                    <doc:para>Tauxdetruc
                                        <doc:list>
                                            <doc:item>
                                                <doc:term>0 à 7</doc:term>
                                                <doc:definition>eh oui</doc:definition>
                                            </doc:item>
                                            <doc:item>
                                                <doc:term>99</doc:term>
                                                <doc:definition>eh non</doc:definition>
                                            </doc:item>
                                        </doc:list>
                                    </doc:para>
                                </doc:definition>
                            </doc:item>
                            <doc:item>
                                <doc:term>machintruc</doc:term>
                                <doc:definition>UINT16 : toujours pas.</doc:definition>
                            </doc:item>
                            <doc:item>
                                <doc:term>pouetpouet</doc:term>
                                <doc:definition>BYTE
                                    <doc:para>oh non
                                        <doc:list>
                                            <doc:item>
                                                <doc:term>0</doc:term>
                                                <doc:definition>zero</doc:definition>
                                            </doc:item>
                                            <doc:item>
                                                <doc:term>1</doc:term>
                                                <doc:definition>un</doc:definition>
                                            </doc:item>
                                            <doc:item>
                                                <doc:term>2</doc:term>
                                                <doc:definition>deux</doc:definition>
                                            </doc:item>
                                            <doc:item>
                                                <doc:term>3</doc:term>
                                                <doc:definition>trois</doc:definition>
                                            </doc:item>
                                            <doc:item>
                                                <doc:term>4</doc:term>
                                                <doc:definition>quatre</doc:definition>
                                            </doc:item>
                                            <doc:item>
                                                <doc:term>5</doc:term>
                                                <doc:definition>cinq</doc:definition>
                                            </doc:item>
                                            <doc:item>
                                                <doc:term>6</doc:term>
                                                <doc:definition>six</doc:definition>
                                            </doc:item>
                                            <doc:item>
                                                <doc:term>7</doc:term>
                                                <doc:definition>sept</doc:definition>
                                            </doc:item>
                                        </doc:list>
                                    </doc:para>
                                </doc:definition>
                            </doc:item>
                            <doc:item>
                                <doc:term>pouetencore</doc:term>
                                <doc:definition>UINT16 : autre chose</doc:definition>
                            </doc:item>
                            <doc:item>
                                <doc:term>hahahah</doc:term>
                                <doc:definition>BYTE
                                    <doc:para>alors oui mais non
                                        <doc:list>
                                            <doc:item>
                                                <doc:term>0</doc:term>
                                                <doc:definition> encore du travail</doc:definition>
                                            </doc:item>
                                            <doc:item>
                                                <doc:term>1</doc:term>
                                                <doc:definition>un</doc:definition>
                                            </doc:item>
                                           <doc:item>
                                                <doc:term>2 à 48</doc:term>
                                                <doc:definition>beaucoup</doc:definition>
                                            </doc:item>
                                            <doc:item>
                                                <doc:term>49</doc:term>
                                                <doc:definition>douze</doc:definition>
                                            </doc:item>
                                            <doc:item>
                                                <doc:term>255</doc:term>
                                                <doc:definition>soixante</doc:definition>
                                            </doc:item>
                                        </doc:list>
                                    </doc:para>
                                </doc:definition>
                            </doc:item>
                            <doc:item>
                                <doc:term>bababab</doc:term>
                                <doc:definition>UINT16 : ah ca avance</doc:definition><!--TODO: voir le type ? -->
                            </doc:item>
                            <doc:item>
                                <doc:term>tjrspa</doc:term>
                                <doc:definition>BYTE
                                    <doc:para>on est la
                                        <doc:list>
                                            <doc:item>
                                                <doc:term>0</doc:term>
                                                <doc:definition>quelquechose</doc:definition>
                                            </doc:item>
                                            <doc:item>
                                                <doc:term>1 à 33</doc:term>
                                                <doc:definition>ah peutetre que non</doc:definition>
                                            </doc:item>
                                            <doc:item>
                                                <doc:term>34</doc:term>
                                                <doc:definition>ya moyen</doc:definition>
                                            </doc:item>
                                        </doc:list>
                                    </doc:para>
                                </doc:definition>
                            </doc:item>
                            <doc:item>
                                <doc:term>badabadou</doc:term>
                                <doc:definition>UINT16 : Pas content.</doc:definition><!--TODO: voir le type ? -->
                            </doc:item>
                            <doc:item>
                                <doc:term>badabadi</doc:term>
                                <doc:definition>STRING : Pas content </doc:definition>
                            </doc:item>
                            <doc:item>
                                <doc:term>badaaa</doc:term>
                                <doc:definition>UINT16 : Pas content.</doc:definition><!--TODO: voir le type ? -->
                            </doc:item>
                            <doc:item>
                                <doc:term>babdddd</doc:term>
                                <doc:definition>UNINT16 : Pas content.</doc:definition><!--TODO: voir le type ? -->
                            </doc:item>
                            <doc:item>
                                <doc:term>mamamia</doc:term>
                                <doc:definition>UINT16 : Pas content.</doc:definition><!--TODO: voir le type ? -->
                            </doc:item>
                            <doc:item>
                                <doc:term>ahbahlechocolat</doc:term>
                                <doc:definition>UINT16 : Pas content.</doc:definition><!--TODO: voir le type ? -->
                            </doc:item>
                            <doc:item>
                                <doc:term>salutsalut</doc:term>
                                <doc:definition>UINT64 : Pas content</doc:definition>
                            </doc:item>
                        </doc:list>
                    </doc:summary>
                </doc:doc>
            </arg>
        </method>
    </interface>
</node>
bachrc commented 3 weeks ago

(just so you know: i did change the xml interface in multiple args so I don't have the problem anymore, but if ever someone has the problem)

diwic commented 3 weeks ago

Thanks. So the issue is not more than 12 arguments in a method call - we support that, it's a struct with more than 12 items.

What's needed is for codegen to resolve this, is to generate a custom type, and then implement Arg, Append and Get for that custom struct. Until somebody implements that, there is a workaround which is to use your own type, like this:

<?xml version="1.0" encoding="UTF-8"?>
<node xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
    <interface name="com.dbus.example">
        <method name="GetTrucDetails">
            <arg type="(yqttqtqtqtqsqqqqt)" direction="out" name="trucDetails">
                <annotation name="rs.dbus.ArgType" value="myType" />
            </arg>
        </method>
    </interface>
</node>

...and then implement Arg, Append and/or Get yourself, as needed for myType.