File tree Expand file tree Collapse file tree 3 files changed +45
-1
lines changed Expand file tree Collapse file tree 3 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
88## Unreleased
99
10- Add unreleased changes here
10+ - Added ` ToFmt ` adapter for ` core::fmt::Write ` .
1111
1212## 0.6.1 - 2023-11-28
1313
Original file line number Diff line number Diff line change 1+ //! Adapters to the `core::fmt::Write`.
2+
3+ /// Adapter to the `core::fmt::Write` trait.
4+ #[ derive( Clone , Default , PartialEq , Debug ) ]
5+ pub struct ToFmt < T : ?Sized > {
6+ inner : T ,
7+ }
8+
9+ impl < T > ToFmt < T > {
10+ /// Create a new adapter.
11+ pub fn new ( inner : T ) -> Self {
12+ Self { inner }
13+ }
14+
15+ /// Consume the adapter, returning the inner object.
16+ pub fn into_inner ( self ) -> T {
17+ self . inner
18+ }
19+ }
20+
21+ impl < T : ?Sized > ToFmt < T > {
22+ /// Borrow the inner object.
23+ pub fn inner ( & self ) -> & T {
24+ & self . inner
25+ }
26+
27+ /// Mutably borrow the inner object.
28+ pub fn inner_mut ( & mut self ) -> & mut T {
29+ & mut self . inner
30+ }
31+ }
32+
33+ impl < T : embedded_io:: Write + ?Sized > core:: fmt:: Write for ToFmt < T > {
34+ fn write_str ( & mut self , s : & str ) -> core:: fmt:: Result {
35+ self . inner . write_all ( s. as_bytes ( ) ) . or ( Err ( core:: fmt:: Error ) )
36+ }
37+
38+ // Use fmt::Write default impls for
39+ // * write_fmt(): better here than e-io::Write::write_fmt
40+ // since we don't need to bother with saving the Error
41+ // * write_char(): would be the same
42+ }
Original file line number Diff line number Diff line change 33#![ warn( missing_docs) ]
44#![ doc = include_str ! ( "../README.md" ) ]
55
6+ pub mod fmt;
7+
68#[ cfg( feature = "std" ) ]
79#[ cfg_attr( docsrs, doc( cfg( feature = "std" ) ) ) ]
810pub mod std;
You can’t perform that action at this time.
0 commit comments