Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to tell if Bytes is unique #533

Closed
zyxw59 opened this issue Feb 28, 2022 · 4 comments · Fixed by #643
Closed

Add a way to tell if Bytes is unique #533

zyxw59 opened this issue Feb 28, 2022 · 4 comments · Fixed by #643

Comments

@zyxw59
Copy link
Contributor

zyxw59 commented Feb 28, 2022

I would like to be able to tell if a Bytes object is the unique reference to the underlying data. The usecase is a cache, where I want to be able to evict an object from the cache only if it is not used elsewhere — otherwise, removing it from the cache would not free up any memory, and if the object was requested again later, it would have to be fetched (in my case, thru a network request), and duplicated in memory if the original copy is still around.

@Darksonn
Copy link
Contributor

Darksonn commented Mar 1, 2022

Seems reasonable enough to me.

@NobodyXu
Copy link
Contributor

@zyxw59 What about instances created using Bytes::from_static?

@zyxw59
Copy link
Contributor Author

zyxw59 commented Apr 20, 2022

I think in that case it is probably correct to always say that it is not unique (since there always might be other copies)

@NobodyXu
Copy link
Contributor

I think this can be easily implemented by adding another function to Vtable of Bytes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants