These are chat archives for rust-lang/rust

9th
Dec 2018
Will Page
@compenguy
Dec 09 2018 05:32
is anyone here familiar with a data structure that keeps track of "seen" values, and keep a single copy of each seen value, and everywhere else that uses it just has an Rc of that value?
I'm specifically thinking in the case of an xml parser, for a particular schema or document type, there's a well known set of tag names, attribute names, sometimes the attribute values are constrained, etc
so each time the xml parser sees a tag with a particular name, rather than keeping a separate copy of the string for each instance of the tag, or requiring that the original text of the document remain resident so that you can hold a reference to it, you keep a pool of "seen" strings, and each tag just has an Rc of it
Rotem Yaari
@vmalloc
Dec 09 2018 07:01
So apparently rustfmt removes prefix :: to use statements, causing code to break - I'm guessing I'm not the first one hitting this. Anyone knows of a tracking issue I can subscribe to to know when this is fixed?
Denis Lisov
@tanriol
Dec 09 2018 09:05
@compenguy You may want to look at the string_interner crate.
You can also find others by searching for interning on crates.io
Will Page
@compenguy
Dec 09 2018 17:47
interesting
thanks, @tanriol
David O'Connor
@David-OConnor
Dec 09 2018 21:02

Is there a way to implement a trait for a closure? Relevant link that I can't get working.

impl<Ms: 'static> Update<Listener<Ms>> for Box<FnMut(String) -> Ms + 'static> {
    fn update(self, listener: &mut Listener<Ms>) {
        listener.setup(self);
    }
}

The error, when passing it a closure of the appropriate type, I receive the error:

no method named `update` found for type ```std::boxed::Box<[closure@examples\counter\src\lib.rs:131:24: 131:59]>

When using closures like this elsewhere, the type needs to have impl prepended, eg Box<impl FnMut(String) -> Ms + 'static>, but this is forbidden:

 `error[E0562]: impl Trait` not allowed outside of function and inherent method return types

Any ideas? I can't get the From workaround in the link above working.

David O'Connor
@David-OConnor
Dec 09 2018 21:13

Clarification: This is what it would look like with the Where clause:

impl<Ms: 'static> Update<Listener<Ms>> for Box<F> where F: FnMut(String) -> Ms + 'static {
    fn update(self, listener: &mut Listener<Ms>) {
        listener.setup(self);
    }
}

With this as the only impl Update, it works, but when I have others for other types that use a trait, I receive the error:

 conflicting implementation for `std::boxed::Box<_>`

Eg:

impl<Ms: 'static> Update<Listener<Ms>> for Box<Ms> {
    fn update(self, listener: &mut Listener<Ms>) {
        listener.setup2(self);
    }
}

It does appear to work if Ms is replaced by a normal type.