Skip to main content

ext_php_rs/types/
mod.rs

1//! Types defined by the Zend engine used in PHP.
2//!
3//! Generally, it is easier to work directly with Rust types, converting into
4//! these PHP types when required.
5
6pub mod array;
7mod callable;
8mod class_object;
9mod iterable;
10mod iterator;
11mod long;
12mod object;
13mod php_ref;
14mod separated;
15mod string;
16mod zval;
17
18pub use array::{ArrayKey, Entry, OccupiedEntry, VacantEntry, ZendEmptyArray, ZendHashTable};
19pub use callable::ZendCallable;
20pub use class_object::ZendClassObject;
21pub use iterable::Iterable;
22pub use iterator::ZendIterator;
23pub use long::ZendLong;
24pub use object::{PropertyQuery, ZendObject};
25pub use php_ref::PhpRef;
26pub use separated::Separated;
27pub use string::ZendStr;
28pub use zval::Zval;
29
30use crate::{convert::FromZval, flags::DataType};
31
32into_zval!(f32, set_double, Double);
33into_zval!(f64, set_double, Double);
34into_zval!(bool, set_bool, Bool);
35
36try_from_zval!(f64, double, Double);
37try_from_zval!(bool, bool, Bool);
38
39impl FromZval<'_> for f32 {
40    const TYPE: DataType = DataType::Double;
41
42    fn from_zval(zval: &Zval) -> Option<Self> {
43        #[allow(clippy::cast_possible_truncation)]
44        zval.double().map(|v| v as f32)
45    }
46}