#[repr(C)]pub struct DiplomatWriteable { /* private fields */ }Expand description
An object that can one can write UTF-8 strings to
This allows the C API to write to arbitrary kinds of objects, for example a C++ std::string or a char buffer.
The way to use this object is to fill out the buf, len, cap fields with
appropriate values for the buffer, its current length, and its current capacity,
and flush and grow with appropriate callbacks (using context to reference any
state they need). This object will be passed by mutable reference to the Rust side,
and Rust will write to it, calling grow() as necessary. Once done, it will call flush()
to update any state on context (e.g. adding a null terminator, updating the length).
The object on the foreign side will be directly usable after this, the foreign side
need not perform additional state updates after passing an DiplomatWriteable to
a function.
[diplomat_simple_writeable()] can be used to write to a fixed-size char buffer.
May be extended in the future to support further invariants
DiplomatWriteable will not perform any cleanup on context or buf, these are logically
“borrows” from the FFI side.
§Safety invariants:
flush()andgrow()will be passedselfincludingcontextand it should always be safe to do so.contextmay be null, howeverflush()andgrow()must then be ready to receive it as such.bufmust becapbytes longgrow()must either return false or updatebufandcapfor a valid buffer of at least the requested buffer sizeDiplomatWriteable::flush()will be automatically called by Diplomat.flush()might also be called (erroneously) on the Rust side (it’s a public method), so it must be idempotent.
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DiplomatWriteable
impl RefUnwindSafe for DiplomatWriteable
impl !Send for DiplomatWriteable
impl !Sync for DiplomatWriteable
impl Unpin for DiplomatWriteable
impl UnwindSafe for DiplomatWriteable
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 48 bytes