# Language inconsistency when implementing a trait

**URL:** <https://internals.rust-lang.org/t/language-inconsistency-when-implementing-a-trait/11878>\
**Category:** language design\
**Created:** [February 22, 2020, 2:25pm UTC](https://internals.rust-lang.org/t/language-inconsistency-when-implementing-a-trait/11878 "2020-02-22T14:25:15Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![jjpe](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jjpe/32/9779_2.png) [@jjpe](https://internals.rust-lang.org/u/jjpe)\
**Post date:** [February 24, 2020, 8:17pm UTC](https://internals.rust-lang.org/t/language-inconsistency-when-implementing-a-trait/11878/21 "2020-02-24T20:17:28Z")

</div>

`BoxBar<T>` in this story is `BoxDelta<T>`. It's a separate type because it represents the delta between two instances of `Box<T>`, but is not to be viewed as an instance itself.

In practice it's meant to assist the computation and application of deltas that are derived from types composed of a `Box<T>` field.

---

<div class="post-metadata">

**Author:** ![CAD97](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cad97/32/3460_2.png) [@CAD97](https://internals.rust-lang.org/u/CAD97)\
**Post date:** [February 24, 2020, 9:42pm UTC](https://internals.rust-lang.org/t/language-inconsistency-when-implementing-a-trait/11878/22 "2020-02-24T21:42:42Z")

</div>

Is there a reason that you've chosen to use `BoxDelta<T>` instead of `Box<DeltaT>` or similar?

---

<div class="post-metadata">

**Author:** ![jjpe](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jjpe/32/9779_2.png) [@jjpe](https://internals.rust-lang.org/u/jjpe)\
**Post date:** [February 24, 2020, 10:21pm UTC](https://internals.rust-lang.org/t/language-inconsistency-when-implementing-a-trait/11878/23 "2020-02-24T22:21:19Z")

</div>

Yes - Delta's are not simply newtypes as they also encode the possibility of a "null delta" i.e. nothing's changed for that value.

On top of that, it's simpler to keep all Delta types roughly similar in structure - this helps to keep things unsurprising.

It's also true that a custom type restricts what can be done with it.

---

<div class="post-metadata">

**Author:** ![CAD97](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cad97/32/3460_2.png) [@CAD97](https://internals.rust-lang.org/u/CAD97)\
**Post date:** [February 25, 2020, 5:06am UTC](https://internals.rust-lang.org/t/language-inconsistency-when-implementing-a-trait/11878/24 "2020-02-25T05:06:29Z")

</div>

Do you also have e.g. `Delta<T>` for owned values? If so why don't you use `Box<Delta<T>>`?

In another formulation, why is it

```rust
impl DeltaOps<T> for Box<T> {
    type Diff = BoxDelta<T>;
}

```

and not

```rust
impl DeltaOps<T: DeltaOps> for Box<T> {
    type Diff = Box<T::Diff>;
}

```

I just don't see why `BoxDelta` needs to exist rather than a regular box of a delta.

---

<div class="post-metadata">

**Author:** ![jjpe](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jjpe/32/9779_2.png) [@jjpe](https://internals.rust-lang.org/u/jjpe)\
**Post date:** [March 3, 2020, 6:38pm UTC](https://internals.rust-lang.org/t/language-inconsistency-when-implementing-a-trait/11878/25 "2020-03-03T18:38:15Z")

</div>

This discussion has become a bit of a moot point. The original problem was that I couldn't use `TryFrom` and `TryInto` because trying to write the relevant impls for `Box<T>` made `rustc` complain.

That problem has since been solved by creating my own, specialized conversion traits that do not suffer from the same restriction on `Box<T>`, i.e. no `#[fundamental]` attribute on its definition.

The relevant takeaway here is that the combination of `TryFrom` and `TryInto` with types marked as `#[fundamental]` turned out to be more restrictive than I had originally anticipated.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [June 1, 2020, 6:38pm UTC](https://internals.rust-lang.org/t/language-inconsistency-when-implementing-a-trait/11878/26 "2020-06-01T18:38:21Z")

</div>

Closed on June 1, 2020, 6:38pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

[Previous page](https://internals.rust-lang.org/t/language-inconsistency-when-implementing-a-trait/11878.md?page=1)
