Module interoptopus::patterns::service [−][src]
Expand description
Bundles function with common receiver into a class
or service in object oriented languages.🚧
Services are defined via the pattern_service_manual macro and consists of the following items:
- an opaque receiver type,
- a constructor function of signature
fn(mmR, ...) -> E
- destructor function of signature
unsafe fn(mmR) -> E
- arbitrary many methods of signature
fn(mR, ...) -> ?
where
mmR
refers to a&mut *mut Receiver
,*mut *mut Receiver
orOption<&mut *mut Receiver>
,mR
refers to a&mut Receiver
,*mut Receiver
orOption<&mut Receiver>
,E
to a success enum,...
ane?
to arbitrary types.
The constructor:
- must return
E::SUCCESS
if and only if it successfully wrote an instance ofReceiver
intommR
- may only write a valid instance or leave the parameter at
null
The unsafe
destructor:
- must handle any values produced by a constructor that successfully returned,
- if it successfully completes, it must write a null pointer into
mmR
,
Violation of any of these conditions may cause UB in FFI calls as the generated bindings rely on this contract. In addition the bindings will guarantee (and the destructor’s signature should indicate) that it
- will only invoked if the constructor returned
E::SUCCESS
, - the value for
mmR
will be exactly the value returned by a previous constructor invocation,
Structs
Combines a receiver, constructor, destructor and multiple methods in one entity.
Traits
For types that can be returned by a generated service what to return when things went wrong?