Skip to content

Commit 81dacc8

Browse files
committed
Add From<Vec<T>> for binary types, tidy up
1 parent 626c944 commit 81dacc8

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

example/skel/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,6 @@ pub fn module(module: ModuleBuilder) -> ModuleBuilder {
167167
#[php_extern]
168168
extern "C" {
169169
fn test_func<'a>() -> Callable<'a>;
170-
fn strpos2<'a>(haystack: &str, needle: &str, offset: Option<i32>) -> Zval;
171-
pub fn strpos<'a>(haystack: &str, needle: &str, offset: Option<i32>) -> Zval;
170+
fn strpos2(haystack: &str, needle: &str, offset: Option<i32>) -> Zval;
171+
pub fn strpos(haystack: &str, needle: &str, offset: Option<i32>) -> Zval;
172172
}

src/php/args.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,7 @@ impl<'a> Arg<'a> {
7171
/// This will be None until the ArgParser is used to parse
7272
/// the arguments.
7373
pub fn val<T: TryFrom<&'a Zval>>(&self) -> Option<T> {
74-
match self.zval {
75-
Some(zval) => match zval.try_into() {
76-
Ok(val) => Some(val),
77-
Err(_) => None,
78-
},
79-
None => None,
80-
}
74+
self.zval.and_then(|zv| zv.try_into().ok())
8175
}
8276

8377
/// Attempts to return a reference to the arguments internal Zval.

src/php/types/binary.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,9 @@ impl<T: Pack> From<Binary<T>> for Vec<T> {
7878
value.0
7979
}
8080
}
81+
82+
impl<T: Pack> From<Vec<T>> for Binary<T> {
83+
fn from(value: Vec<T>) -> Self {
84+
Self::new(value)
85+
}
86+
}

0 commit comments

Comments
 (0)