Skip to content

Replace ownership wrapper types with ZBox<T> #85

@davidcole1340

Description

@davidcole1340

Types such as ZendStr have an owned variant ZendString. This can be generically replaced with a type ZBox<T>, where T implements a new trait ZBoxable, which is implemented on Zend heap-allocated types, such as ZendStr, ZendObject and HashTable:

pub struct ZBox<T: ZBoxable>(NonNull<T>);

pub unsafe trait ZBoxable {
    fn free(&mut self) {
        // by default, just free the memory using the ZMM
        // downstream types like strings and objects can override with their respective release functions
        unsafe { efree(self) };
    }
}

ZBox will dereference to T, and downstream modules such as string can implement on ZBox<ZendStr>, such as impl TryFrom<String> for ZBox<ZendStr>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions