Skip to content

Commit

Permalink
api: remove 'impl Into' from parameter types
Browse files Browse the repository at this point in the history
I think this was an oversight. I generally don't like using 'impl Trait'
in public APIs unless there is no avoiding it. In particular, when using
'impl Trait', it inhibits the use of turbofish, which can sometimes be
useful.
  • Loading branch information
BurntSushi committed Aug 18, 2024
1 parent 9da0595 commit e40eab9
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/civil/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2140,9 +2140,9 @@ impl DateTime {
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
#[inline]
pub fn round(
pub fn round<R: Into<DateTimeRound>>(
self,
options: impl Into<DateTimeRound>,
options: R,
) -> Result<DateTime, Error> {
let options: DateTimeRound = options.into();
options.round(t::NANOS_PER_CIVIL_DAY, self)
Expand Down
2 changes: 1 addition & 1 deletion src/civil/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,7 @@ impl Time {
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
#[inline]
pub fn round(self, options: impl Into<TimeRound>) -> Result<Time, Error> {
pub fn round<R: Into<TimeRound>>(self, options: R) -> Result<Time, Error> {
let options: TimeRound = options.into();
options.round(self)
}
Expand Down
4 changes: 2 additions & 2 deletions src/civil/weekday.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ impl Weekday {
/// assert_eq!(1 + Weekday::Sunday, Weekday::Monday);
/// ```
#[inline]
pub fn wrapping_add(self, days: impl Into<i64>) -> Weekday {
pub fn wrapping_add<D: Into<i64>>(self, days: D) -> Weekday {
let start = t::NoUnits::rfrom(self.to_monday_zero_offset_ranged());
// OK because all i64 values fit in a NoUnits.
let rhs = t::NoUnits::new(days.into()).unwrap();
Expand Down Expand Up @@ -452,7 +452,7 @@ impl Weekday {
/// weekday has no semantic meaning, the weekday cannot be on the right
/// hand side of the `-` operator.
#[inline]
pub fn wrapping_sub(self, days: impl Into<i64>) -> Weekday {
pub fn wrapping_sub<D: Into<i64>>(self, days: D) -> Weekday {
self.wrapping_add(-days.into())
}

Expand Down
28 changes: 14 additions & 14 deletions src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1559,9 +1559,9 @@ impl Span {
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
#[inline]
pub fn checked_add<'a>(
pub fn checked_add<'a, A: Into<SpanArithmetic<'a>>>(
&self,
options: impl Into<SpanArithmetic<'a>>,
options: A,
) -> Result<Span, Error> {
let options: SpanArithmetic<'_> = options.into();
options.checked_add(*self)
Expand Down Expand Up @@ -1687,9 +1687,9 @@ impl Span {
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
#[inline]
pub fn checked_sub<'a>(
pub fn checked_sub<'a, A: Into<SpanArithmetic<'a>>>(
&self,
options: impl Into<SpanArithmetic<'a>>,
options: A,
) -> Result<Span, Error> {
let mut options: SpanArithmetic<'_> = options.into();
options.duration = options.duration.checked_neg()?;
Expand Down Expand Up @@ -1780,9 +1780,9 @@ impl Span {
/// See the examples for [`Span::total`] if you want to sort spans without
/// an `unwrap()` call.
#[inline]
pub fn compare<'a>(
pub fn compare<'a, C: Into<SpanCompare<'a>>>(
&self,
options: impl Into<SpanCompare<'a>>,
options: C,
) -> Result<Ordering, Error> {
let options: SpanCompare<'_> = options.into();
options.compare(*self)
Expand Down Expand Up @@ -1910,9 +1910,9 @@ impl Span {
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
#[inline]
pub fn total<'a>(
pub fn total<'a, T: Into<SpanTotal<'a>>>(
&self,
options: impl Into<SpanTotal<'a>>,
options: T,
) -> Result<f64, Error> {
let options: SpanTotal<'_> = options.into();
options.total(*self)
Expand Down Expand Up @@ -2077,9 +2077,9 @@ impl Span {
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
#[inline]
pub fn round<'a>(
pub fn round<'a, R: Into<SpanRound<'a>>>(
self,
options: impl Into<SpanRound<'a>>,
options: R,
) -> Result<Span, Error> {
let options: SpanRound<'a> = options.into();
options.round(self)
Expand Down Expand Up @@ -2141,9 +2141,9 @@ impl Span {
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
#[inline]
pub fn to_jiff_duration<'a>(
pub fn to_jiff_duration<'a, R: Into<SpanRelativeTo<'a>>>(
&self,
relative: impl Into<SpanRelativeTo<'a>>,
relative: R,
) -> Result<SignedDuration, Error> {
let max_unit = self.largest_unit();
let relative: SpanRelativeTo<'a> = relative.into();
Expand Down Expand Up @@ -2289,9 +2289,9 @@ impl Span {
/// ```
#[deprecated(since = "0.1.5", note = "use Span::to_jiff_duration instead")]
#[inline]
pub fn to_duration<'a>(
pub fn to_duration<'a, R: Into<SpanRelativeTo<'a>>>(
&self,
relative: impl Into<SpanRelativeTo<'a>>,
relative: R,
) -> Result<UnsignedDuration, Error> {
if self.is_negative() {
return Err(err!(
Expand Down
4 changes: 2 additions & 2 deletions src/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1820,9 +1820,9 @@ impl Timestamp {
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
#[inline]
pub fn round(
pub fn round<R: Into<TimestampRound>>(
self,
options: impl Into<TimestampRound>,
options: R,
) -> Result<Timestamp, Error> {
let options: TimestampRound = options.into();
options.round(self)
Expand Down
4 changes: 2 additions & 2 deletions src/zoned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2788,9 +2788,9 @@ impl Zoned {
/// timestamp would result in rounding up to the next day. But the next day
/// is greater than the maximum, and so this returns an error.
#[inline]
pub fn round(
pub fn round<R: Into<ZonedRound>>(
&self,
options: impl Into<ZonedRound>,
options: R,
) -> Result<Zoned, Error> {
let options: ZonedRound = options.into();
options.round(self)
Expand Down

0 comments on commit e40eab9

Please sign in to comment.