pub struct NodeBridge { /* private fields */ }
Expand description
The Bridge between node and rust.
Implementations§
Source§impl NodeBridge
impl NodeBridge
Sourcepub fn new() -> NodeBridge
pub fn new() -> NodeBridge
Creates a bridge between node and rust. There can be only 1 bridge per rust program.
Sourcepub fn send<T: ToString, F: ToString>(
&self,
channel_name: T,
data: F,
) -> Result<(), BridgeClosedError>
pub fn send<T: ToString, F: ToString>( &self, channel_name: T, data: F, ) -> Result<(), BridgeClosedError>
Sends a message through a channel to node. Results with an Err(BridgeClosedError) if the bridge is already closed.
assert_eq!(bridge.send("channel_foo", "bar"), Ok(()));
bridge.close().await;
assert_eq!(bridge.send("channel_foo", "bar"), Err(BridgeClosedError));
Sourcepub async fn wait_until_closes(&self)
pub async fn wait_until_closes(&self)
Waits until the bridge is closed in some way to prevent it from closing on its own.
Sourcepub async fn receive<T: ToString>(
&self,
channel_name: T,
) -> Result<String, BridgeClosedError>
pub async fn receive<T: ToString>( &self, channel_name: T, ) -> Result<String, BridgeClosedError>
Receives a message through a channel from node. Results with an Err(BridgeClosedError) if the bridge is already closed.
bridge.receive("channel_foo").await.unwrap();
bridge.close().await;
assert_eq!(bridge.receive("channel_foo").await, Err(BridgeClosedError));
Sourcepub fn register<T: ToString + 'static, D: Send + 'static + Clone, B: FromStr + 'static>(
&self,
name: &str,
function: fn(Vec<B>, Option<D>) -> T,
pass_data: Option<D>,
)
pub fn register<T: ToString + 'static, D: Send + 'static + Clone, B: FromStr + 'static>( &self, name: &str, function: fn(Vec<B>, Option<D>) -> T, pass_data: Option<D>, )
Registers a sync function that can be called from node as long as the bridge is not closed.
Sourcepub fn register_async<T: ToString, F, D>(
&self,
name: &str,
function: F,
pass_data: Option<D>,
)
pub fn register_async<T: ToString, F, D>( &self, name: &str, function: F, pass_data: Option<D>, )
Registers an async function that can be called from node as long as the bridge is not closed.
Trait Implementations§
Source§impl Clone for NodeBridge
impl Clone for NodeBridge
Source§fn clone(&self) -> NodeBridge
fn clone(&self) -> NodeBridge
Returns a duplicate of the value. Read more
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for NodeBridge
impl RefUnwindSafe for NodeBridge
impl Send for NodeBridge
impl Sync for NodeBridge
impl Unpin for NodeBridge
impl UnwindSafe for NodeBridge
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
Mutably borrows from an owned value. Read more