Main Problem:
I write a cli application to communicate with a http-server. The Server provides me with several endpoints and some functions under these endpoints (eg. /todo/add
, /other_endpoint/del
). Access to the library should represent these endpoints (eg master.todo.add(...)
, master.other_endpoint.del(...)
).
My first attemp was to add the Master
as reference to all endpoint objects.
struct Todo {
m: Master
}
The Master
holds objects to all endpoints
struct Master {
todo: Todo,
other_endpoint: OtherEndpoint,
server: Server,
}
Master
holds a server
object to communicate with the http-server. So endpoint objects can call this server object via self.master.server.communicate()
.
But I have driven my rust(y) car against a recursive type 'Master' has infinite size
. After that I have tried a m: &'a Master
with all definitions of the lifetimes. But without success.
I have now two questions:
- What do I have to do to get this to work?
- Does another design exist (maybe a nicer one) to get this done?
Edit:
- The question isn't resolved with Why are recursive struct types illegal in Rust? as I ask about the design around this problem.