Skip to content

Return a connection object from a function? #343

Answered by diwic
Ziris85 asked this question in Q&A
Discussion options

You must be logged in to vote

I think there isn't one right answer to this question; there are several designs. Probably the easiest one is to create a struct like this:

struct MyConnection {
    conn: Connection,
    intf: DBusInterface // I e, your existing enum
}

And then in every method of MyConnection, construct the proxy and then call whatever methods you need on that.

The other option would be to create a struct that contains both a Connection and a Proxy and that struct then has to use a crate like rental because the Proxy references the Connection. I guess this is more complicated, but I don't know because I never used rental myself.

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@Ziris85
Comment options

@diwic
Comment options

@Ziris85
Comment options

@diwic
Comment options

@Ziris85
Comment options

Answer selected by Ziris85
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants