@@ -28,7 +28,6 @@ use std::mem;
28
28
use std:: ops:: Range ;
29
29
use std:: sync:: Arc ;
30
30
31
- use crate :: data:: private:: UnsafeFlag ;
32
31
use crate :: { equal, validate_binary_view, validate_string_view} ;
33
32
34
33
#[ inline]
@@ -1781,33 +1780,61 @@ impl PartialEq for ArrayData {
1781
1780
}
1782
1781
}
1783
1782
1784
- mod private {
1785
- /// A boolean flag that cannot be mutated outside of unsafe code.
1783
+ /// A boolean flag that cannot be mutated outside of unsafe code.
1784
+ ///
1785
+ /// Defaults to a value of false.
1786
+ ///
1787
+ /// This structure is used to enforce safety in the [`ArrayDataBuilder`]
1788
+ ///
1789
+ /// [`ArrayDataBuilder`]: super::ArrayDataBuilder
1790
+ ///
1791
+ /// # Example
1792
+ /// ```rust
1793
+ /// use arrow_data::UnsafeFlag;
1794
+ /// assert!(!UnsafeFlag::default().get()); // default is false
1795
+ /// let mut flag = UnsafeFlag::new();
1796
+ /// assert!(!flag.get()); // defaults to false
1797
+ /// // can only set it to true in unsafe code
1798
+ /// unsafe { flag.set(true) };
1799
+ /// assert!(flag.get()); // now true
1800
+ /// ```
1801
+ #[ derive( Debug , Clone ) ]
1802
+ pub struct UnsafeFlag ( bool ) ;
1803
+
1804
+ impl UnsafeFlag {
1805
+ /// Creates a new `UnsafeFlag` with the value set to `false`.
1806
+ ///
1807
+ /// See examples on [`Self::new`]
1808
+ #[ inline]
1809
+ pub const fn new ( ) -> Self {
1810
+ Self ( false )
1811
+ }
1812
+
1813
+ /// Sets the value of the flag to the given value
1786
1814
///
1787
- /// Defaults to a value of false.
1815
+ /// Note this can purposely only be done in `unsafe` code
1788
1816
///
1789
- /// This structure is used to enforce safety in the [`ArrayDataBuilder`]
1817
+ /// # Safety
1790
1818
///
1791
- /// [`ArrayDataBuilder`]: super::ArrayDataBuilder
1792
- #[ derive( Debug ) ]
1793
- pub struct UnsafeFlag ( bool ) ;
1794
-
1795
- impl UnsafeFlag {
1796
- /// Creates a new `UnsafeFlag` with the value set to `false`
1797
- #[ inline]
1798
- pub const fn new ( ) -> Self {
1799
- Self ( false )
1800
- }
1819
+ /// If set, the flag will be set to the given value. There is nothing
1820
+ /// immediately unsafe about doing so, however, the flag can be used to
1821
+ /// subsequently bypass safety checks in the [`ArrayDataBuilder`].
1822
+ #[ inline]
1823
+ pub unsafe fn set ( & mut self , val : bool ) {
1824
+ self . 0 = val;
1825
+ }
1801
1826
1802
- #[ inline]
1803
- pub unsafe fn set ( & mut self , val : bool ) {
1804
- self . 0 = val;
1805
- }
1827
+ /// Returns the value of the flag
1828
+ #[ inline]
1829
+ pub fn get ( & self ) -> bool {
1830
+ self . 0
1831
+ }
1832
+ }
1806
1833
1807
- # [ inline ]
1808
- pub fn get ( & self ) -> bool {
1809
- self . 0
1810
- }
1834
+ // Manual impl to make it clear you can not construct unsafe with true
1835
+ impl Default for UnsafeFlag {
1836
+ fn default ( ) -> Self {
1837
+ Self :: new ( )
1811
1838
}
1812
1839
}
1813
1840
0 commit comments