pub struct NtConn {Show 14 fields
pub(crate) reconnect: Arc<Semaphore>,
pub(crate) next_id: Arc<Mutex<i32>>,
pub(crate) incoming_abort: Arc<RwLock<Option<AbortHandle>>>,
pub(crate) outgoing_abort: Arc<RwLock<Option<AbortHandle>>>,
pub(crate) c2s_tx: UnboundedSender<Message>,
pub(crate) client_ident: Arc<RwLock<String>>,
pub(crate) server: Arc<RwLock<String>>,
pub(crate) sock_rd: Arc<RwLock<Option<SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>>>>,
pub(crate) sock_wr: Arc<RwLock<Option<SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>, Message>>>>,
pub(crate) server_client: Arc<RwLock<HashMap<i32, i32>>>,
pub(crate) client_server: Arc<RwLock<HashMap<i32, i32>>>,
pub(crate) server_topics: Arc<RwLock<HashMap<String, (i32, String)>>>,
pub(crate) values: Arc<RwLock<HashMap<i32, Receiver<(u64, Data)>>>>,
pub(crate) value_tx: Arc<RwLock<HashMap<i32, Sender<(u64, Data)>>>>,
}
Expand description
A NetworkTables connection
Fields§
§reconnect: Arc<Semaphore>
§next_id: Arc<Mutex<i32>>
Next sequential ID
incoming_abort: Arc<RwLock<Option<AbortHandle>>>
Incoming request receiver event loop abort handle
outgoing_abort: Arc<RwLock<Option<AbortHandle>>>
Outgoing request sender event loop abort handle
c2s_tx: UnboundedSender<Message>
Outgoing client-to-server message queue
client_ident: Arc<RwLock<String>>
§server: Arc<RwLock<String>>
§sock_rd: Arc<RwLock<Option<SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>>>>
§sock_wr: Arc<RwLock<Option<SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>, Message>>>>
§server_client: Arc<RwLock<HashMap<i32, i32>>>
§client_server: Arc<RwLock<HashMap<i32, i32>>>
§server_topics: Arc<RwLock<HashMap<String, (i32, String)>>>
Mapping from topic names to topic IDs for topics we’ve received from server
values: Arc<RwLock<HashMap<i32, Receiver<(u64, Data)>>>>
§value_tx: Arc<RwLock<HashMap<i32, Sender<(u64, Data)>>>>
Implementations§
Source§impl NtConn
impl NtConn
Sourcepub async fn new(
server: impl Into<IpAddr>,
client_ident: impl Into<String>,
) -> Result<Self>
pub async fn new( server: impl Into<IpAddr>, client_ident: impl Into<String>, ) -> Result<Self>
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();
// ...
}
pub(crate) async fn init_background_event_loops( &self, c2s_rx: UnboundedReceiver<Message>, )
pub(crate) async fn handle_incoming_msg( &self, msg: Result<Message, TungsteniteError>, ) -> Result<()>
pub(crate) async fn connect(&self) -> Result<()>
pub(crate) async fn next_id(&self) -> i32
Sourcepub async fn publish<T: DataWrap>(
&self,
name: impl Into<String>,
) -> Result<NtTopic<'_, T>>
pub async fn publish<T: DataWrap>( &self, name: impl Into<String>, ) -> Result<NtTopic<'_, T>>
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 theDataType
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();
// ...
}
pub(crate) async fn publish_<T: DataWrap>( &self, name: String, pubuid: i32, ) -> Result<()>
Sourcepub(crate) fn unpublish(&self, pubuid: i32) -> Result<()>
pub(crate) fn unpublish(&self, pubuid: i32) -> Result<()>
Unpublish topic
This method is typically called when an NtTopic
is dropped.
Sourcepub async fn subscribe(&self, topic: &str) -> Result<NtSubscription<'_>>
pub async fn subscribe(&self, topic: &str) -> Result<NtSubscription<'_>>
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();
// ...
}
Sourcepub(crate) fn unsubscribe(&self, subuid: i32) -> Result<()>
pub(crate) fn unsubscribe(&self, subuid: i32) -> Result<()>
Unsubscribe from a topic
This method is typically called when an NtSubscription
is dropped.
Sourcepub(crate) fn read_bin_frame(buf: Vec<u8>) -> Result<(u64, u64, Data)>
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)
Trait Implementations§
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> 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