how to properly use rust network client
bigbrett opened this issue · comments
I'm trying to write a program that uses the TcpClient, but I had to modify mod.rs
to expose it properly in order for my application to use it. The modification required is:
diff --git a/lognplot/src/net/mod.rs b/lognplot/src/net/mod.rs
index bd488aa..b20e910 100644
--- a/lognplot/src/net/mod.rs
+++ b/lognplot/src/net/mod.rs
@@ -9,7 +9,7 @@
//! - Read data from file
//! - Demo data (random values)
-mod client;
+pub mod client;
mod payload;
Am I doing something wrong here (I'm not a very experienced rust programmer)? What is the proper way for an application to use the TcpClient structure to communicate with the GUI?
Hi @bigbrett ,
This line should probably get you started into the right direction:
https://github.com/windelbouwman/lognplot/blob/master/swviewer/src/serial_wire_viewer.rs#L217
I understand that we lack a simple rust client example? Maybe a good idea to add this as a sort of minimal example?
Regards,
Windel
Btw: the modification you made should not be required, if it is, it is a bug in lognplot. The library should be usable using the TcpClient
struct.
Hi Windel,
Yeah I can't use TcpClient without that modification. Which is why I filed the issue. I could be doing something wrong, but without the modification, I get the following error:
error[E0603]: module `client` is private
--> src/main.rs:3:20
|
3 | use lognplot::net::client as lognplotcl;
| ^^^^^^ private module
|
note: the module `client` is defined here
--> /home/brett/System/source/lognplot/lognplot/src/net/mod.rs:12:1
|
12 | mod client;
| ^^^^^^^^^^^
I include it in my Cargo.toml
as:
lognplot = { path = "/home/brett/System/source/lognplot/lognplot"}
Of course, as I post that, I figure out the answer.
I was including the module as:
use lognplot::net::client;
// ...
client::TcpClient::new()
when I should have been using
use lognplot::net::TcpClient;
// ...
TcpClient::new()
Now it seems to work. Thanks.