Sled: Minor API proposal: change `From` to `Into`

Created on 29 Feb 2020  路  3Comments  路  Source: spacejam/sled

Several Tree methods (insert being the most obvious) have an interface like this:

fn modify<V>(&self, value: V)
    where IVec: From<V> { ... }

I propose changing these to where V: Into<IVec>, for the following reasons:

  • It allows a slightly larger set of input types, as there are rare cases where Into<T> can be implemented but T: From<U> cannot.
  • It allows the trait bound to be on V, the input parameter type, which personally I find to be cleaner than an indirect bound on IVec.
  • Generally, using Into<T> is more common in Rust APIs [citation needed].
  • This is a strictly forwards-compatible change, because T: From<U> implies U: Into<T>.

I'm happy to go through and make this change myself, but I wanted to first propose the change and get feedback / approval.

Most helpful comment

@Lucretiel yeah that's a good point, I think I just had the blanket recommendation of "use From not Into" into my head without thinking at all, not remembering that recommendation is for implementing the traits themselves rather than interfaces which accept them.

I'd gladly accept that change as long as it doesn't cause gnarly API breakage in some unforeseen way, which I don't think will happen!

All 3 comments

@Lucretiel yeah that's a good point, I think I just had the blanket recommendation of "use From not Into" into my head without thinking at all, not remembering that recommendation is for implementing the traits themselves rather than interfaces which accept them.

I'd gladly accept that change as long as it doesn't cause gnarly API breakage in some unforeseen way, which I don't think will happen!

Great! Can you assign this bug to me so that I don't lose track of it?

Sure!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

spacejam picture spacejam  路  7Comments

brechtcs picture brechtcs  路  4Comments

spacejam picture spacejam  路  7Comments

spacejam picture spacejam  路  6Comments

D1plo1d picture D1plo1d  路  3Comments