Comments (5)
I made an attempt to resolve this in #141 by wrapping the configuration properties in an enum as @RobDavenport suggested. Having two separate enums for connect (TransportConnect
) and listen ( TransportListen
) allows an adapter to implement different properties on both methods. The adapter is determined by variant of the TransportConnect
/ TransportListen
enum and then the enum is passed all the way down to the adapter. In the adapter we can assume the variant as the controller would not call this specific adapter otherwise.
The last bit cannot be statically checked, unfortunately. However, I think the code is simple enough to accept this? Also from the public API it actually is guaranteed as retrieving the adapter from the variant is an internal function.
I kept the original connect()
and listen()
methods with the standard Transport
enum which maps to TransportConnect
/ TransportListen
with default settings.
from message-io.
- Avoid that the user could mix configurations from one adapter with a transport that doesn't belong. Is it possible to maintain this safety at compile time?
Would it be possible to solve this by instead modifying the network.connect
to instead of receiving a transport as a parameter, use it as type parameter? This way we could do something like network.connect::(addr, TcpConfig::default()), or network.connect::(addr, my_config). With traits this should allow compile time checking for incompatibilities. Downsides is it might require quite a big rewrite of the network engine.
from message-io.
Thanks, @RobDavenport ! Yeah, this could be a big candidate.
The TcpConfig
should contain a Transport::Tcp
internally associated with it (that identified the internal adapter used), and the connect()
function could be something like Network::connect(impl TransportConfig, impl ToRemoteAddr)
.
The problem is, what happens if the listen()
function and the connect()
function can receive different configs?
Is it mandatory to create two different trait configs? TransportConnectConfig
, TransportListenConfig
. (problem 1)
Regarding the adapter API, the adapter function can handle directly the correct type statically, because the adapter knows all the types it uses. The tricky part is how to pass the config through the network engine as you say (without dynamic memory if possible!). (problem 2)
I had some ideas related to this feature here https://github.com/lemunozm/message-io/compare/ideas/transport_with_config. The idea is to use something like Transport::TcpWith(TcpConfig{}), for the cases you need extra configuration than the default. I am not sure if this idea obfuscates the Transport
concept too much. Anyway, both previous problems remain too.
from message-io.
Regarding problem 2.
Because the TransportConfig
must contain the transport (that identifies the adapter used). It could be done with some pinch of unsafe code to handle that transport as a "generic transport" and rebuild to the transport type that the adapter required by its type without any downside of performance using a Box
(that could be the safe idea)
from message-io.
I really like your implementation. This feature is great to open the door to future extensions.
Thanks for your contribution to this!!
from message-io.
Related Issues (20)
- How to use endpoint HOT 6
- Sending HTTP Responses HOT 2
- Typo in documents? HOT 2
- Modify some parameters of udp connection HOT 2
- Packages contain code that will be rejected by a future version of Rust HOT 12
- Send message from basic websocket client HOT 2
- Disconnecting badly acting client (endpoint) HOT 2
- Cancelling timed messages fails sometimes HOT 3
- Release 0.14.8
- Unable to connect with FramedTcp HOT 1
- Release v0.15.0 HOT 8
- Add support for Bevy ECS HOT 3
- Error compiling with only tcp feature enabled HOT 3
- Release 0.16.0 HOT 2
- Buymeacoffee badge is misspelled ("bymeacoffee") HOT 1
- ws can not receive text HOT 10
- Is it possible to limit max packet size when using FramedTcp transport? HOT 1
- Is it possible to create an UART adapter? HOT 3
- Not compiling on linux (ubuntu 22.04) HOT 2
- Scaling of a application HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from message-io.