launchdarkly / cpp-sdks

C++ Client/Server SDKs
Other
5 stars 2 forks source link

feat!: RedisDataSource::Create should return unique_ptr instead of shared_ptr #344

Closed cwaldren-ld closed 8 months ago

cwaldren-ld commented 8 months ago

Previously, RedisDataSource::Create returned an expected<shared_ptr<RedisDataSource>, error>.

The idea was that DataSystem config accepts a shared_ptr (in theory, so that they don't have to give up management of the source's lifetime. TBD if this turns out to be helpful or not.)

We don't need to force the user into shared ownership in the factory function though - instead, return a unique_ptr and let them make the transformation.

Motivation is thatshared_ptr is painful with the C bindings. We get back a stack-allocated shared_ptr from the factory, and then need to heap allocate one so we cast it to the opaque type. This is not necessary if we just return a unique_ptr, since we can call .release() and then pass the unmanaged pointer around.

shortcut-integration[bot] commented 8 months ago

This pull request has been linked to Shortcut Story #227152: Return unique_ptr when creating RedisDataSource.