Skip to main content

Value

Struct Value 

Source
pub struct Value(/* private fields */);
Expand description

A CUE value backed by a libcue cue_value handle.

Construct one via Value::compile_string or Value::compile_bytes; the underlying handle is freed automatically when this value is dropped.

A successfully constructed Value may still represent an invalid CUE value (e.g. a bottom value produced by a conflicting unification). Call Value::is_valid to confirm the value is error-free before using it.

Implementations§

Source§

impl Value

Source

pub fn compile_string(ctx: &Ctx, src: &str) -> Result<Self, Error>

Compiles a CUE source string into a Value.

§Errors

Returns Error::StringContainsNul if src contains interior nul bytes, or Error::Cue if libcue reports a compilation error.

Source

pub fn compile_bytes(ctx: &Ctx, src: &[u8]) -> Result<Self, Error>

Compiles a CUE source byte slice into a Value.

Unlike Value::compile_string, this accepts source that may contain interior nul bytes (since it is passed by pointer and length rather than as a C string).

§Errors

Returns Error::Cue if libcue reports a compilation error.

Source

pub fn to_json_bytes(&self) -> Result<Bytes, Error>

Encodes this CUE value as JSON.

Calls cue_dec_json from libcue and copies the result into an owned bytes::Bytes buffer containing the raw JSON bytes. The C-allocated buffer is freed before returning.

§Errors

Returns Error::Cue if libcue reports an error (e.g. the value cannot be represented as JSON).

Source

pub fn unify(v1: &Value, v2: &Value) -> Self

Unifies two CUE values, returning the meet of the two.

Calls cue_unify from libcue. In CUE, unification is the & operator: the result is the most specific value that satisfies both operands. If the two values are incompatible the result is the bottom value (_|_); call Value::is_valid to check.

Source

pub fn is_valid(&self) -> Result<(), Error>

Validates this CUE value, returning an error if it is not valid.

Calls cue_validate from libcue with no export options. A value is valid when it contains no errors (e.g. it is not a bottom value).

§Errors

Returns Error::Cue if libcue reports a validation error.

Trait Implementations§

Source§

impl Debug for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Value

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnsafeUnpin for Value

§

impl UnwindSafe for Value

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.