I am writing a library in rust which builds a self-referential data structure; it uses indexes internally for nodes which are actually identified by URIs (or IRIs which is the same thing).
I have a method like so:
fn iri(self, s: String)-> IRI
IRI is actually just a type alias for usize:
struct IRI(usize)
so that I can do this, where ont
is the main data structure:
let i = ont.iri("http://example.com");
I can then pass this to further methods:
let c = ont.class(i);
This is okay, but I'd like to combine these into one line:
let c = ont.class(ont.iri("http://example.com"))
This fails because I can't borrow the reference to ont
twice. Both the iri
and class
calls are mutable and need to be.
Is there any way of achieving this without an intermediate variable?