These are chat archives for rust-lang/rust

18th
Apr 2018
Andy Grove
@andygrove
Apr 18 2018 03:45
I'm wondering if I'm over complicating my code ...
struct AggregateEntry {
    group_values: Vec<ScalarValue>,
    aggr_values: Vec<Rc<RefCell<Rc<AggregateFunction>>>>
}
where AggregateFunction is a trait
is it normal to nest things like this in Rust?
I'm also struggling to borrow the AggregateFunction mutably in this case
I can get a mutable reference to the Rc<AggregateFunction> but not sure what to do next
Andy Grove
@andygrove
Apr 18 2018 03:50
this all seems overly complex though
Andy Grove
@andygrove
Apr 18 2018 04:07
I was able to simplify to
struct AggregateEntry {
    group_values: Vec<ScalarValue>,
    aggr_values: Vec<Box<AggregateFunction>>
}
Russell Cohen
@rcoh
Apr 18 2018 05:56
@andygrove I believe that's the best you can do -- you need the Box to be able to keep multiple different concrete types of the same trait in a list
You might also be able to use &T style types, but I'm not sure you'd be able to borrow mutably
This looks very similar to the processing engine angle grinder: https://github.com/rcoh/angle-grinder
you might find the code helpful
Michal 'vorner' Vaner
@vorner
Apr 18 2018 07:11
@andygrove It's quite common to nest the thnigs like this (though two Rcs might be unnecessary). If I find myself too deep in the nesting, I often introduce a type alias or an actual type with some methods that abstracts part of the nesting away, to stay sane.
Dylan DPC
@Dylan-DPC
Apr 18 2018 07:12
is there a way to flatten a Vec<Vec<String>> to a <Vec<String>
Michal 'vorner' Vaner
@vorner
Apr 18 2018 07:14
Something like outer_vec.into_iter().flat_map(IntoIterator::into_iter).collect::<Vec<_>>()
Dylan DPC
@Dylan-DPC
Apr 18 2018 07:15
ya that's what i was trying
ah i forgot the .cloned()
Michal 'vorner' Vaner
@vorner
Apr 18 2018 07:16
Cloned? Why? Don't you want to consume the old one and just reshape it?
Dylan DPC
@Dylan-DPC
Apr 18 2018 07:21
i'm passing a borrow atm because i might need the original vec
Manuel Holtgrewe
@holtgrewe
Apr 18 2018 14:32
I'm using the slog crate. I want to see debug!() output also when compiling in release mode. However, it appears that only log messages with info and above are printed there... What's the best pratice here? Use a different logger?
Denis Lisov
@tanriol
Apr 18 2018 14:40
@holtgrewe Maybe you need to set the corresponding features (updated link)?
Manuel Holtgrewe
@holtgrewe
Apr 18 2018 14:43
@tanriol yes, thanks
Ah, Rust is a great experience. I have "that's the way it should have worked with C++" moments all the time.
patientplatypus
@patientplatypus
Apr 18 2018 22:06
hi
anyone here?
Denis Lisov
@tanriol
Apr 18 2018 22:14
@patientplatypus Go ahead and ask :-)
patientplatypus
@patientplatypus
Apr 18 2018 22:17
im looking at this example here https://stackoverflow.com/questions/49227046/does-this-code-follow-observer-pattern
im looking to implement this observer pattern (the first answer) using named observers and named observables, but im not sure how to start
Basically I want to build this out to a point where a named observable is posting to only certain named named observers and another named observable is posting to other named observables.
@tanriol
Denis Lisov
@tanriol
Apr 18 2018 22:20
So you want to register an observer not using a reference to the struct being observed, but just by giving the same name?
patientplatypus
@patientplatypus
Apr 18 2018 22:22
I think so, I have a little difficulty in parsing what you said
yes
Denis Lisov
@tanriol
Apr 18 2018 22:32
Ok, so you need some central registry of observers. When you register an observer, it's added to the registry; when an event happens, you iterate over all observers that observe it and call every one. Does it make sense?
patientplatypus
@patientplatypus
Apr 18 2018 22:36
i think so, sure.
i would think i would change the observable struct to have a list of names rather than event vectors and and have the observer struct behave similarly. then have the actual event creation happen outside of the observable class in some other class. would that work?
then when the event is called it cycles through all the names in the observable struct
patientplatypus
@patientplatypus
Apr 18 2018 23:54