Smart pointer which owns its target

Some more:

For the other readers of this thread: Yeah, that's what I was pointing out here:


One reason why call it smart pointer can be found here:


Hmmmm, where would such a bound be used? For the GAT, e.g. return type of mmtkvdb::Txn::get? Not sure if I fully understand it or whether it's also a bit ugly.

Meta: I feel like we're discussing now more about how Rust could be extended rather than helping me with a particular problem. (edit: or is MethodDispatchAs<T> something that can be implemented in today's Rust?) Thus I felt like IRLO was not a bad place to talk about these issues. I'm interested in how Rust could be improved to make these things better, not just how I can write a crate with today's Rust. Of course, I'm also not experienced enough yet to understand everything, so when writing on IRLO this also helps me understand things better, i.e. it's some sort of "support" I get. Anyway, I feel like both URLO and IRLO are not quite fitting for my purpose. On IRLO I feel like a "dumb user" who just doesn't understand the language, and on URLO I feel like questioning the language concepts itself instead of using the language (as it is). What does the pinned post on IRLO say?

Here is the hub for discussing everything related to the implementation and design of the Rust programming language .

This is not a support forum. Questions or requests for support using Rust should be directed to the user forum. This forum is for people contributing to the Rust compiler and standard toolchain, or otherwise working on changes to the language and its implementation.

Did my post on IRLO help me to get support? It wasn't my main intention, but it did help me to get support also. So the latter would be a reason to not post there. Did I want to discuss the implemenation and design of the Rust programming language? Yes, that would be a reason to post there. Am I contributing to the Rust compiler, standard toolchain, or am I otherwise working on changes to the language and its implementation? Not really, though I do occasionally write bug reports and you could see my posts as contribution. Perhaps the quality isn't well enough to make me eligible to post them on IRLO? Either way, I felt like my input wasn't really appreciated by most people (with some exceptions of course). I didn't feel fully comfortable.

Perhaps it would have been easier if there was just one forum instead of two. Also shifting this discussion from IRLO to URLO has been technically tedious. Perhaps I should just go to URLO next time even if I want to discuss language features and never post on IRLO unless I'm 100% sure about a topic?

Anyway, now we're here on URLO, and I think we can stay here. Unless someone tells me to go to IRLO with this!!!!1!! :rofl:


Let me try to find a good explanation for why I resort to use an IntoOwned bound on my GAT (generic associated type) AlignedRef that mmtkvdb::Txn::get returns:

The GAT determines at compile-time whether I return a borrowed or an owned value (or maybe both, depending on actual memory addresses encountered, though I didn't implement optional realignment, and it might come with more overhead than it saves). Thus the return type would either be &'a B, Owned<O>, or Cow<'a, B>. That's what the IntoOwned bound is about:

There's still the curious case of OwnedRef, and I have the feeling that this might bring some things to surface that aren't well thought out yet.

Anyway, the generic AlignedRef<'a>: Deref<Target = B> + IntoOwned is an generalization of all of:

  • &'a B (always borrowed)
  • Cow<'a, B> (sometimes borrowed, sometimes owned)
  • Owned<O> (always owned)

(Edit: Note that all three types are reference-like types, even Owned despite its name. Owned<O> isn't the "owned" type, but O is.)

Does that make sense? I need Deref to go to B where needed (and to have deref ergonomics, otherwise I could use Borrow), and I need IntoOwned to go to O without doing an extra (useless) clone.

I will look into what that "yoke" is. Maybe it's something I could need.


  1. Providing fn(&self) -> &T with the guarantee that &Self and &T behave “the same.” ↩︎

  2. I saw your "smart pointer" link, but I don't think that reference section supports your definition of "smart pointer".) ↩︎