ScuffleTV / scuffle

Live streaming platform
https://scuffle.tv
224 stars 25 forks source link

fix: unsound cache upcast #136

Closed TroyKomodo closed 8 months ago

TroyKomodo commented 8 months ago

Proposed changes

Removes the unsafe code around cache upcasting by introducing traited functions as_ref and as_mut on the AutoImplCacheRef trait. Also no longer requires the unsafe attribute.

Types of changes

What types of changes does your code introduce to Scuffle? Put an x in the boxes that apply

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

Further comments

If this is a relatively large or complex change, you may want to start the discussion by explaining why you chose the solution you did, what alternatives you considered, etc.

TroyKomodo commented 8 months ago

My review is pretty useless here because I never wrote any unsafe and don't really know what's going on here. I don't even understand what this was for in the first place.

lgtm

It was so that we can allow for a cache to be a reference, rather than having an owned value. An example of this might be

let cache = SharedCache::new()

loader.load("key", &cache);
loader.load("key", &cache);

Rather than

let cache = Arc::new(SharedCache::new())

loader.load("key", cache.clone());
loader.load("key", cache.clone());
lennartkloock commented 8 months ago

It was so that we can allow for a cache to be a reference, rather than having an owned value. An example of this might be

I see.

Always good to remove unsafe code.