Skip to main content

Value

Enum Value 

Source
pub enum Value {
    Null,
    Boolean(bool),
    Int(i32),
    BigInt(Box<i128>),
    Float(f64),
    String(Arc<str>),
    Enum(Arc<str>),
    List(Vec<Value>),
    Object(Arc<Object>),
    External(External),
}
Expand description

A GraphQL input or result value.

Variants§

§

Null

The explicit null value.

§

Boolean(bool)

A boolean.

§

Int(i32)

A 32-bit signed integer. GraphQL’s built-in Int is 32-bit.

§

BigInt(Box<i128>)

An integer that does not fit in GraphQL’s built-in 32-bit Int.

Document literals can carry integers up to i128 and JSON transports preserve 64-bit integers. Keeping them as an exact integer lets a custom scalar receive them unchanged, lets Float widen them to a double, and lets ID render them as a decimal string. The built-in Int scalar rejects a BigInt outside its 32-bit range at coercion time.

The value is boxed so this variant does not widen Value on every other value and stack frame; use Value::integer to construct one and Value::as_i128 to read it.

§

Float(f64)

A 64-bit IEEE-754 floating point number.

§

String(Arc<str>)

A string.

§

Enum(Arc<str>)

The name of an enum value.

§

List(Vec<Value>)

An ordered list.

§

Object(Arc<Object>)

An object: an ordered sequence of distinct field names and values.

§

External(External)

An opaque Rust value produced by a higher-level API.

Executors never serialize this variant directly. It exists so a type-safe schema builder can pass its own model types (for example a User struct) between resolvers while the engine stays completely generic. An object type with a resolver accepts it as the parent value; the high-level layer downcasts it with External::downcast_ref.

Implementations§

Source§

impl Value

Source

pub fn string(value: impl Into<Arc<str>>) -> Value

Construct a string value from anything string-like.

Source

pub fn enumeration(value: impl Into<Arc<str>>) -> Value

Construct an enum value from an enum variant name.

Source

pub fn object(object: impl Into<Object>) -> Value

Construct an object value.

Source

pub fn integer(value: i128) -> Value

Construct an integer value, narrowing to Value::Int when it fits.

Source

pub const fn is_null(&self) -> bool

Whether the value is explicit null.

Source

pub const fn kind(&self) -> &'static str

The name of the value’s GraphQL-ish kind, used in error messages.

Source

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

Borrow the value as a string.

Source

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

Borrow the value as a bool.

Source

pub const fn as_i32(&self) -> Option<i32>

Borrow the value as an i32.

A Value::BigInt also converts when it fits, so callers that accept the built-in Int range do not have to spell out both variants.

Source

pub const fn as_i64(&self) -> Option<i64>

Borrow the value as an i64.

Source

pub const fn as_i128(&self) -> Option<i128>

Borrow the value as an exact i128.

Source

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

Borrow the value as an f64.

Integers widen exactly as the Float scalar does. Values outside i128 are not representable by this type at all.

Source

pub fn as_object(&self) -> Option<&Object>

Borrow the value as an object.

Source

pub fn as_object_mut(&mut self) -> Option<&mut Object>

Mutably borrow the value as an object.

Source

pub fn as_list(&self) -> Option<&[Value]>

Borrow the value as a list.

Source

pub fn external<T>(value: T) -> Value
where T: Any + Send + Sync,

Wrap a model value for a type-safe high-level API.

Source

pub const fn is_external(&self) -> bool

Whether this is an opaque model value.

Source

pub fn as_external<T>(&self) -> Option<&T>
where T: Any,

Borrow an opaque model value as a concrete type.

Source

pub fn into_list(self) -> Option<Vec<Value>>

Turn the value into a list, if it is one.

Source

pub fn into_string(self) -> Option<Arc<str>>

Turn the value into a string, if it is one.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

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

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

impl Display for Value

Source§

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

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

impl From<&str> for Value

Source§

fn from(value: &str) -> Value

Converts to this type from the input type.
Source§

impl From<Arc<str>> for Value

Source§

fn from(value: Arc<str>) -> Value

Converts to this type from the input type.
Source§

impl From<Cow<'_, str>> for Value

Source§

fn from(value: Cow<'_, str>) -> Value

Converts to this type from the input type.
Source§

impl From<Object> for Value

Source§

fn from(value: Object) -> Value

Converts to this type from the input type.
Source§

impl<T> From<Option<T>> for Value
where T: Into<Value>,

Source§

fn from(value: Option<T>) -> Value

Converts to this type from the input type.
Source§

impl From<RawObject> for Value

Source§

fn from(value: RawObject) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(value: String) -> Value

Converts to this type from the input type.
Source§

impl From<Upload> for Value

Source§

fn from(value: Upload) -> Value

Converts to this type from the input type.
Source§

impl<T> From<Value> for Raw<T>

Source§

fn from(value: Value) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Value>> for Value

Source§

fn from(value: Vec<Value>) -> Value

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(value: bool) -> Value

Converts to this type from the input type.
Source§

impl From<f32> for Value

Source§

fn from(value: f32) -> Value

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(value: f64) -> Value

Converts to this type from the input type.
Source§

impl From<i8> for Value

Source§

fn from(value: i8) -> Value

Converts to this type from the input type.
Source§

impl From<i16> for Value

Source§

fn from(value: i16) -> Value

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(value: i32) -> Value

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(value: i64) -> Value

Converts to this type from the input type.
Source§

impl From<i128> for Value

Source§

fn from(value: i128) -> Value

Converts to this type from the input type.
Source§

impl From<u8> for Value

Source§

fn from(value: u8) -> Value

Converts to this type from the input type.
Source§

impl From<u16> for Value

Source§

fn from(value: u16) -> Value

Converts to this type from the input type.
Source§

impl From<u32> for Value

Source§

fn from(value: u32) -> Value

Converts to this type from the input type.
Source§

impl From<u64> for Value

Source§

fn from(value: u64) -> Value

Converts to this type from the input type.
Source§

impl PartialEq for Value

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for Value

Available on crate feature serde only.
Source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Value

Auto Trait Implementations§

§

impl !RefUnwindSafe for Value

§

impl !UnwindSafe for Value

§

impl Forget for Value

§

impl Freeze for Value

§

impl Move for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnsafeUnpin 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.