Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add literal 'null', 'true' and 'false' consts to RawValue struct. #1221

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}

Expand Down Expand Up @@ -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()
}
}

Expand Down
Loading