Struct minint::NtConn

source ·
pub struct NtConn {
    pub(crate) next_id: Arc<Mutex<i32>>,
    pub(crate) incoming_abort: Option<AbortHandle>,
    pub(crate) outgoing_abort: Option<AbortHandle>,
    pub(crate) c2s: UnboundedSender<Message>,
    pub(crate) topics: Arc<Mutex<HashMap<i32, String>>>,
    pub(crate) topic_pubuids: Arc<Mutex<HashMap<i32, i32>>>,
    pub(crate) pubuid_topics: Arc<Mutex<HashMap<i32, i32>>>,
    pub(crate) values: Arc<Mutex<HashMap<i32, Data>>>,
}
Expand description

A NetworkTables connection

Fields§

§next_id: Arc<Mutex<i32>>

Next sequential ID

§incoming_abort: Option<AbortHandle>

Incoming request receiver event loop abort handle

§outgoing_abort: Option<AbortHandle>

Outgoing request sender event loop abort handle

§c2s: UnboundedSender<Message>

Outgoing client-to-server message queue

§topics: Arc<Mutex<HashMap<i32, String>>>§topic_pubuids: Arc<Mutex<HashMap<i32, i32>>>§pubuid_topics: Arc<Mutex<HashMap<i32, i32>>>§values: Arc<Mutex<HashMap<i32, Data>>>

Implementations§

source§

impl NtConn

source

pub async fn new( server: impl Into<IpAddr>, client_ident: impl Into<String>, ) -> Result<Self, Box<dyn Error>>

Connect to a NetworkTables server

§Arguments
  • server - The IP address of the NetworkTables server.
  • client_ident - The client identifier to use for this connection.
§Examples
use minint::NtConn;

#[tokio::main]
async fn main() {
    // Connect to the NetworkTables server at 10.0.0.2
    let conn = NtConn::new("10.0.0.2", "my_client").await.unwrap();

    // ...
}
source

pub(crate) async fn next_id(&self) -> i32

source

pub async fn publish<T: DataType>( &self, name: impl Into<String>, ) -> Result<NtTopic<'_, T>, Box<dyn Error>>

Publish a topic

The topic will be unpublished when the NtTopic is dropped.

§Arguments
  • name - The name of the topic to publish.
§Type Parameters
  • T - The type of data to be published on the topic. Must implement the DataType trait.
§Examples
use minint::{NtConn, datatype::DataType};

#[tokio::main]
async fn main() {
    // Connect to the NetworkTables server
    let conn = NtConn::new("10.0.0.2", "my_client").await.unwrap();

    // Publish a new topic named "my_topic" with data type f64
    let mut topic = conn.publish::<f64>("my_topic").await.unwrap();

    // ...
}
source

pub(crate) fn unpublish(&self, pubuid: i32) -> Result<(), Box<dyn Error>>

Unpublish topic

This method is typically called when an NtTopic is dropped.

source

pub async fn subscribe( &self, topic: &str, ) -> Result<NtSubscription<'_>, Box<dyn Error>>

Subscribe to a topic

§Arguments
  • topic - The name of the topic to subscribe to.
§Examples
use minint::NtConn;

#[tokio::main]
async fn main() {
    // Connect to the NetworkTables server
    let conn = NtConn::new("10.0.0.2", "my_client").await.unwrap();

    // Subscribe to the topic named "my_topic"
    let subscription = conn.subscribe("my_topic").await.unwrap();

    // ...
}
source

pub(crate) fn unsubscribe(&self, subuid: i32) -> Result<(), Box<dyn Error>>

Unsubscribe from topic(s)

This method is typically called when an NtSubscription is dropped.

source

pub(crate) fn read_bin_frame(buf: Vec<u8>) -> Result<(u64, u64, Data), ()>

Read/parse a binary frame

This method is used internally to process incoming data values for subscribed topics.

Returns (uid, timestamp, data)

source

pub(crate) fn write_bin_frame<T: DataWrap>( &self, uid: i32, ts: u64, value: T, ) -> Result<(), Box<dyn Error>>

Write a binary frame

This method is used internally to send data values to the NetworkTables server.

source

pub fn stop(self)

Shutdown the connection

This method stops the event loops for sending and receiving messages. All NtTopic instances associated with this connection must be dropped before calling this method.

Trait Implementations§

source§

impl Clone for NtConn

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for NtConn

§

impl !RefUnwindSafe for NtConn

§

impl Send for NtConn

§

impl Sync for NtConn

§

impl Unpin for NtConn

§

impl !UnwindSafe for NtConn

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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

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

§

fn vzip(self) -> V