These are chat archives for rust-lang/rust

14th
Oct 2017
George Singer
@georgewsinger
Oct 14 2017 02:58
Consider from the Rust Book:
#[test]
fn calling_next_directly() {
    let mut counter = Counter::new();

    assert_eq!(counter.next(), Some(1));
    assert_eq!(counter.next(), Some(2));
    assert_eq!(counter.next(), Some(3));
    assert_eq!(counter.next(), Some(4));
    assert_eq!(counter.next(), Some(5));
    assert_eq!(counter.next(), None);
}
When we write let mut counter = ..., is counter a mutable reference to an object or the mutable object itself?
Zakarum
@omni-viral
Oct 14 2017 06:33
@georgewsinger it is mutable object
In this case it is a mutable object of type Counter
let ref mut counter = Counter::new(); this line creates mutable reference.
let mut counter = &mut Counter::new();
And this one too
xhallix
@xhallix
Oct 14 2017 07:38
@omni-viral thanks i will try later- trying to get another approach to work :)
Aleksandr Denisov
@alerdenisov
Oct 14 2017 12:47
Could you please suggest to me any great cargo to work with network? Games related is appreciated
Denis Lisov
@tanriol
Oct 14 2017 12:48
What kind of networking do you want? Client-server communication?
Aleksandr Denisov
@alerdenisov
Oct 14 2017 12:48
I know here is std::net, but I'm looking for something more high level
@tanriol exactly
Main goal to obtain inputs from clients and broadcasting udpated state
Zakarum
@omni-viral
Oct 14 2017 13:11
@alerdenisov look at tokio
Aleksandr Denisov
@alerdenisov
Oct 14 2017 13:24
@omni-viral thx i will
Aleksandr Denisov
@alerdenisov
Oct 14 2017 18:05
guys, why TransformBundle was removed with 0.5.1?
As I see in previous version ecs::transform contains bundle.rs but since 0.5.1 this is gone
Denis Lisov
@tanriol
Oct 14 2017 18:27
@alerdenisov Did you mean to ask this in the amethyst chat?
Looks like it was introduced after 0.5.1, no?
Aleksandr Denisov
@alerdenisov
Oct 14 2017 18:54
oh, sorry guys
missed with chat
Morgan Nesbitt
@MorganNesbitt
Oct 14 2017 19:17
Hi Everyone, does anyone have any experience with creating builds builds for alpine linux? I've tried running builds from various docker images and I keep getting stuck with some linker issues
Denis Lisov
@tanriol
Oct 14 2017 19:57
Are you using the corresponding -musl target?
Morgan Nesbitt
@MorganNesbitt
Oct 14 2017 21:10
i am, i actually just got it to build after passing RUSTFLAGS="-C linker=musl-gcc", but now its not statically linking the mysqlclient
or i should say i was using one of the musl docker images and just doing cargo build --release.
blankhart
@blankhart
Oct 14 2017 21:33
hi there, just started with Rust and this naive stack implementation:
pub enum List<T> {
  Nil,
  Cons { head: T, tail: Box<List<T>> }
}

impl<T> List<T> {

  pub fn push(&mut self, elem: T) {
    let tail = Box::new(mem::replace(self, List::Nil));
    *self = List::Cons { head: elem, tail: tail };
  }

  pub fn pop(&mut self) -> Option<T> {
    match mem::replace(self, List::Nil) {
      List::Nil => None,
      List::Cons { head, tail } => {
        *self = *tail;
        Some(head)
      }
    }
  }

}
the default implementation of the Drop trait is not stack-safe, but pattern matching breaks if Drop is implemented
the reason seems to be that you can't destructure a Dropable variable because Drop might try to use the missing fields
however, it seems to me that you should be able to do this as long as you move all of the fields. Is that right?
i.e., if there were some kind of exhaustiveness check to ensure that you moved all of the fields after destructuring, the compiler shouldn't complain
Denis Lisov
@tanriol
Oct 14 2017 21:42
There's an RFC about something like this: rust-lang/rfcs#2061
blankhart
@blankhart
Oct 14 2017 21:47
oh look at that! that is encouraging
thank you