1- //! Bindings and abstractions for the Zend API to build PHP extensions natively in Rust.
2- //!
3- //! The library guide can be read [here.](https://davidcole1340.github.io/ext-php-rs/guide)
4-
1+ #![ doc = include_str ! ( "../README.md" ) ]
52#![ deny( clippy:: unwrap_used) ]
63#![ allow( non_upper_case_globals) ]
74#![ allow( non_camel_case_types) ]
@@ -23,12 +20,17 @@ pub mod php;
2320///
2421/// # Example
2522///
26- /// ```ignore
23+ /// ```
24+ /// # use ext_php_rs::prelude::*;
2725/// #[php_const]
2826/// const TEST_CONSTANT: i32 = 100;
2927///
3028/// #[php_const]
3129/// const ANOTHER_CONST: &str = "Hello, world!";
30+ /// # #[php_module]
31+ /// # pub fn module(module: ModuleBuilder) -> ModuleBuilder {
32+ /// # module
33+ /// # }
3234/// ```
3335pub use ext_php_rs_derive:: php_const;
3436
@@ -58,16 +60,22 @@ pub use ext_php_rs_derive::php_const;
5860/// can take either [`String`] or [`&str`], the optional parameter `offset` is an [`Option<i64>`],
5961/// and the return value is a [`Zval`] as the return type is an integer-boolean union.
6062///
61- /// ```ignore
63+ /// ```
64+ /// # use ext_php_rs::prelude::*;
65+ /// # use ext_php_rs::php::types::zval::Zval;
6266/// #[php_extern]
6367/// extern "C" {
6468/// fn strpos(haystack: &str, needle: &str, offset: Option<i64>) -> Zval;
6569/// }
6670///
6771/// #[php_function]
6872/// pub fn my_strpos() {
69- /// assert_eq!(unsafe { strpos("Hello", "e", None) }, 1 );
73+ /// assert_eq!(unsafe { strpos("Hello", "e", None) }.long(), Some(1) );
7074/// }
75+ /// # #[php_module]
76+ /// # pub fn module(module: ModuleBuilder) -> ModuleBuilder {
77+ /// # module
78+ /// # }
7179/// ```
7280///
7381/// [`strpos`]: https://www.php.net/manual/en/function.strpos.php
@@ -153,18 +161,24 @@ pub use ext_php_rs_derive::php_extern;
153161/// Creating a simple function which will return a string. The function still must be declared in
154162/// the PHP module to be able to call.
155163///
156- /// ```ignore
164+ /// ```
165+ /// # use ext_php_rs::prelude::*;
157166/// #[php_function]
158167/// pub fn hello(name: String) -> String {
159168/// format!("Hello, {}!", name)
160169/// }
170+ /// # #[php_module]
171+ /// # pub fn module(module: ModuleBuilder) -> ModuleBuilder {
172+ /// # module
173+ /// # }
161174/// ```
162175///
163176/// Parameters can also be deemed optional by passing the parameter name in the attribute options.
164177/// This function takes one required parameter (`hello`) and two optional parameters (`description`
165178/// and `age`).
166179///
167- /// ```ignore
180+ /// ```
181+ /// # use ext_php_rs::prelude::*;
168182/// #[php_function(optional = "description")]
169183/// pub fn hello(name: String, description: Option<String>, age: Option<i32>) -> String {
170184/// let mut response = format!("Hello, {}!", name);
@@ -179,26 +193,25 @@ pub use ext_php_rs_derive::php_extern;
179193///
180194/// response
181195/// }
196+ /// # #[php_module]
197+ /// # pub fn module(module: ModuleBuilder) -> ModuleBuilder {
198+ /// # module
199+ /// # }
182200/// ```
183201///
184202/// Defaults can also be given in a similar fashion. For example, the above function could have
185203/// default values for `description` and `age` by changing the attribute to the following:
186204///
187- /// ```ignore
205+ /// ```
206+ /// # use ext_php_rs::prelude::*;
188207/// #[php_function(optional = "description", defaults(description = "David", age = 10))]
189208/// pub fn hello(name: String, description: String, age: i32) -> String {
190- /// let mut response = format!("Hello, {}!", name);
191- ///
192- /// if let Some(description) = description {
193- /// response.push_str(format!(" {}.", description).as_ref());
194- /// }
195- ///
196- /// if let Some(age) = age {
197- /// response.push_str(format!(" I am {} year(s) old.", age).as_ref());
198- /// }
199- ///
200- /// response
209+ /// format!("Hello, {}! {}. I am {} year(s) old.", name, description, age)
201210/// }
211+ /// # #[php_module]
212+ /// # pub fn module(module: ModuleBuilder) -> ModuleBuilder {
213+ /// # module
214+ /// # }
202215/// ```
203216///
204217/// [`Result<T, E>`]: std::result::Result
@@ -245,7 +258,7 @@ pub use ext_php_rs_derive::php_function;
245258///
246259/// ```ignore
247260/// #[derive(Debug, Default, ZendObjectHandler)]
248- /// struct Human {
261+ /// pub struct Human {
249262/// name: String,
250263/// age: i32,
251264/// }
@@ -302,7 +315,8 @@ pub use ext_php_rs_derive::php_impl;
302315/// since the function is declared above the module it will automatically be registered when the
303316/// module attribute is called.
304317///
305- /// ```ignore
318+ /// ```
319+ /// # use ext_php_rs::prelude::*;
306320/// #[php_function]
307321/// pub fn hello(name: String) -> String {
308322/// format!("Hello, {}!", name)
@@ -330,11 +344,16 @@ pub use ext_php_rs_derive::php_module;
330344///
331345/// # Example
332346///
333- /// ```ignore
347+ /// ```
348+ /// # use ext_php_rs::prelude::*;
334349/// #[php_startup]
335350/// pub fn startup_function() {
336351/// // do whatever you need to do...
337352/// }
353+ /// # #[php_module]
354+ /// # pub fn module(module: ModuleBuilder) -> ModuleBuilder {
355+ /// # module
356+ /// # }
338357/// ```
339358pub use ext_php_rs_derive:: php_startup;
340359
0 commit comments