[][src]Struct zenoh::net::Session

pub struct Session { /* fields omitted */ }

A zenoh-net session.

Implementations

impl Session[src]

pub async fn close(__arg0: Self) -> ZResult<()>[src]

Close the zenoh-net Session.

Sessions are automatically closed when dropped, but you may want to use this function to handle errors or close the Session asynchronously.

Examples

use zenoh::net::*;

let session = open(config::peer()).await.unwrap();
session.close().await.unwrap();

pub async fn info<'_>(&'_ self) -> InfoProperties[src]

Get informations about the zenoh-net Session.

Examples

use zenoh::net::*;

let session = open(config::peer()).await.unwrap();
let info = session.info();

pub async fn declare_resource<'_, '_>(
    &'_ self,
    resource: &'_ ResKey
) -> ZResult<ResourceId>
[src]

Associate a numerical Id with the given resource key.

This numerical Id will be used on the network to save bandwidth and ease the retrieval of the concerned resource in the routing tables.

Arguments

  • resource - The resource key to map to a numerical Id

Examples

use zenoh::net::*;

let session = open(config::peer()).await.unwrap();
let rid = session.declare_resource(&"/resource/name".into()).await.unwrap();

pub async fn undeclare_resource<'_>(&'_ self, rid: ResourceId) -> ZResult<()>[src]

Undeclare the numerical Id/resource key association previously declared with declare_resource.

Arguments

  • rid - The numerical Id to unmap

Examples

use zenoh::net::*;

let session = open(config::peer()).await.unwrap();
let rid = session.declare_resource(&"/resource/name".into()).await.unwrap();
session.undeclare_resource(rid).await;

pub async fn declare_publisher<'_, '_, '_>(
    &'_ self,
    resource: &'_ ResKey
) -> ZResult<Publisher<'_>>
[src]

Declare a Publisher for the given resource key.

Written resources that match the given key will only be sent on the network if matching subscribers exist in the system.

Arguments

  • resource - The resource key to publish

Examples

use zenoh::net::*;

let session = open(config::peer()).await.unwrap();
let publisher = session.declare_publisher(&"/resource/name".into()).await.unwrap();
session.write(&"/resource/name".into(), "value".as_bytes().into()).await.unwrap();

pub async fn declare_subscriber<'_, '_, '_, '_>(
    &'_ self,
    resource: &'_ ResKey,
    info: &'_ SubInfo
) -> ZResult<Subscriber<'_>>
[src]

Declare a Subscriber for the given resource key.

Arguments

  • resource - The resource key to subscribe
  • info - The SubInfo to configure the subscription

Examples

use zenoh::net::*;
use futures::prelude::*;

let session = open(config::peer()).await.unwrap();
let sub_info = SubInfo {
    reliability: Reliability::Reliable,
    mode: SubMode::Push,
    period: None
};
let mut subscriber = session.declare_subscriber(&"/resource/name".into(), &sub_info).await.unwrap();
while let Some(sample) = subscriber.stream().next().await {
    println!("Received : {:?}", sample);
}

pub async fn declare_callback_subscriber<DataHandler, '_, '_, '_, '_>(
    &'_ self,
    resource: &'_ ResKey,
    info: &'_ SubInfo,
    data_handler: DataHandler
) -> ZResult<CallbackSubscriber<'_>> where
    DataHandler: FnMut(Sample) + Send + Sync + 'static, 
[src]

Declare a CallbackSubscriber for the given resource key.

Arguments

  • resource - The resource key to subscribe
  • info - The SubInfo to configure the subscription
  • data_handler - The callback that will be called on each data reception

Examples

use zenoh::net::*;

let session = open(config::peer()).await.unwrap();
let sub_info = SubInfo {
    reliability: Reliability::Reliable,
    mode: SubMode::Push,
    period: None
};
let subscriber = session.declare_callback_subscriber(&"/resource/name".into(), &sub_info,
    |sample| { println!("Received : {} {}", sample.res_name, sample.payload); }
).await.unwrap();

pub async fn declare_queryable<'_, '_, '_>(
    &'_ self,
    resource: &'_ ResKey,
    kind: ZInt
) -> ZResult<Queryable<'_>>
[src]

Declare a Queryable for the given resource key.

Arguments

Examples

use zenoh::net::*;
use zenoh::net::queryable::EVAL;
use futures::prelude::*;

let session = open(config::peer()).await.unwrap();
let mut queryable = session.declare_queryable(&"/resource/name".into(), EVAL).await.unwrap();
while let Some(query) = queryable.stream().next().await {
    query.reply(Sample{
        res_name: "/resource/name".to_string(),
        payload: "value".as_bytes().into(),
        data_info: None,
    }).await;
}

pub async fn write<'_, '_>(
    &'_ self,
    resource: &'_ ResKey,
    payload: RBuf
) -> ZResult<()>
[src]

Write data.

Arguments

  • resource - The resource key to write
  • payload - The value to write

Examples

use zenoh::net::*;

let session = open(config::peer()).await.unwrap();
session.write(&"/resource/name".into(), "value".as_bytes().into()).await.unwrap();

pub async fn write_ext<'_, '_>(
    &'_ self,
    resource: &'_ ResKey,
    payload: RBuf,
    encoding: ZInt,
    kind: ZInt,
    congestion_control: CongestionControl
) -> ZResult<()>
[src]

Write data with options.

Arguments

  • resource - The resource key to write
  • payload - The value to write
  • encoding - The encoding of the value
  • kind - The kind of value
  • congestion_control - The value for the congestion control

Examples

use zenoh::net::*;

let session = open(config::peer()).await.unwrap();
session.write_ext(&"/resource/name".into(), "value".as_bytes().into(), encoding::TEXT_PLAIN, data_kind::PUT, CongestionControl::Drop).await.unwrap();

pub async fn query<'_, '_, '_>(
    &'_ self,
    resource: &'_ ResKey,
    predicate: &'_ str,
    target: QueryTarget,
    consolidation: QueryConsolidation
) -> ZResult<Receiver<Reply>>
[src]

Query data from the matching queryables in the system.

Arguments

  • resource - The resource key to query
  • predicate - An indication to matching queryables about the queried data
  • target - The kind of queryables that should be target of this query
  • consolidation - The kind of consolidation that should be applied on replies

Examples

use zenoh::net::*;
use futures::prelude::*;

let session = open(config::peer()).await.unwrap();
let mut replies = session.query(
    &"/resource/name".into(),
    "predicate",
    QueryTarget::default(),
    QueryConsolidation::default()
).await.unwrap();
while let Some(reply) = replies.next().await {
    println!(">> Received {:?}", reply.data);
}

Trait Implementations

impl Debug for Session[src]

impl Drop for Session[src]

impl Primitives for Session[src]

Auto Trait Implementations

impl !RefUnwindSafe for Session

impl Send for Session

impl Sync for Session

impl Unpin for Session

impl !UnwindSafe for Session

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

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