Just add docs

This commit is contained in:
Daniil Gentili 2023-10-21 23:21:23 +02:00
parent 924a99e73b
commit 8890767ba9
4 changed files with 7 additions and 64 deletions

View File

@ -83,10 +83,10 @@ jobs:
- name: Build
env:
EXT_PHP_RS_TEST: ""
run: cargo build --release --features closure,anyhow,async --all
run: cargo build --release --features closure,anyhow --all
# Test & lint
- name: Test inline examples
run: cargo test --release --all --features closure,anyhow,async
run: cargo test --release --all --features closure,anyhow
- name: Run rustfmt
if: matrix.rust == 'stable' && matrix.os == 'ubuntu-latest' && matrix.php == '8.2'
run: cargo fmt --all -- --check

View File

@ -5,7 +5,7 @@ repository = "https://github.com/davidcole1340/ext-php-rs"
homepage = "https://github.com/davidcole1340/ext-php-rs"
license = "MIT OR Apache-2.0"
keywords = ["php", "ffi", "zend"]
version = "0.10.4"
version = "0.10.3"
authors = ["David Cole <david.cole1340@gmail.com>"]
edition = "2018"
categories = ["api-bindings"]
@ -19,12 +19,10 @@ once_cell = "1.17"
anyhow = { version = "1", optional = true }
ext-php-rs-derive = { version = "=0.10.1", path = "./crates/macros" }
[target.'cfg(linux)'.dependencies]
php-tokio = { version = "=0.1.4", optional = true }
[dev-dependencies]
skeptic = "0.13"
reqwest = "0.11.22"
php-tokio = "0.1.4"
[build-dependencies]
anyhow = "1"
@ -43,7 +41,6 @@ zip = "0.6"
[features]
closure = []
embed = []
async = ["dep:php-tokio"]
[workspace]
members = ["crates/macros", "crates/cli"]

View File

@ -184,13 +184,9 @@ In this example, we're exposing an async Rust HTTP client library called [reqwes
This allows full compatibility with [amphp](https://amphp.org), [PSL](https://github.com/azjezz/psl), [reactphp](https://reactphp.org) and any other async PHP library based on [Revolt](https://revolt.run).
Currently, only Linux is supported by php-tokio.
```rust,no_run
# #![cfg(linux)]
# extern crate ext_php_rs;
# use ext_php_rs::prelude::*;
use php_tokio::EventLoop;
```rust,ignore
use ext_php_rs::prelude::*;
use php_tokio::{php_async_impl, EventLoop};
#[php_class]
struct Client {}
@ -217,8 +213,6 @@ pub extern "C" fn request_shutdown(_type: i32, _module_number: i32) -> i32 {
pub fn get_module(module: ModuleBuilder) -> ModuleBuilder {
module.request_shutdown_function(request_shutdown)
}
# fn main() {}
```
Here's the async PHP code we use to interact with the Rust class we just exposed.

View File

@ -48,8 +48,6 @@ pub mod prelude {
pub use crate::php_extern;
pub use crate::php_function;
pub use crate::php_impl;
#[cfg(any(docs, feature = "async"))]
pub use crate::php_async_impl;
pub use crate::php_module;
pub use crate::php_print;
pub use crate::php_println;
@ -392,52 +390,6 @@ pub use ext_php_rs_derive::php_function;
/// ```
pub use ext_php_rs_derive::php_impl;
/// Just like php_impl, annotates a structs `impl` block, declaring that
/// all methods and constants declared inside the `impl` block will be declared
/// as PHP methods and constants.
///
/// This variant of php_impl supports async Rust methods, using [php-tokio](https://github.com/danog/php-tokio)
/// to integrate [tokio](https://tokio.rs) with PHP fibers and the [Revolt](https://revolt.run) event loop,
/// compatible with [Amphp](https://amphp.org), [PSL](https://github.com/azjezz/psl) and any other async PHP library based on Revolt.
///
/// # Example
///
/// ```no_run
/// # #![cfg(linux)]
/// # use ext_php_rs::prelude::*;
/// use php_tokio::EventLoop;
///
/// #[php_class]
/// struct Client {}
///
/// #[php_async_impl]
/// impl Client {
/// pub fn init() -> PhpResult<u64> {
/// EventLoop::init()
/// }
/// pub fn wakeup() -> PhpResult<()> {
/// EventLoop::wakeup()
/// }
/// pub async fn get(url: &str) -> anyhow::Result<String> {
/// Ok(reqwest::get(url).await?.text().await?)
/// }
/// }
///
/// pub extern "C" fn request_shutdown(_type: i32, _module_number: i32) -> i32 {
/// EventLoop::shutdown();
/// 0
/// }
///
/// #[php_module]
/// pub fn get_module(module: ModuleBuilder) -> ModuleBuilder {
/// module.request_shutdown_function(request_shutdown)
/// }
///
/// pub fn main() {}
/// ```
#[cfg(any(docs, feature = "async"))]
pub use php_tokio::php_async_impl;
/// Annotates a function that will be used by PHP to retrieve information about
/// the module.
///