Comments (7)
Wouldn't you be better suited to write those ufmt objects into some intermediary buffer before sending them for transmission to the stack?
E.g.
let mut buffer = heapless::String::new();
uwrite!(&mut buffer, "my_http_format_string", my_http_data).unwrap();
tcp_stack.send(tcp_sock, buffer.as_slice()).unwrap()
I don't see why the network stack itself has to be some type of writable stream outside of the potential desire to avoid buffering?
from embedded-nal.
I think it would be helpful to understand why this would be needed. What's the use case for impl uWrite
? I personally don't use ufmt and don't have any need for it. Is there a purpose that it should be pulled into this library, or can it be kept external?
from embedded-nal.
I use uWrite to construct HTTP PUT requests. I also use it to transmit sensor readings. I can understand if uwrite is gated behind a feature flag. I added StackAndSocket
because I wanted the function with_socket()
, although I suspect that method could be added using a custom trait . I'll have to experiment with that.
from embedded-nal.
I tried your example:
let mut x = embedded_nal::heapless::String::new();
uwrite!(&mut x, "bacon {}", 42);
I get the following error
error[E0599]: no method named `do_as_formatter` found for mutable reference `&mut embedded_nal::heapless::String<{_: usize}>` in the current scope
--> src/main.rs:585:5
|
585 | uwrite!(&mut x, "bacon {}", 42);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ method not found in `&mut embedded_nal::heapless::String<{_: usize}>`
|
::: /home/thoth/.cargo/git/checkouts/heapless-c15edde3bc74f47c/8460024/src/string.rs:8:1
|
8 | pub struct String<const N: usize> {
| ---------------------------------
| |
| doesn't satisfy `_: UnstableDoAsFormatter`
| doesn't satisfy `embedded_nal::heapless::String<{_: usize}>: uWrite`
|
= note: the method `do_as_formatter` exists but the following trait bounds were not satisfied:
`embedded_nal::heapless::String<{_: usize}>: uWrite`
which is required by `embedded_nal::heapless::String<{_: usize}>: UnstableDoAsFormatter`
`&mut embedded_nal::heapless::String<{_: usize}>: uWrite`
which is required by `&mut embedded_nal::heapless::String<{_: usize}>: UnstableDoAsFormatter`
`str: uWrite`
which is required by `str: UnstableDoAsFormatter`
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
It turns out that the custom trait is a workable solution without modifying embedded-nal
. https://github.com/mutantbob/embedded-nal-plus/blob/master/src/lib.rs
from embedded-nal.
Using a custom trait will break any kind of cross-compatibility with existing embedded-nal libraries - I would not recommend going that route. I think there are means to work around this without a custom trait and without a custom NAL.
from embedded-nal.
I'm interested in seeing an example of an existing embedded-nal library that would be incompatible with how I designed the custom trait. If anyone can construct one, it would enhance my understanding of Rust.
from embedded-nal.
I agree with @ryan-summers and do not think embedded-nal
would be the place to provide implementations for ufmt
traits.
IIUC there is nothing in ufmt
that embedded-nal
would inherently benefit from and I would keep the rather short adapter code outside of this crate as to avoid non-essential dependencies.
If you disagree, you are welcome to provide a compelling use case and reopen this issue. Closing.
from embedded-nal.
Related Issues (20)
- Guidance on TcpConnect and self-referential structs
- e-nal-async: Missing lifetimes in `UdpStack` HOT 15
- bind-multiple is hard to imlement on smoltcp HOT 4
- Notes for implementer not visible on docs.rs
- TCP socket state/error handling insufficiently specified HOT 3
- [Proposal] Socket-directed API HOT 17
- TCP: receive_exact? HOT 8
- Dealing with stacks that need pinning HOT 5
- How to implement RAII / Drop for Sockets? HOT 4
- TCP: Typestate client and server sockets HOT 1
- Proposal: embedded-nal-async HOT 2
- Reintroduce UDP traits for async
- Restore feature parity in async TCP HOT 1
- AVR Applications using the embedded-nal crate fail to compile
- #use of connect() for tftp protocol HOT 8
- New release of `embedded-nal` HOT 3
- `Dns` traits force caching in-flight DNS requests HOT 1
- get_host_by_name: Clarify behavior w/rt AI_V4MAPPED and AI_ADDRCONFIG
- SocketAddr associated types HOT 9
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 embedded-nal.