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
impl Value
Sourcepub fn compile_string(ctx: &Ctx, src: &str) -> Result<Self, Error>
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.
Sourcepub fn compile_bytes(ctx: &Ctx, src: &[u8]) -> Result<Self, Error>
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.
Sourcepub fn to_json_bytes(&self) -> Result<Bytes, Error>
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).
Sourcepub fn unify(v1: &Value, v2: &Value) -> Self
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.
Sourcepub fn is_valid(&self) -> Result<(), Error>
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.