Skip to content

Commit

Permalink
fix soundness
Browse files Browse the repository at this point in the history
  • Loading branch information
2ndTaleStudio committed Nov 16, 2020
1 parent 0565f8e commit b0d2bd2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/lib.rs
Expand Up @@ -81,8 +81,10 @@ pub struct Singleton<T: 'static> {

// The Singleton need to implement Send & Sync to ensure cross core compile check mechanics
// this is safe as the inner RWLock ensures cross core safety
unsafe impl<T> Sync for Singleton<T> {}
unsafe impl<T> Send for Singleton<T> {}
// but we need to be conditional on the inner type to prevent interior mutable types beeing used
// inside a singleton
unsafe impl<T> Sync for Singleton<T> where T: Sync {}
unsafe impl<T> Send for Singleton<T> where T: Send {}

impl<T: 'static> Singleton<T> {
/// Create a new [Singleton] instance to be used in a static variable. Only ``const fn`` constructors are allowed
Expand Down

0 comments on commit b0d2bd2

Please sign in to comment.