Skip to main content

Value

Enum Value 

Source
pub enum Value<X: Extension = Never> {
    Null,
    Bool(bool),
    Int(i64),
    Float(f64),
    Str(Str),
    Array(Array<X>),
    Object(Array<X>),
    Ext(X),
}
Expand description

A PHP value.

Variants§

§

Null

PHP null.

§

Bool(bool)

A PHP bool.

§

Int(i64)

A PHP int.

§

Float(f64)

A PHP float.

§

Str(Str)

A PHP string, as bytes.

§

Array(Array<X>)

A PHP array.

§

Object(Array<X>)

A stdClass instance: its properties in order (string keys, not normalised).

§

Ext(X)

An object of another class.

Implementations§

Source§

impl<X: Extension> Value<X>

Source

pub fn type_name(&self) -> &'static str

gettype().

Source

pub fn debug_type(&self) -> &str

get_debug_type().

Source

pub fn truthy(&self) -> bool

(bool) $v (zend_is_true).

Source

pub fn to_php_string(&self) -> Result<Str, EngineError>

(string) $v (zval_get_string): floats at the precision setting, arrays "Array" (PHP also warns); objects throw Error.

Source

pub fn to_double(&self) -> f64

(float) $v (zval_get_double): strings by their leading number, arrays 0.0 or 1.0, objects 1.0 (PHP warns).

Source

pub fn loose_eq(&self, o: &Self) -> bool

PHP 8 $a == $b.

Source

pub fn strict_eq(&self, o: &Self) -> bool

$a === $b: same type and value; arrays with the same keys in the same order and identical values. Objects are never identical (see the module docs).

Source

pub fn cmp_php(&self, o: &Self) -> Ordering

PHP 8 $a <=> $b. Uncomparable values (an array missing a key of the other, objects of different classes, NaN) are Greater, as in PHP.

Source

pub fn compare(&self, o: &Self) -> i32

zend_compare: -1, 0 or 1 (1 also for uncomparable values).

Source

pub fn from_json(v: &Json) -> Self

The request-model value of JSON, as Utopia\Http\Request decodes a body: objects are arrays (keys normalised), except empty ones, which stay stdClass; integers beyond i64 are floats.

Source

pub fn to_json(&self) -> Json

JSON for this value: lists are arrays, other arrays and objects are objects (integer keys as strings). Lossy where JSON cannot hold the value: invalid UTF-8 becomes U+FFFD and non-finite floats null. Use crate::json::encode for PHP’s exact json_encode.

Source§

impl<X: Extension> Value<X>

Source

pub fn try_to_json(&self) -> Option<Json>

The request-model JSON of this value, exactly: like Value::to_json (lists are arrays, other arrays and objects are objects with integer keys as strings, an extension object its to_array()), but None where JSON cannot hold the value: a non-finite float, or a string or key that is not UTF-8.

use php_std::{Str, Value};
use serde_json::json;

let list: Value = Value::from_json(&json!(["a", {"b": 1}]));
assert_eq!(list.try_to_json(), Some(json!(["a", {"b": 1}])));
assert_eq!(Value::<php_std::Never>::Str(Str::copy_from(&[0xff])).try_to_json(), None);
assert_eq!(Value::<php_std::Never>::Float(f64::INFINITY).try_to_json(), None);

Trait Implementations§

Source§

impl<X: Clone + Extension> Clone for Value<X>

Source§

fn clone(&self) -> Self

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<X: Debug + Extension> Debug for Value<X>

Source§

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

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

impl<X: Extension> Default for Value<X>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<X: Extension> From<&str> for Value<X>

Source§

fn from(s: &str) -> Self

A PHP string with the bytes of s.

Source§

impl<X: Extension> From<Array<X>> for Value<X>

Source§

fn from(a: Array<X>) -> Self

A PHP array.

Source§

impl<X: Extension> From<Str> for Value<X>

Source§

fn from(s: Str) -> Self

A PHP string.

Source§

impl<X: Extension> From<bool> for Value<X>

Source§

fn from(b: bool) -> Self

A PHP bool.

Source§

impl<X: Extension> From<f64> for Value<X>

Source§

fn from(f: f64) -> Self

A PHP float.

Source§

impl<X: Extension> From<i64> for Value<X>

Source§

fn from(i: i64) -> Self

A PHP int.

Source§

impl<X: Extension> FromIterator<Value<X>> for Array<X>

A list.

Source§

fn from_iter<T: IntoIterator<Item = Value<X>>>(iter: T) -> Self

A list of the values.

Source§

impl<X: PartialEq + Extension> PartialEq for Value<X>

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl<X: PartialEq + Extension> StructuralPartialEq for Value<X>

Auto Trait Implementations§

§

impl<X = Never> !Freeze for Value<X>

§

impl<X> Forget for Value<X>

§

impl<X> Move for Value<X>

§

impl<X> RefUnwindSafe for Value<X>

§

impl<X> Send for Value<X>
where Array<X>: Send,

§

impl<X> Sync for Value<X>
where Array<X>: Sync,

§

impl<X> Unpin for Value<X>
where X: Unpin, Array<X>: Unpin,

§

impl<X> UnsafeUnpin for Value<X>

§

impl<X> UnwindSafe for Value<X>
where Array<X>: UnwindSafe, X: UnwindSafe,

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> Same for T

Source§

type Output = T

Should always be Self
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, 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.