Struct JsonValue

Source
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>

Source

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.

Source

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.

Source

pub fn as_str(&self) -> Option<&str>

Returns the value, if it is a string.

Source

pub fn as_num(&self) -> Option<f64>

Returns the value, if it is a number.

Source

pub fn as_bool(&self) -> Option<bool>

Returns the value, if it is a bool.

Source

pub fn as_null(&self) -> Option<()>

Returns Some(()) if the value is null.

Source

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.

Source

pub fn from_num(vm: &'a JsonnetVm, v: f64) -> Self

Convert the given double to a JsonValue.

Source

pub fn from_bool(vm: &'a JsonnetVm, v: bool) -> Self

Convert the given bool to a JsonValue.

Source

pub fn null(vm: &'a JsonnetVm) -> Self

Make a JsonValue representing null.

Source

pub fn from_array<T>(vm: &'a JsonnetVm, iter: T) -> Self
where T: IntoIterator<Item = JsonValue<'a>>,

Convert the given list into a JsonValue array.

Source

pub fn from_map<'b, T>(vm: &'a JsonnetVm, iter: T) -> Self
where T: IntoIterator<Item = (&'b CStr, JsonValue<'a>)>,

Convert the given map into a JsonValue object.

Source

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.

Trait Implementations§

Source§

impl<'a> Drop for JsonValue<'a>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for JsonValue<'a>

§

impl<'a> RefUnwindSafe for JsonValue<'a>

§

impl<'a> !Send for JsonValue<'a>

§

impl<'a> !Sync for JsonValue<'a>

§

impl<'a> Unpin for JsonValue<'a>

§

impl<'a> UnwindSafe for JsonValue<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.