Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-utils/src/bool.rs
8406 views
1
use std::ops::Deref;
2
3
// a boolean flag that can only be set to `true` safely
4
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
5
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6
#[cfg_attr(feature = "dsl-schema", derive(schemars::JsonSchema))]
7
pub struct UnsafeBool(bool);
8
impl Default for UnsafeBool {
9
fn default() -> Self {
10
UnsafeBool(true)
11
}
12
}
13
14
impl UnsafeBool {
15
#[allow(clippy::missing_safety_doc)]
16
pub unsafe fn new_false() -> Self {
17
UnsafeBool(false)
18
}
19
}
20
21
impl Deref for UnsafeBool {
22
type Target = bool;
23
24
fn deref(&self) -> &Self::Target {
25
&self.0
26
}
27
}
28
29
impl AsRef<bool> for UnsafeBool {
30
fn as_ref(&self) -> &bool {
31
&self.0
32
}
33
}
34
35