Skip to main content

fmt_object_ref

Function fmt_object_ref 

Source
pub fn fmt_object_ref<T: ObjectRefCore>(
    this: &T,
    f: &mut Formatter<'_>,
) -> Result
Expand description

Format a managed reference as its runtime type key and object address, as the Debug implementation of #[derive(ObjectRef)] does.

Call it from Debug for a reference type implemented by hand, such as a typed view over another reference, so that downcast(..).unwrap() and assert_eq! can print it.

use tvm_ffi::object::{fmt_object_ref, ObjectRef};
use tvm_ffi::Array;
struct Shown(ObjectRef);
impl std::fmt::Debug for Shown {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        fmt_object_ref(&self.0, f)
    }
}
let shown = Shown(Array::from_vec(vec![1_i64]).into());
assert!(format!("{shown:?}").starts_with("ffi.Array@"));