mirror of
https://github.com/danog/ext-php-rs.git
synced 2024-12-02 09:37:51 +01:00
Add feature to convert anyhow errors to PHP exceptions (#110)
This commit is contained in:
parent
6fd31621f2
commit
c12dde1866
@ -15,6 +15,7 @@ exclude = ["/.github", "/.crates", "/guide"]
|
|||||||
bitflags = "1.2.1"
|
bitflags = "1.2.1"
|
||||||
parking_lot = "0.11.2"
|
parking_lot = "0.11.2"
|
||||||
cfg-if = "1.0"
|
cfg-if = "1.0"
|
||||||
|
anyhow = { version = "1", optional = true }
|
||||||
ext-php-rs-derive = { version = "=0.7.1", path = "./crates/macros" }
|
ext-php-rs-derive = { version = "=0.7.1", path = "./crates/macros" }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
@ -115,6 +115,15 @@ See the following links for the dependency crate requirements:
|
|||||||
- [`cc`](https://github.com/alexcrichton/cc-rs#compile-time-requirements)
|
- [`cc`](https://github.com/alexcrichton/cc-rs#compile-time-requirements)
|
||||||
- [`bindgen`](https://rust-lang.github.io/rust-bindgen/requirements.html)
|
- [`bindgen`](https://rust-lang.github.io/rust-bindgen/requirements.html)
|
||||||
|
|
||||||
|
## Cargo Features
|
||||||
|
|
||||||
|
All features are disabled by default.
|
||||||
|
|
||||||
|
- `closure` - Enables the ability to return Rust closures to PHP. Creates a new
|
||||||
|
class type, `RustClosure`.
|
||||||
|
- `anyhow` - Implements `Into<PhpException>` for `anyhow::Error`, allowing you
|
||||||
|
to return anyhow results from PHP functions. Supports anyhow v1.x.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
This project only works for PHP >= 8.0 (for now). Due to the fact that the PHP
|
This project only works for PHP >= 8.0 (for now). Due to the fact that the PHP
|
||||||
|
@ -78,6 +78,13 @@ impl From<&str> for PhpException {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "anyhow")]
|
||||||
|
impl From<anyhow::Error> for PhpException {
|
||||||
|
fn from(err: anyhow::Error) -> Self {
|
||||||
|
Self::new(err.to_string(), 0, crate::zend::ce::exception())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Throws an exception with a given message. See [`ClassEntry`] for some
|
/// Throws an exception with a given message. See [`ClassEntry`] for some
|
||||||
/// built-in exception types.
|
/// built-in exception types.
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user