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
7
7
8
8
## Unreleased
9
9
10
- Add unreleased changes here
10
+ - Added ` ToFmt ` adapter for ` core::fmt::Write ` .
11
11
12
12
## 0.6.1 - 2023-11-28
13
13
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 3
3
#![ warn( missing_docs) ]
4
4
#![ doc = include_str ! ( "../README.md" ) ]
5
5
6
+ pub mod fmt;
7
+
6
8
#[ cfg( feature = "std" ) ]
7
9
#[ cfg_attr( docsrs, doc( cfg( feature = "std" ) ) ) ]
8
10
pub mod std;
You can’t perform that action at this time.
0 commit comments