Add From<Vec<T>> for binary types, tidy up

This commit is contained in:
David Cole 2021-08-20 16:19:07 +12:00
parent 626c944218
commit 81dacc8cb0
3 changed files with 9 additions and 9 deletions

View File

@ -167,6 +167,6 @@ pub fn module(module: ModuleBuilder) -> ModuleBuilder {
#[php_extern]
extern "C" {
fn test_func<'a>() -> Callable<'a>;
fn strpos2<'a>(haystack: &str, needle: &str, offset: Option<i32>) -> Zval;
pub fn strpos<'a>(haystack: &str, needle: &str, offset: Option<i32>) -> Zval;
fn strpos2(haystack: &str, needle: &str, offset: Option<i32>) -> Zval;
pub fn strpos(haystack: &str, needle: &str, offset: Option<i32>) -> Zval;
}

View File

@ -71,13 +71,7 @@ impl<'a> Arg<'a> {
/// This will be None until the ArgParser is used to parse
/// the arguments.
pub fn val<T: TryFrom<&'a Zval>>(&self) -> Option<T> {
match self.zval {
Some(zval) => match zval.try_into() {
Ok(val) => Some(val),
Err(_) => None,
},
None => None,
}
self.zval.and_then(|zv| zv.try_into().ok())
}
/// Attempts to return a reference to the arguments internal Zval.

View File

@ -78,3 +78,9 @@ impl<T: Pack> From<Binary<T>> for Vec<T> {
value.0
}
}
impl<T: Pack> From<Vec<T>> for Binary<T> {
fn from(value: Vec<T>) -> Self {
Self::new(value)
}
}