Stream: t-compiler/help

Topic: from slice to List


Santiago Pastorino (Oct 10 2019 at 20:04, on Zulip):

is there a way to go from &[T] to &List<T> ?

simulacrum (Oct 10 2019 at 20:09, on Zulip):

I think you'd need to intern it?

simulacrum (Oct 10 2019 at 20:09, on Zulip):

depends on the T, I suspect

simulacrum (Oct 10 2019 at 20:10, on Zulip):

yeah, you need to intern

Santiago Pastorino (Oct 10 2019 at 20:12, on Zulip):

yeah that was my guess

Santiago Pastorino (Oct 10 2019 at 20:12, on Zulip):

shouldn't one be able without that?

Santiago Pastorino (Oct 10 2019 at 20:13, on Zulip):

List is a wrapper around a slice so I'd like to move the slice inside the List and return a pointer to that just created wrapper

simulacrum (Oct 10 2019 at 20:16, on Zulip):

List specifically is "I am interned"

simulacrum (Oct 10 2019 at 20:17, on Zulip):

https://github.com/rust-lang/rust/blob/9c588c1e2391c20c156814f7ae118f62e96a3976/src/librustc/ty/mod.rs#L608-L613

simulacrum (Oct 10 2019 at 20:17, on Zulip):

at least per the doc comment on it

Santiago Pastorino (Oct 10 2019 at 20:25, on Zulip):

yeah maybe I can talk about the specific case I'm hitting ...

Santiago Pastorino (Oct 10 2019 at 20:25, on Zulip):

I'm trying to use it inside a Cow

Santiago Pastorino (Oct 10 2019 at 20:25, on Zulip):

I want to create copies on write but copies may not happen and I want to do nothing

Santiago Pastorino (Oct 10 2019 at 20:27, on Zulip):

the problem is that I can't wrap a List in a Cow so I end converting it to a slice at some point but if nothing happens I want the List back out of that slice

Santiago Pastorino (Oct 10 2019 at 20:28, on Zulip):

I have the original List still somewhere but was wondering if this could be done

simulacrum (Oct 10 2019 at 21:06, on Zulip):

I think what you want is basically not possible

simulacrum (Oct 10 2019 at 21:07, on Zulip):

maybe a custom cow that re-interns on write or something

Santiago Pastorino (Oct 10 2019 at 21:42, on Zulip):

the thing is I want that conversion when a write didn't occur, if I write occurs I needto reintern for sure

Santiago Pastorino (Oct 10 2019 at 21:42, on Zulip):

I meant, I have solved this in a different and better way

Santiago Pastorino (Oct 10 2019 at 21:42, on Zulip):

but still I was wondering in general if was possible to go from &[T] to &List<T>

simulacrum (Oct 10 2019 at 21:51, on Zulip):

sure, by interning for some T

simulacrum (Oct 10 2019 at 21:51, on Zulip):

but not otherwise

Last update: Nov 11 2019 at 22:00UTC