mirror of
https://github.com/serde-rs/json.git
synced 2025-09-29 22:11:13 +00:00
Merge pull request #1221 from bheylin/add-const-raw-values-for-null-and-bools
Add literal 'null', 'true' and 'false' consts to `RawValue` struct.
This commit is contained in:
commit
96576bad53
11
src/raw.rs
11
src/raw.rs
@ -119,7 +119,14 @@ pub struct RawValue {
|
||||
}
|
||||
|
||||
impl RawValue {
|
||||
fn from_borrowed(json: &str) -> &Self {
|
||||
/// A literal JSON null value as `RawValue`.
|
||||
pub const NULL: &'static RawValue = RawValue::from_borrowed("null");
|
||||
/// A literal JSON boolean true value as `RawValue`.
|
||||
pub const TRUE: &'static RawValue = RawValue::from_borrowed("true");
|
||||
/// A literal JSON boolean false value as `RawValue`.
|
||||
pub const FALSE: &'static RawValue = RawValue::from_borrowed("false");
|
||||
|
||||
const fn from_borrowed(json: &str) -> &Self {
|
||||
unsafe { mem::transmute::<&str, &RawValue>(json) }
|
||||
}
|
||||
|
||||
@ -148,7 +155,7 @@ impl ToOwned for RawValue {
|
||||
|
||||
impl Default for Box<RawValue> {
|
||||
fn default() -> Self {
|
||||
RawValue::from_borrowed("null").to_owned()
|
||||
RawValue::NULL.to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user