These are chat archives for rust-lang/rust

11th
Apr 2019
svraghavan
@svraghavan
Apr 11 00:21
@tanriol Thanks alot for the pointer.
Ichoran
@Ichoran
Apr 11 00:39
@weiznich - Ownership is perfect for preventing multi-time use.
John
@onFireForGod_gitlab
Apr 11 02:36
how do I use a non clonnable object multiple times?
        let mut query = wf::table.into_boxed();
        query = query.filter(wf::forecast_time.eq(msg.forecast_date));
        if let Some(date) = msg.start_date { 
            query = query.filter(wf::time.ge(date)); 
        } 
        if let Some(date) = msg.end_date { 
            query = query.filter(wf::time.le(date)); 
        }


        let resultpdx: Vec<WeatherForecastData> = query
            .filter(wf::location_name.eq("PDX"))
            .order(wf::time.asc())
            .load::<WeatherForecastData>(conn)
            .map_err(|e| error::ErrorInternalServerError(e))?;

        let resultsea: Vec<WeatherForecastData> = query
            .filter(wf::location_name.eq("SEA"))
            .order(wf::time.asc())
            .load::<WeatherForecastData>(conn)
            .map_err(|e| error::ErrorInternalServerError(e))?;

        let resultgeg: Vec<WeatherForecastData> = query
            .filter(wf::location_name.eq("GEG"))
            .order(wf::time.asc())
            .load::<WeatherForecastData>(conn)
            .map_err(|e| error::ErrorInternalServerError(e))?;
error[E0382]: use of moved value: `query`
   --> src/db/routes/weather.rs:105:51
    |
73  |         let mut query = wf::table.into_boxed();
    |             --------- move occurs because `query` has type `diesel::query_builder::BoxedSelectStatement<'_, (diesel::sql_types::BigInt, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Nullable<diesel::sql_types::Double>, diesel::sql_types::Nullable<diesel::sql_types::Double>, diesel::sql_types::Datetime, diesel::sql_types::Datetime, diesel::sql_types::Nullable<diesel::sql_types::Datetime>, diesel::sql_types::Nullable<diesel::sql_types::Datetime>, diesel::sql_types::Nullable<diesel::sql_types::Double>, diesel::sql_types::Nullable<diesel::sql_types::Double>, diesel::sql_types::Nullable<diesel::sql_types::Double>, diesel::sql_types::Nullable<diesel::sql_types::Double>, diesel::sql_types::Nullable<diesel::sql_types::Double>, diesel::sql_types::Nullable<diesel::sql_types::Double>, diesel::sql_types::Nullable<diesel::sql_types::Double>, diesel::sql_types::Nullable<diesel::sql_types::Double>, diesel::sql_types::Nullable<diesel::sql_types::Double>, diesel::sql_types::Nullable<diesel::sql_types::Double>, diesel::sql_types::Nullable<diesel::sql_types::Double>, diesel::sql_types::Nullable<diesel::sql_types::Double>, diesel::sql_types::Nullable<diesel::sql_types::Double>, diesel::sql_types::Nullable<diesel::sql_types::Double>), schema::weather_forecast::table, diesel::mysql::Mysql>`, which does not implement the `Copy` trait
...
99  |         let resultsea: Vec<WeatherForecastData> = query
    |                                                   ----- value moved here
...
105 |         let resultgeg: Vec<WeatherForecastData> = query
    |                                                   ^^^^^ value used here after move
aohan237
@aohan237
Apr 11 02:40
the type parameter T is not constrained by the impl trait, self type, or predicates unconstrained type parameter
what does this mean?
not constrained??
Denis Lisov
@tanriol
Apr 11 07:51
@onFireForGod_gitlab If it is not cloneable, you need to build multiple queries.
John
@onFireForGod_gitlab
Apr 11 07:52
that sounds kinda silly
        let mut query = wf::table.into_boxed();
        query = query.filter(wf::forecast_time.eq(msg.forecast_date));
        if let Some(date) = msg.start_date { 
            query = query.filter(wf::time.ge(date)); 
        } 
        if let Some(date) = msg.end_date { 
            query = query.filter(wf::time.le(date)); 
        }
basically copy paste this 3 times, just change the var name
Denis Lisov
@tanriol
Apr 11 07:56
You can make a function for that and do /*...*/ = make_query_template(msg)/*...*/
Denis Lisov
@tanriol
Apr 11 08:04
@aohan237 Rust requires the type parameter to be actually used somewhere in the type the impl is for, or the trait that is being implemented if that's a trait impl, or in associated types if there are any. Otherwise Rust would have no way to choose which parameter value it is supposed to use.
Georg Semmler
@weiznich
Apr 11 09:09
@Ichoran It's not about perventing multi-time usage (The type is even Copy :wink:), it's about prevent specific forms of multi-time usage. (Like referencing something that has not been defined before or preventing defining it multiple times.)
Paul Delafosse
@oknozor
Apr 11 11:58
hello, i am having trouble to understand how conditional compilation works, i just need one line to be compiled in "debug" mode or else compile another one. Is there some default configuration attribute for that ?
Zakarum
@omni-viral
Apr 11 11:58
IIRC #[cfg(debug_assertions)]
Paul Delafosse
@oknozor
Apr 11 11:59
i know, i am currently reading this
but it's unclear to me how to pass it via cargo rustc
Zakarum
@omni-viral
Apr 11 12:00
cargo --release disables it
Ingvar Stepanyan
@RReverser
Apr 11 12:00
yeah you don't need to pass it, it's the default
unfortunately, it doesn't give 100% guarantee because someone might want to build release build with debug assertions, but that's the closest to it anyway
Paul Delafosse
@oknozor
Apr 11 12:00
ahah i am so stupid
it will do
thank you !