These are chat archives for rust-lang/rust

10th
Nov 2018
laurent bernabé
@loloof64
Nov 10 2018 07:36
Hi everyone, maybe still a basic issue again with the borrow checker
#[derive(Default)]
pub struct Model {
    position: Chess,
}

impl Model
{
    fn play(&mut self, move_to_play: &Move){
        self.position.play(move_to_play);
    }
}
Why does the compiler prevent me from using self inside the play method, though I am just pointing to the position field of Model structure ? (Cannot move out of borrowed content)
Andrey Lesnikov
@ozkriff
Nov 10 2018 07:39
what's the signature of Chess::play?
laurent bernabé
@loloof64
Nov 10 2018 07:39
I'm going to look right now, it is from the shakmaty crate.
fn play(self, m: &Move) -> Result<Self, IllegalMoveError>
And declared in a Position class from the same crate
Andrey Lesnikov
@ozkriff
Nov 10 2018 07:41
this play method consumes self and returns a new one
laurent bernabé
@loloof64
Nov 10 2018 07:42
Ok, I understand better : thank you :smile:
Indeed, I notice that play method does not do any borrow on self
laurent bernabé
@loloof64
Nov 10 2018 07:47
Does this attempt sounds quite good (still have errors) ?
impl Model
{
    fn play(self, move_to_play: &Move) -> Self {
        let result = &mut self.position.play(move_to_play);
        match result {
            Ok(_) => self,
            _ => self,
        }
    }
}
(self value used after move)
laurent bernabé
@loloof64
Nov 10 2018 07:57
Maybe that lone snippet is too few in order to undestand what makes me into trouble
I'm using Relm / Shakmaty / Rust_chessground crates.
laurent bernabé
@loloof64
Nov 10 2018 08:05
After a better analyse of the problem, I've rewritten my play method like this, but still having a borrow error
fn play(&mut self, move_to_play: &Move) {
        let play_result = self.position.play(move_to_play);
        match play_result {
            Ok(position) => self.position = position,
            _ => {}
        }
    }
cannot move out of borrowed content
  --> src/main.rs:38:27
   |
38 |         let play_result = self.position.play(move_to_play);
   |                           ^^^^ cannot move out of borrowed content
Denis Lisov
@tanriol
Nov 10 2018 08:11
I'm afraid you'll need to store position: Option<Chess> to be able to self.position.take().play(move_to_play)
laurent bernabé
@loloof64
Nov 10 2018 08:12
Thank you, so I'll try this way. So I'll have to remove the Default attribute in the model.
laurent bernabé
@loloof64
Nov 10 2018 08:18
Otherwise, as I always need to store a Position, even if it remains the same on IllegalMove, I tried to rather play with references this way, but still one borrow error to solve
cannot move out of borrowed content
  --> src/main.rs:38:27
   |
38 |         let play_result = self.position.play(move_to_play);
   |                           ^^^^ cannot move out of borrowed content
aohan237
@aohan237
Nov 10 2018 08:56
Let a =123; a+=123; what’s the difference compared to and_then? Let a = (123).and_then(123+1);
Suddenly,confused about and_then
miss a mug..
mut
uncotion
@uncotion
Nov 10 2018 10:25
Hi bros, how can i access a variable inside of future map ?
                let u = 12;
                (r.body()
                    .from_err::<actix_web::error::PayloadError>()
                ).map(|f| {
//access u here
})
Zakarum
@omni-viral
Nov 10 2018 10:36
I want type to store either &mut T or T, implement AsMut<T> and has method like into_owned(self) -> Result<T, Self>.
Would I have to write it myself or there is already such a thing?
tandrysyawaludin
@tandrysyawaludin
Nov 10 2018 18:45
Does anyone know why i got this error when i run my application on Heroku?
Application error An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command heroku logs --tail
here my Procfile web: ROCKET_PORT=$PORT ROCKET_ENV=production ./target/release/trashbuddy
Denis Lisov
@tanriol
Nov 10 2018 18:46
Not enough information. You really need to check the logs.
tandrysyawaludin
@tandrysyawaludin
Nov 10 2018 18:48
Screen Shot 2018-11-11 at 01.48.10.png
it is what log said
Denis Lisov
@tanriol
Nov 10 2018 18:52
There's the top part about failing to connect to localhost:5432. Are you trying to use Heroku Postgres?
tandrysyawaludin
@tandrysyawaludin
Nov 10 2018 18:53
my app use Postgres but i haven't used Heroku Postgres
Denis Lisov
@tanriol
Nov 10 2018 18:56
Have you actually started the database server?
tandrysyawaludin
@tandrysyawaludin
Nov 10 2018 19:00
Do you mean I have to install Heroku Postgres?
Denis Lisov
@tanriol
Nov 10 2018 19:02
You need to have a database. This may be Heroku Postgres or something else. But most databases require a special process that's managing the database itself, which you probably don't start. I don't know in detail Heroku limitations, so it may be possible to just run Postgres there... or not.
tandrysyawaludin
@tandrysyawaludin
Nov 10 2018 19:11
okay thank you, maybe I will try to configure with heroku postgres first