objr_procmacro 1.0.0

procmacro crate for objr
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//SPDX-License-Identifier: MIT OR Apache-2.0

///Returns an implementation of ObjcInstance for type
pub fn instance_impl(_type: &str) -> String{
    format!(r#"
    impl ::objr::bindings::ObjcInstance for {TYPE} {{
        }}
        unsafe impl ::objr::bindings::Arguable for {TYPE} {{ }}
        impl std::fmt::Display for {TYPE} {{
            fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {{
                use ::objr::foundation::NSObjectTrait;
                //this ought to be safe, since the object was allocated somehow and we had an autoreleasepool for that.
                let fake_pool = unsafe {{ ::objr::bindings::ActiveAutoreleasePool::assume_autoreleasepool() }};
                write!(f, "{{}}",self.description(&fake_pool).to_str(&fake_pool))
            }}
        }}
    "#,TYPE=_type)
}