Skip to content

Commit 9c9aa1f

Browse files
committed
Add literal 'null', 'true' and 'false' consts to RawValue struct.
1 parent 7cce517 commit 9c9aa1f

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: &RawValue = RawValue::from_borrowed("null");
124+
/// A literal JSON boolean true value as `RawValue`.
125+
pub const TRUE: &RawValue = RawValue::from_borrowed("true");
126+
/// A literal JSON boolean false value as `RawValue`.
127+
pub const FALSE: &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)