[][src]Module fred::borrowed

An interface for the RedisClient that borrows self on each command.

This pattern gives the caller more freedom to manage ownership over the value, such as when the client is wrapped with another struct.

However, this pattern is more tedious to use when commands are chained together in a single chain of futures as it requires the caller to either explicitly clone or move the client into those callbacks. For that reason it is not the default interface used in the examples. However, if you intend on wrapping the client in another struct, or an Arc, or something that manages ownership and mutability for the inner value, then this interface is probably what you want. You will still have to manually move or clone the wrapper struct into callbacks as needed, but with this interface the ownership requirements are removed on all commands.

For example, one use case for this interface would be as follows:

  1. Create several RedisClient instances on an event loop.
  2. Move each of the RedisClient instances into another wrapper struct Foo.
  3. Wrap Foo in an Arc, and send clones of the Arc<Foo> to different threads.

If the commands on the RedisClient instances required taking ownership over self then this pattern would be much more difficult to implement, since an Arc only allows for using functions that borrow the inner value. This interface is primarily designed to support this kind of usage.

Traits

RedisClientBorrowed