Mercurial > public > mercurial-scm > hg-stable
comparison rust/pyo3-sharedref/src/lib.rs @ 52856:189491cea922
pyo3-sharedref: add static assertions that we never implement Deref*
Unfortunately, the `static_assertions` crate has never been updated past
its 1.1.0 release, meaning we don't get the (now 5+ years old) change that
allows us to use generic parameters, so we use `static_assertions_next`.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Tue, 07 Jan 2025 12:51:52 +0100 |
parents | 78b2894cd58c |
children | 8f6d25439bdc |
comparison
equal
deleted
inserted
replaced
52855:d85a3a5545ab | 52856:189491cea922 |
---|---|
480 /// Underlying data of artificial lifetime, which is valid only when | 480 /// Underlying data of artificial lifetime, which is valid only when |
481 /// state.generation == self.generation. | 481 /// state.generation == self.generation. |
482 data: T, | 482 data: T, |
483 } | 483 } |
484 | 484 |
485 // DO NOT implement Deref for SharedByPyObject<T>! Dereferencing | 485 // DO NOT implement Deref or DerefMut for SharedByPyObject<T>! Dereferencing |
486 // SharedByPyObject without taking Python GIL wouldn't be safe. Also, the | 486 // SharedByPyObject without taking Python GIL wouldn't be safe. Also, the |
487 // underling reference is invalid if generation != state.generation. | 487 // underling reference is invalid if generation != state.generation. |
488 static_assertions_next::assert_impl!( | |
489 for(T) SharedByPyObject<T>: !Deref | |
490 ); | |
491 | |
492 static_assertions_next::assert_impl!( | |
493 for(T) SharedByPyObject<T>: !DerefMut | |
494 ); | |
488 | 495 |
489 impl<T: ?Sized> SharedByPyObject<T> { | 496 impl<T: ?Sized> SharedByPyObject<T> { |
490 // No panicking version of borrow() and borrow_mut() are implemented | 497 // No panicking version of borrow() and borrow_mut() are implemented |
491 // because the underlying value is supposed to be mutated in Python | 498 // because the underlying value is supposed to be mutated in Python |
492 // world, and the Rust library designer can't prevent it. | 499 // world, and the Rust library designer can't prevent it. |