shepmaster / sxd-document

An XML library in Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Investigate moving elements between documents.

shepmaster opened this issue · comments

It'd be nice to be able to rely on lifetimes or some other magic to know when two documents are different. Otherwise we might have to do something ugly like compare references.

Lifetimes won't be useful for this unless you use something like Haskell's runSt trick, which is incredibly heavyweight.

@pythonesque thanks for the heads-up. I was really hoping for a magical, compile-time-only solution to present itself. Since each item has its own, unique lifetime, I really wanted to be able to leverage something like the old InvariantLifetime somehow. I'll look into runSt, purely because I have no idea what it is!

You can replicate InvariantLifetime, which is what is actually done in the BTreeMap implementation. See https://doc.rust-lang.org/src/collections/btree/map.rs.html#615-628. The reason I say it's very heavyweight is that the only way to make its properties useful is to require each document to be created (or at least, accessed) within a closure.

Ah, so the heavyweightness is due to an onus on the programmer, not necessarily on runtime speed / memory. That's a shame.