From 267a8855c2285433e5ca0cbea9ea57f22d591b29 Mon Sep 17 00:00:00 2001 From: Simon Gomizelj Date: Thu, 23 Sep 2021 02:02:52 -0400 Subject: [PATCH] Add a tentative Display trait implementation for ZendObject Possibly a bad idea as it can panic. Probably best to explicitly cast before displaying. --- src/php/types/object.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/php/types/object.rs b/src/php/types/object.rs index b33346832..07acd12bf 100644 --- a/src/php/types/object.rs +++ b/src/php/types/object.rs @@ -3,7 +3,7 @@ use std::{ convert::TryInto, - fmt::Debug, + fmt::{self, Debug}, marker::PhantomData, mem::{self, MaybeUninit}, ops::{Deref, DerefMut}, @@ -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::().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,