Skip to content

Commit

Permalink
Add a tentative Display trait implementation for ZendObject
Browse files Browse the repository at this point in the history
Possibly a bad idea as it can panic. Probably best to explicitly cast
before displaying.
  • Loading branch information
vodik committed Sep 23, 2021
1 parent 99f029d commit 267a885
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/php/types/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::{
convert::TryInto,
fmt::Debug,
fmt::{self, Debug},
marker::PhantomData,
mem::{self, MaybeUninit},
ops::{Deref, DerefMut},
Expand Down Expand Up @@ -238,6 +238,16 @@ impl Debug for ZendObject {
}
}

impl fmt::Display for ZendObject {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}",
self.extract::<String>().expect("Failed to cast to string")
)
}
}

/// Wrapper struct used to return a reference to a PHP object.
pub struct ClassRef<'a, T: RegisteredClass> {
ptr: &'a mut ZendClassObject<T>,
Expand Down

0 comments on commit 267a885

Please sign in to comment.