Struct RpcServiceImplDefines

Source
pub struct RpcServiceImplDefines<'a> {
    pub service: &'a RpcService,
    pub extra_args: &'a [(&'a str, &'a str)],
    pub on_invalid_request_cb: &'a str,
    pub is_size_prefixed: bool,
    pub default_message_limit: &'a str,
}
Expand description

Generates module file interface to parse and forward flatbuffer requests to user’s created modules’ functions

Generated code has following requirements:

§Dependencies

  • flatbuffers - To parse and generate flatbuffer
  • xxhash-rust - To generate efficient method dispatcher using 128bit hashes. Needs features xxh3 and const_xxh3

§User modules

Assuming schema has two methods daily and transform_new_image, file will import following modules and functions:

mod daily;
pub use daily::daily;
mod transform_new_image;
pub use transform_new_image::transform_new_image;

§Module function signature:

pub async fn daily<'a, 'b>(
    rpc_argument: &Request,
    mandatory_flatbuffer_builder: &'b mut FlatBufferBuilder<'a>,
    extra_arg: &ExtraArgument,
) -> Result<ResponseBuilder<'a, 'b>, CommonError> {

§Result type

In above example ResponseBuilder MUST be builder struct generated by flatc which uses mandatory_flatbuffer_builder

§Error type

In above example CommonError must implement following method:

impl Error {
    #[inline]
    ///Creates flatbuffer error object
    pub fn to_interface<'a>(
        &self,
        builder: &mut flatbuffers::FlatBufferBuilder<'a>,
    ) -> flatbuffers::WIPOffset<interface::Error<'a>> {
     todo!()
    }
}

Where interface::Error MUST be flatbuffer struct generated by flatc

§Dispatch signature

As result following signature will be generated:

pub async fn dispatch(extra_arg: &ExtraArgument, method: &str, input: &[u8], builder: &mut flatbuffers::FlatBufferBuilder<'_>) -> Option<Result<(), ()>>;

Where return result indicates following:

None - Unknown method Some(Ok(())) - RPC call dispatched successfully, result is written to builder Some(Err(())) - RPC call failed, error is written to builder

Fields§

§service: &'a RpcService

Service definition

§extra_args: &'a [(&'a str, &'a str)]

Extra arguments to define in dispatch and pass to every RPC method

Following names are used by code generator:

  • method
  • input
  • builder
§on_invalid_request_cb: &'a str

Callback to be called when RPC input cannot be parsed

Must have following signature

fn on_invalid_request(builder: &mut flatbuffers::FlatBufferBuilder, error: flatbuffers::InvalidFlatbuffer) -> Option<Result<(), ()>>;
§is_size_prefixed: bool

Specifies whether flatbuffers input and output MUST be prefixed with size.

Namely it increases size of message by adding header with size when set to true.

§default_message_limit: &'a str

Defines constant to limit flatbuffer message size.

Trait Implementations§

Source§

impl<'a> Clone for RpcServiceImplDefines<'a>

Source§

fn clone(&self) -> RpcServiceImplDefines<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Display for RpcServiceImplDefines<'a>

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Copy for RpcServiceImplDefines<'a>

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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.