Skip to content

Commit d5d8d84

Browse files
committed
Bring back the Display requirement for Encodings
Basically, it's just really convenient and doing string formatting without this requirement is a pain. This reverts part of 2bc8f57
1 parent 1359042 commit d5d8d84

File tree

3 files changed

+13
-24
lines changed

3 files changed

+13
-24
lines changed

README.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,8 @@ assert!(parsed == &i32::encode());
3434

3535
# Generating encoding strings
3636

37-
The string representation of an `Encoding` can be generated via its `write`
38-
method:
39-
40-
``` rust
41-
let mut result = String::new();
42-
i32::encode().write(&mut result).unwrap();
43-
assert_eq!(result, "i");
44-
```
45-
46-
The encodings defined in this crate also implement `Display` for convenience,
47-
allowing the `to_string` method to be used:
37+
Every `Encoding` implements `Display` as its string representation.
38+
This can be generated conveniently through the `to_string` method:
4839

4940
``` rust
5041
assert_eq!(i32::encode().to_string(), "i");

src/encoding/never.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use core::fmt;
2+
13
use {Descriptor, Encoding};
24
use multi::{Encodings, EncodingsIterateCallback};
35

@@ -24,3 +26,9 @@ impl Encodings for Never {
2426
match self { }
2527
}
2628
}
29+
30+
impl fmt::Display for Never {
31+
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
32+
match self { }
33+
}
34+
}

src/lib.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,8 @@ assert!(parsed == &i32::encode());
3737
3838
# Generating encoding strings
3939
40-
The string representation of an `Encoding` can be generated via its `write`
41-
method:
42-
43-
```
44-
# use objc_encode::{Encode, Encoding};
45-
let mut result = String::new();
46-
i32::encode().write(&mut result).unwrap();
47-
assert_eq!(result, "i");
48-
```
49-
50-
The encodings defined in this crate also implement `Display` for convenience,
51-
allowing the `to_string` method to be used:
40+
Every `Encoding` implements `Display` as its string representation.
41+
This can be generated conveniently through the `to_string` method:
5242
5343
```
5444
# use objc_encode::Encode;
@@ -75,7 +65,7 @@ pub use descriptor::Descriptor;
7565
pub use multi::{Encodings, EncodingsIterateCallback};
7666

7767
/// An Objective-C type encoding.
78-
pub trait Encoding {
68+
pub trait Encoding: fmt::Display {
7969
/// The type of `Encoding` that Self will use if it is an encoding for
8070
/// a pointer to describe its target.
8171
type PointerTarget: ?Sized + Encoding;

0 commit comments

Comments
 (0)