Skip to content

Commit addf231

Browse files
committed
Permit unsized writers for format_into
1 parent 338f84f commit addf231

File tree

9 files changed

+47
-43
lines changed

9 files changed

+47
-43
lines changed

time/src/date.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,7 @@ impl Date {
13101310
/// Format the `Date` using the provided [format description](crate::format_description).
13111311
pub fn format_into(
13121312
self,
1313-
output: &mut impl io::Write,
1313+
output: &mut (impl io::Write + ?Sized),
13141314
format: &(impl Formattable + ?Sized),
13151315
) -> Result<usize, error::Format> {
13161316
format.format_into(output, Some(self), None, None)

time/src/formatting/formattable.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ mod sealed {
4242
/// Format the item into the provided output, returning the number of bytes written.
4343
fn format_into(
4444
&self,
45-
output: &mut impl io::Write,
45+
output: &mut (impl io::Write + ?Sized),
4646
date: Option<Date>,
4747
time: Option<Time>,
4848
offset: Option<UtcOffset>,
@@ -66,7 +66,7 @@ mod sealed {
6666
impl sealed::Sealed for BorrowedFormatItem<'_> {
6767
fn format_into(
6868
&self,
69-
output: &mut impl io::Write,
69+
output: &mut (impl io::Write + ?Sized),
7070
date: Option<Date>,
7171
time: Option<Time>,
7272
offset: Option<UtcOffset>,
@@ -87,7 +87,7 @@ impl sealed::Sealed for BorrowedFormatItem<'_> {
8787
impl sealed::Sealed for [BorrowedFormatItem<'_>] {
8888
fn format_into(
8989
&self,
90-
output: &mut impl io::Write,
90+
output: &mut (impl io::Write + ?Sized),
9191
date: Option<Date>,
9292
time: Option<Time>,
9393
offset: Option<UtcOffset>,
@@ -103,7 +103,7 @@ impl sealed::Sealed for [BorrowedFormatItem<'_>] {
103103
impl sealed::Sealed for OwnedFormatItem {
104104
fn format_into(
105105
&self,
106-
output: &mut impl io::Write,
106+
output: &mut (impl io::Write + ?Sized),
107107
date: Option<Date>,
108108
time: Option<Time>,
109109
offset: Option<UtcOffset>,
@@ -124,7 +124,7 @@ impl sealed::Sealed for OwnedFormatItem {
124124
impl sealed::Sealed for [OwnedFormatItem] {
125125
fn format_into(
126126
&self,
127-
output: &mut impl io::Write,
127+
output: &mut (impl io::Write + ?Sized),
128128
date: Option<Date>,
129129
time: Option<Time>,
130130
offset: Option<UtcOffset>,
@@ -143,7 +143,7 @@ where
143143
{
144144
fn format_into(
145145
&self,
146-
output: &mut impl io::Write,
146+
output: &mut (impl io::Write + ?Sized),
147147
date: Option<Date>,
148148
time: Option<Time>,
149149
offset: Option<UtcOffset>,
@@ -157,7 +157,7 @@ where
157157
impl sealed::Sealed for Rfc2822 {
158158
fn format_into(
159159
&self,
160-
output: &mut impl io::Write,
160+
output: &mut (impl io::Write + ?Sized),
161161
date: Option<Date>,
162162
time: Option<Time>,
163163
offset: Option<UtcOffset>,
@@ -208,7 +208,7 @@ impl sealed::Sealed for Rfc2822 {
208208
impl sealed::Sealed for Rfc3339 {
209209
fn format_into(
210210
&self,
211-
output: &mut impl io::Write,
211+
output: &mut (impl io::Write + ?Sized),
212212
date: Option<Date>,
213213
time: Option<Time>,
214214
offset: Option<UtcOffset>,
@@ -284,7 +284,7 @@ impl sealed::Sealed for Rfc3339 {
284284
impl<const CONFIG: EncodedConfig> sealed::Sealed for Iso8601<CONFIG> {
285285
fn format_into(
286286
&self,
287-
output: &mut impl io::Write,
287+
output: &mut (impl io::Write + ?Sized),
288288
date: Option<Date>,
289289
time: Option<Time>,
290290
offset: Option<UtcOffset>,

time/src/formatting/iso8601.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{error, Date, Time, UtcOffset};
1414

1515
/// Format the date portion of ISO 8601.
1616
pub(super) fn format_date<const CONFIG: EncodedConfig>(
17-
output: &mut impl io::Write,
17+
output: &mut (impl io::Write + ?Sized),
1818
date: Date,
1919
) -> Result<usize, error::Format> {
2020
let mut bytes = 0;
@@ -70,7 +70,7 @@ pub(super) fn format_date<const CONFIG: EncodedConfig>(
7070

7171
/// Format the time portion of ISO 8601.
7272
pub(super) fn format_time<const CONFIG: EncodedConfig>(
73-
output: &mut impl io::Write,
73+
output: &mut (impl io::Write + ?Sized),
7474
time: Time,
7575
) -> Result<usize, error::Format> {
7676
let mut bytes = 0;
@@ -115,7 +115,7 @@ pub(super) fn format_time<const CONFIG: EncodedConfig>(
115115

116116
/// Format the UTC offset portion of ISO 8601.
117117
pub(super) fn format_offset<const CONFIG: EncodedConfig>(
118-
output: &mut impl io::Write,
118+
output: &mut (impl io::Write + ?Sized),
119119
offset: UtcOffset,
120120
) -> Result<usize, error::Format> {
121121
if Iso8601::<CONFIG>::FORMAT_TIME && offset.is_utc() {

time/src/formatting/mod.rs

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,17 @@ const WEEKDAY_NAMES: [&[u8]; 7] = [
4040
];
4141

4242
/// Write all bytes to the output, returning the number of bytes written.
43-
pub(crate) fn write(output: &mut impl io::Write, bytes: &[u8]) -> io::Result<usize> {
43+
pub(crate) fn write(output: &mut (impl io::Write + ?Sized), bytes: &[u8]) -> io::Result<usize> {
4444
output.write_all(bytes)?;
4545
Ok(bytes.len())
4646
}
4747

4848
/// If `pred` is true, write all bytes to the output, returning the number of bytes written.
49-
pub(crate) fn write_if(output: &mut impl io::Write, pred: bool, bytes: &[u8]) -> io::Result<usize> {
49+
pub(crate) fn write_if(
50+
output: &mut (impl io::Write + ?Sized),
51+
pred: bool,
52+
bytes: &[u8],
53+
) -> io::Result<usize> {
5054
if pred {
5155
write(output, bytes)
5256
} else {
@@ -56,7 +60,7 @@ pub(crate) fn write_if(output: &mut impl io::Write, pred: bool, bytes: &[u8]) ->
5660

5761
/// If `pred` is true, write `true_bytes` to the output. Otherwise, write `false_bytes`.
5862
pub(crate) fn write_if_else(
59-
output: &mut impl io::Write,
63+
output: &mut (impl io::Write + ?Sized),
6064
pred: bool,
6165
true_bytes: &[u8],
6266
false_bytes: &[u8],
@@ -69,7 +73,7 @@ pub(crate) fn write_if_else(
6973
/// This method accepts the number of digits before and after the decimal. The value will be padded
7074
/// with zeroes to the left if necessary.
7175
pub(crate) fn format_float(
72-
output: &mut impl io::Write,
76+
output: &mut (impl io::Write + ?Sized),
7377
value: f64,
7478
digits_before_decimal: u8,
7579
digits_after_decimal: Option<NonZeroU8>,
@@ -98,7 +102,7 @@ pub(crate) fn format_float(
98102
///
99103
/// The sign must be written by the caller.
100104
pub(crate) fn format_number<const WIDTH: u8>(
101-
output: &mut impl io::Write,
105+
output: &mut (impl io::Write + ?Sized),
102106
value: impl itoa::Integer + DigitCount + Copy,
103107
padding: modifier::Padding,
104108
) -> Result<usize, io::Error> {
@@ -113,7 +117,7 @@ pub(crate) fn format_number<const WIDTH: u8>(
113117
///
114118
/// The sign must be written by the caller.
115119
pub(crate) fn format_number_pad_space<const WIDTH: u8>(
116-
output: &mut impl io::Write,
120+
output: &mut (impl io::Write + ?Sized),
117121
value: impl itoa::Integer + DigitCount + Copy,
118122
) -> Result<usize, io::Error> {
119123
let mut bytes = 0;
@@ -128,7 +132,7 @@ pub(crate) fn format_number_pad_space<const WIDTH: u8>(
128132
///
129133
/// The sign must be written by the caller.
130134
pub(crate) fn format_number_pad_zero<const WIDTH: u8>(
131-
output: &mut impl io::Write,
135+
output: &mut (impl io::Write + ?Sized),
132136
value: impl itoa::Integer + DigitCount + Copy,
133137
) -> Result<usize, io::Error> {
134138
let mut bytes = 0;
@@ -143,7 +147,7 @@ pub(crate) fn format_number_pad_zero<const WIDTH: u8>(
143147
///
144148
/// If the sign is mandatory, the sign must be written by the caller.
145149
pub(crate) fn format_number_pad_none(
146-
output: &mut impl io::Write,
150+
output: &mut (impl io::Write + ?Sized),
147151
value: impl itoa::Integer + Copy,
148152
) -> Result<usize, io::Error> {
149153
write(output, itoa::Buffer::new().format(value).as_bytes())
@@ -153,7 +157,7 @@ pub(crate) fn format_number_pad_none(
153157
/// component requires information that it does not provide or if the value cannot be output to the
154158
/// stream.
155159
pub(crate) fn format_component(
156-
output: &mut impl io::Write,
160+
output: &mut (impl io::Write + ?Sized),
157161
component: Component,
158162
date: Option<Date>,
159163
time: Option<Time>,
@@ -198,7 +202,7 @@ pub(crate) fn format_component(
198202
// region: date formatters
199203
/// Format the day into the designated output.
200204
fn fmt_day(
201-
output: &mut impl io::Write,
205+
output: &mut (impl io::Write + ?Sized),
202206
date: Date,
203207
modifier::Day { padding }: modifier::Day,
204208
) -> Result<usize, io::Error> {
@@ -207,7 +211,7 @@ fn fmt_day(
207211

208212
/// Format the month into the designated output.
209213
fn fmt_month(
210-
output: &mut impl io::Write,
214+
output: &mut (impl io::Write + ?Sized),
211215
date: Date,
212216
modifier::Month {
213217
padding,
@@ -232,7 +236,7 @@ fn fmt_month(
232236

233237
/// Format the ordinal into the designated output.
234238
fn fmt_ordinal(
235-
output: &mut impl io::Write,
239+
output: &mut (impl io::Write + ?Sized),
236240
date: Date,
237241
modifier::Ordinal { padding }: modifier::Ordinal,
238242
) -> Result<usize, io::Error> {
@@ -241,7 +245,7 @@ fn fmt_ordinal(
241245

242246
/// Format the weekday into the designated output.
243247
fn fmt_weekday(
244-
output: &mut impl io::Write,
248+
output: &mut (impl io::Write + ?Sized),
245249
date: Date,
246250
modifier::Weekday {
247251
repr,
@@ -273,7 +277,7 @@ fn fmt_weekday(
273277

274278
/// Format the week number into the designated output.
275279
fn fmt_week_number(
276-
output: &mut impl io::Write,
280+
output: &mut (impl io::Write + ?Sized),
277281
date: Date,
278282
modifier::WeekNumber { padding, repr }: modifier::WeekNumber,
279283
) -> Result<usize, io::Error> {
@@ -290,7 +294,7 @@ fn fmt_week_number(
290294

291295
/// Format the year into the designated output.
292296
fn fmt_year(
293-
output: &mut impl io::Write,
297+
output: &mut (impl io::Write + ?Sized),
294298
date: Date,
295299
modifier::Year {
296300
padding,
@@ -356,7 +360,7 @@ fn fmt_year(
356360
// region: time formatters
357361
/// Format the hour into the designated output.
358362
fn fmt_hour(
359-
output: &mut impl io::Write,
363+
output: &mut (impl io::Write + ?Sized),
360364
time: Time,
361365
modifier::Hour {
362366
padding,
@@ -374,7 +378,7 @@ fn fmt_hour(
374378

375379
/// Format the minute into the designated output.
376380
fn fmt_minute(
377-
output: &mut impl io::Write,
381+
output: &mut (impl io::Write + ?Sized),
378382
time: Time,
379383
modifier::Minute { padding }: modifier::Minute,
380384
) -> Result<usize, io::Error> {
@@ -383,7 +387,7 @@ fn fmt_minute(
383387

384388
/// Format the period into the designated output.
385389
fn fmt_period(
386-
output: &mut impl io::Write,
390+
output: &mut (impl io::Write + ?Sized),
387391
time: Time,
388392
modifier::Period {
389393
is_uppercase,
@@ -400,16 +404,16 @@ fn fmt_period(
400404

401405
/// Format the second into the designated output.
402406
fn fmt_second(
403-
output: &mut impl io::Write,
407+
output: &mut (impl io::Write + ?Sized),
404408
time: Time,
405409
modifier::Second { padding }: modifier::Second,
406410
) -> Result<usize, io::Error> {
407411
format_number::<2>(output, time.second(), padding)
408412
}
409413

410414
/// Format the subsecond into the designated output.
411-
fn fmt_subsecond<W: io::Write>(
412-
output: &mut W,
415+
fn fmt_subsecond(
416+
output: &mut (impl io::Write + ?Sized),
413417
time: Time,
414418
modifier::Subsecond { digits }: modifier::Subsecond,
415419
) -> Result<usize, io::Error> {
@@ -441,7 +445,7 @@ fn fmt_subsecond<W: io::Write>(
441445
// region: offset formatters
442446
/// Format the offset hour into the designated output.
443447
fn fmt_offset_hour(
444-
output: &mut impl io::Write,
448+
output: &mut (impl io::Write + ?Sized),
445449
offset: UtcOffset,
446450
modifier::OffsetHour {
447451
padding,
@@ -460,7 +464,7 @@ fn fmt_offset_hour(
460464

461465
/// Format the offset minute into the designated output.
462466
fn fmt_offset_minute(
463-
output: &mut impl io::Write,
467+
output: &mut (impl io::Write + ?Sized),
464468
offset: UtcOffset,
465469
modifier::OffsetMinute { padding }: modifier::OffsetMinute,
466470
) -> Result<usize, io::Error> {
@@ -469,7 +473,7 @@ fn fmt_offset_minute(
469473

470474
/// Format the offset second into the designated output.
471475
fn fmt_offset_second(
472-
output: &mut impl io::Write,
476+
output: &mut (impl io::Write + ?Sized),
473477
offset: UtcOffset,
474478
modifier::OffsetSecond { padding }: modifier::OffsetSecond,
475479
) -> Result<usize, io::Error> {
@@ -479,7 +483,7 @@ fn fmt_offset_second(
479483

480484
/// Format the Unix timestamp into the designated output.
481485
fn fmt_unix_timestamp(
482-
output: &mut impl io::Write,
486+
output: &mut (impl io::Write + ?Sized),
483487
date: Date,
484488
time: Time,
485489
offset: UtcOffset,

time/src/offset_date_time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ impl OffsetDateTime {
12881288
/// description](crate::format_description).
12891289
pub fn format_into(
12901290
self,
1291-
output: &mut impl io::Write,
1291+
output: &mut (impl io::Write + ?Sized),
12921292
format: &(impl Formattable + ?Sized),
12931293
) -> Result<usize, error::Format> {
12941294
format.format_into(

time/src/primitive_date_time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ impl PrimitiveDateTime {
870870
/// description](crate::format_description).
871871
pub fn format_into(
872872
self,
873-
output: &mut impl io::Write,
873+
output: &mut (impl io::Write + ?Sized),
874874
format: &(impl Formattable + ?Sized),
875875
) -> Result<usize, error::Format> {
876876
format.format_into(output, Some(self.date), Some(self.time), None)

time/src/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ impl Time {
715715
/// Format the `Time` using the provided [format description](crate::format_description).
716716
pub fn format_into(
717717
self,
718-
output: &mut impl io::Write,
718+
output: &mut (impl io::Write + ?Sized),
719719
format: &(impl Formattable + ?Sized),
720720
) -> Result<usize, error::Format> {
721721
format.format_into(output, None, Some(self), None)

time/src/utc_date_time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ impl UtcDateTime {
10421042
/// description](crate::format_description).
10431043
pub fn format_into(
10441044
self,
1045-
output: &mut impl io::Write,
1045+
output: &mut (impl io::Write + ?Sized),
10461046
format: &(impl Formattable + ?Sized),
10471047
) -> Result<usize, error::Format> {
10481048
format.format_into(

time/src/utc_offset.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ impl UtcOffset {
371371
/// Format the `UtcOffset` using the provided [format description](crate::format_description).
372372
pub fn format_into(
373373
self,
374-
output: &mut impl io::Write,
374+
output: &mut (impl io::Write + ?Sized),
375375
format: &(impl Formattable + ?Sized),
376376
) -> Result<usize, error::Format> {
377377
format.format_into(output, None, None, Some(self))

0 commit comments

Comments
 (0)