Proc

Struct Proc 

Source
pub struct Proc { /* private fields */ }
Expand description

A remote procedure published in netidx

Implementations§

Source§

impl Proc

Source

pub fn new<T: Send + 'static, F: FnMut(RpcCall) -> Option<T> + Send + 'static>( publisher: &Publisher, name: Path, doc: Value, args: impl IntoIterator<Item = ArgSpec>, map: F, handler: Option<Sender<T>>, ) -> Result<Proc>

Publish a new remote procedure. If successful this will return a Proc which, if dropped, will cause the removal of the procedure from netidx.

§Arguments
  • publisher - A reference to the publisher that will publish the procedure.
  • name - The path of the procedure in netidx.
  • doc - The procedure level doc string to be published along with the procedure
  • args - An iterator containing the procedure arguments
  • map - A function that will map the raw parameters into the type of the channel. if it returns None then nothing will be pushed into the channel.
  • handler - The channel that will receive the rpc call invocations (if any)

If you can handle the procedure entirely without async (or blocking) then you only need to define map, you don’t need to pass a handler channel. Your map function should handle the call, reply to the client, and return None.

If you need to do something async in order to handle the call, then you must pass an mpsc channel that will receive the output of your map function. You can define as little or as much slack as you desire, however be aware that if the channel fills up then clients attempting to call your procedure will wait.

§Example
#[macro_use] extern crate netidx_protocols;
use netidx::{path::Path, subscriber::Value};
use netidx_protocols::rpc::server::{Proc, ArgSpec, RpcCall};
use arcstr::ArcStr;
    let echo = define_rpc!(
        &publisher,
        Path::from("/examples/api/echo"),
        "echos it's argument",
        |mut c: RpcCall, arg: Value| -> Option<()> {
            c.reply.send(arg);
            None
        },
        None,
        arg: Value = Value::Null; "argument to echo"
    );
§Notes

If more than one publisher is publishing the same compatible RPC (same arguments, same name, hopefully the same semantics!), then clients will randomly pick one procedure from the set at client creation time.

Arguments with the same key that are specified multiple times will overwrite previous versions; the procedure will receive only the last version set. *

Source

pub fn new_with_flags<T: Send + 'static, F: FnMut(RpcCall) -> Option<T> + Send + 'static>( publisher: &Publisher, flags: PublishFlags, name: Path, doc: Value, args: impl IntoIterator<Item = ArgSpec>, map: F, handler: Option<Sender<T>>, ) -> Result<Proc>

Source

pub fn id(&self) -> ProcId

Get the rpc procedure id

Trait Implementations§

Source§

impl Debug for Proc

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Proc

§

impl !RefUnwindSafe for Proc

§

impl Send for Proc

§

impl Sync for Proc

§

impl Unpin for Proc

§

impl !UnwindSafe for Proc

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> 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> 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 = 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V