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
impl NtConn
sourcepub async fn new(
server: impl Into<IpAddr>,
client_ident: impl Into<String>,
) -> Result<Self, Box<dyn Error>>
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();
// ...
}
pub(crate) async fn next_id(&self) -> i32
sourcepub async fn publish<T: DataType>(
&self,
name: impl Into<String>,
) -> Result<NtTopic<'_, T>, Box<dyn Error>>
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 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();
// ...
}
sourcepub(crate) fn unpublish(&self, pubuid: i32) -> Result<(), Box<dyn Error>>
pub(crate) fn unpublish(&self, pubuid: i32) -> Result<(), Box<dyn Error>>
Unpublish topic
This method is typically called when an NtTopic
is dropped.
sourcepub async fn subscribe(
&self,
topic: &str,
) -> Result<NtSubscription<'_>, Box<dyn Error>>
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();
// ...
}
sourcepub(crate) fn unsubscribe(&self, subuid: i32) -> Result<(), Box<dyn Error>>
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.
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)