Skip to main content

PhpBridgeGenerator

Struct PhpBridgeGenerator 

Source
pub struct PhpBridgeGenerator {
    pub core_import: String,
    pub type_paths: HashMap<String, String>,
    pub error_type: String,
    pub struct_param_types: HashSet<String>,
    pub struct_return_types: HashSet<String>,
    pub forwardable_defaulted: HashSet<String>,
}
Expand description

PHP-specific trait bridge generator. Implements code generation for bridging PHP objects to Rust traits.

Fields§

§core_import: String

Core crate import path (e.g., "sample_core").

§type_paths: HashMap<String, String>

Map of type name → fully-qualified Rust path for type references.

§error_type: String

Error type name (e.g., "SampleCrateError").

§struct_param_types: HashSet<String>

Callback-param type names that get NATIVE-object marshalling — known serde structs per the shared crate::codegen::generators::trait_bridge::is_native_marshalled_struct rule. For such a param the bridge constructs the binding’s native PHP object (the #[php_class] wrapper, via the same From<core::T> conversion used for return values) and hands THAT to the PHP method as a Zval, instead of serializing the param to a JSON string. Enums, opaque/handle types, and excluded/unknown Named params are absent and keep their prior JSON-string representation.

§struct_return_types: HashSet<String>

Callback-RETURN type names that get NATIVE-object marshalling — known serde structs returned directly by a method, gated to those with a generated From<Binding> for core conversion. For such a return the bridge first extracts the host’s native #[php_class] object via FromZval and converts via From<Binding>, falling back to the val.string() + serde path.

§forwardable_defaulted: HashSet<String>

Rust-defaulted trait methods the bridge forwards to the host when the PHP object’s class defines them (per the shared forwardable_defaulted_method_names rule). Methods absent here keep the trait’s Rust default unconditionally.

Trait Implementations§

Source§

impl TraitBridgeGenerator for PhpBridgeGenerator

Source§

fn gen_lifecycle_presence_check( &self, method: &MethodDef, _spec: &TraitBridgeSpec<'_>, ) -> Option<String>

Presence-check expression for a Plugin lifecycle method (initialize, shutdown) synthesized by the super-trait impl. Read more
Source§

fn gen_method_presence_check( &self, method: &MethodDef, _spec: &TraitBridgeSpec<'_>, ) -> Option<String>

Presence-check expression for a Rust-defaulted trait method. Read more
Source§

fn foreign_object_type(&self) -> &str

The type of the wrapped foreign object (e.g., "Py<PyAny>", "ThreadsafeFunction").
Source§

fn bridge_imports(&self) -> Vec<String>

Additional use imports needed for the bridge code.
Source§

fn gen_sync_method_body( &self, method: &MethodDef, spec: &TraitBridgeSpec<'_>, ) -> String

Generate the body of a synchronous method bridge. Read more
Source§

fn gen_async_method_body( &self, method: &MethodDef, spec: &TraitBridgeSpec<'_>, ) -> String

Generate the body of an async method bridge. Read more
Source§

fn gen_constructor(&self, spec: &TraitBridgeSpec<'_>) -> String

Generate the constructor body that validates and wraps the foreign object. Read more
Source§

fn gen_unregistration_fn(&self, spec: &TraitBridgeSpec<'_>) -> String

Generate an unregistration function for the bridge. Read more
Source§

fn gen_clear_fn(&self, spec: &TraitBridgeSpec<'_>) -> String

Generate a clear-all-plugins function for the bridge. Read more
Source§

fn gen_registration_fn(&self, spec: &TraitBridgeSpec<'_>) -> String

Generate the complete registration function including attributes, signature, and body. Read more
Source§

fn async_trait_is_send(&self) -> bool

Whether the #[async_trait] macro should require Send on its futures. Read more
Source§

fn extra_bridge_fields( &self, _spec: &TraitBridgeSpec<'_>, ) -> Vec<(String, String)>

Extra fields on the wrapper struct, as (name, rust_type) pairs. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more