Skip to content

Commit 96576ba

Browse files
authored
Merge pull request #1221 from bheylin/add-const-raw-values-for-null-and-bools
Add literal 'null', 'true' and 'false' consts to `RawValue` struct.
2 parents 0903de4 + 4db66fb commit 96576ba

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/raw.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,14 @@ pub struct RawValue {
119119
}
120120

121121
impl RawValue {
122-
fn from_borrowed(json: &str) -> &Self {
122+
/// A literal JSON null value as `RawValue`.
123+
pub const NULL: &'static RawValue = RawValue::from_borrowed("null");
124+
/// A literal JSON boolean true value as `RawValue`.
125+
pub const TRUE: &'static RawValue = RawValue::from_borrowed("true");
126+
/// A literal JSON boolean false value as `RawValue`.
127+
pub const FALSE: &'static RawValue = RawValue::from_borrowed("false");
128+
129+
const fn from_borrowed(json: &str) -> &Self {
123130
unsafe { mem::transmute::<&str, &RawValue>(json) }
124131
}
125132

@@ -148,7 +155,7 @@ impl ToOwned for RawValue {
148155

149156
impl Default for Box<RawValue> {
150157
fn default() -> Self {
151-
RawValue::from_borrowed("null").to_owned()
158+
RawValue::NULL.to_owned()
152159
}
153160
}
154161

0 commit comments

Comments
 (0)