Open bestouff opened 2 years ago
In fact my problem seems to be that SourceId
needs Display
, but I can't impl that on a usize
alone. I've tried using (&spircer::Project, spircer::FileId)
as a SourceId
but then that makes temporaries which can't be returned by reference from Span::source()
...
I got out of that by using a std::path::Path
as SourceId
and building a separate HashMap
for storing the mapping, but it's a bit of a pity to have to duplicate an existing structure instead of just implementing a trait ...
I'm planning to do a big overhaul to the API of Ariadne within the next week or two, and this is one of the big things on my list to change. I'll let you know when I have something worth testing!
Ok, thanks for that.
If you also could avoid passing the Cache
by value (I have to clone()
it for each message), that's be great.
There is a blanket impl of Cache
for &mut impl Cache
: https://docs.rs/ariadne/0.1.3/ariadne/trait.Cache.html#impl-Cache%3CId%3E-for-%26%27b%20mut%20C
You can pass it via mutable reference.
Yes but as I can access it from multiple threads I only have a shared reference ...
In that case, you should be able to implement it for &MyType
if MyType
is local. This will still work because accessing &MyType
mutably only gives you a mutable reference to the shared reference, not the underlying value.
Yes that works, thanks.
I just ran into something similar. It's unfortunate that the current API design basically forces Id
be a std::path::Path
or something similar, as opposed to e.g. a cheap integer ID that can look up a Path
for display
. The lifetimes on fn display
essentially require this.
I've got some troubles trying to implement
Cache
; trying to compile this:Errors like this:
Shouldn't the
Cache
trait have an explicit lifetime ? Otherwise I don't know how to reconcile'p
and'a
in my example.FileId
(what stands for anSourceId
) is just anusize
indexing into the rightFile
structure, in myProject
structure.