From 81dacc8cb03ccadd2bb0d0485a107b868f0ec3e1 Mon Sep 17 00:00:00 2001 From: David Cole Date: Fri, 20 Aug 2021 16:19:07 +1200 Subject: [PATCH] Add `From>` for binary types, tidy up --- example/skel/src/lib.rs | 4 ++-- src/php/args.rs | 8 +------- src/php/types/binary.rs | 6 ++++++ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/example/skel/src/lib.rs b/example/skel/src/lib.rs index 69b99d6..34ff8d4 100644 --- a/example/skel/src/lib.rs +++ b/example/skel/src/lib.rs @@ -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) -> Zval; - pub fn strpos<'a>(haystack: &str, needle: &str, offset: Option) -> Zval; + fn strpos2(haystack: &str, needle: &str, offset: Option) -> Zval; + pub fn strpos(haystack: &str, needle: &str, offset: Option) -> Zval; } diff --git a/src/php/args.rs b/src/php/args.rs index 09209be..f04e55f 100644 --- a/src/php/args.rs +++ b/src/php/args.rs @@ -71,13 +71,7 @@ impl<'a> Arg<'a> { /// This will be None until the ArgParser is used to parse /// the arguments. pub fn val>(&self) -> Option { - 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. diff --git a/src/php/types/binary.rs b/src/php/types/binary.rs index a573e34..30b2331 100644 --- a/src/php/types/binary.rs +++ b/src/php/types/binary.rs @@ -78,3 +78,9 @@ impl From> for Vec { value.0 } } + +impl From> for Binary { + fn from(value: Vec) -> Self { + Self::new(value) + } +}