pub struct JsonValue<'a> { /* private fields */ }
Expand description
Rust wrapper for owned libjsonnet JSON values.
These are used as return values from jsonnet native callbacks.
See JsonVal
for the borrowed version.
Implementations§
Source§impl<'a> JsonValue<'a>
impl<'a> JsonValue<'a>
Sourcepub unsafe fn from_ptr(vm: &'a JsonnetVm, p: *mut JsonnetJsonValue) -> Self
pub unsafe fn from_ptr(vm: &'a JsonnetVm, p: *mut JsonnetJsonValue) -> Self
Construct a JsonValue
from a pointer returned from a
low-level jsonnet C function.
§Safety
It is up to the caller to ensure that p
was indeed allocated
by vm
.
Sourcepub fn as_ptr(&self) -> *const JsonnetJsonValue
pub fn as_ptr(&self) -> *const JsonnetJsonValue
Returns the inner pointer to this jsonnet value.
The returned pointer will be valid for as long as self
is.
Sourcepub fn from_str(vm: &'a JsonnetVm, v: &str) -> Self
pub fn from_str(vm: &'a JsonnetVm, v: &str) -> Self
Convert the given UTF8 string to a JsonValue.
§Panics
Panics if v
contains an embedded nul character.
Sourcepub fn from_array<T>(vm: &'a JsonnetVm, iter: T) -> Selfwhere
T: IntoIterator<Item = JsonValue<'a>>,
pub fn from_array<T>(vm: &'a JsonnetVm, iter: T) -> Selfwhere
T: IntoIterator<Item = JsonValue<'a>>,
Convert the given list into a JsonValue array.
Sourcepub fn from_map<'b, T>(vm: &'a JsonnetVm, iter: T) -> Self
pub fn from_map<'b, T>(vm: &'a JsonnetVm, iter: T) -> Self
Convert the given map into a JsonValue object.
Sourcepub fn into_raw(self) -> *mut JsonnetJsonValue
pub fn into_raw(self) -> *mut JsonnetJsonValue
Transfer ownership to a C caller (presumably a jsonnet function).
If you call this, it is up to you to ensure that the value is freed correctly (using the appropriate jsonnet function), or the memory will leak.