These are chat archives for rust-lang/rust

13th
Jun 2018
Paul Masurel
@fulmicoton
Jun 13 2018 00:00
@dongcarl you can check how it is done in the fst / fst-bin crate . https://github.com/BurntSushi/fst/blob/master/fst-bin/Cargo.toml
James Sewell
@jamessewell
Jun 13 2018 00:00
Result covers any (returnval, error) pair really
Paul Masurel
@fulmicoton
Jun 13 2018 00:00
note that the produced binary does not need to be called fst-bin.
Denis Lisov
@tanriol
Jun 13 2018 00:01
@fulmicoton Why make them separate crates at all?
Paul Masurel
@fulmicoton
Jun 13 2018 00:03
Can you define a different set of dependencies if they are in the same crate ?
Also if you have more than one binary target, you still have to pick one as the main one to be installed when people cargo install yourcrate
(correct me if I am wrong)
@jamessewell For invalid argument, it is not uncommon to express that as an error, or panic. It is kind of the same story as RuntimeException CheckedException in Java.
Is there a chance your client will want to manage the error or not?
James Sewell
@jamessewell
Jun 13 2018 00:08
I suppose it depends where the code lives too, you’d be less inclined to panic in a public library fn right?
Paul Masurel
@fulmicoton
Jun 13 2018 00:08
Yes.
Denis Lisov
@tanriol
Jun 13 2018 00:09
You can make these dependencies optional and make the binary build require them. cargo-install by default installs all binaries (it's not limited to just one).
Paul Masurel
@fulmicoton
Jun 13 2018 00:10
@tanriol thanks for the info.
Making the dependencies optional is a bit cumbersome if there is a lot of them, I think I'll stick to different crate for tantivy-cli as there are a lot of those...
Denis Lisov
@tanriol
Jun 13 2018 00:16
That's certainly a possible choice :-) although I'd guess a good helper crate like quicli can replace quite a number of them.
Judson Lester
@nyarly
Jun 13 2018 05:14
Confirming: impl Trait is not yet available as the return type of trait methods and associated functions?
In stable, anyway?
trsh
@trsh
Jun 13 2018 10:35
Hi guys I have this error no idea why
pub fn process(&mut self, pd: Box<ProcessData>) -> Box<Future<Item = (), Error = String>> {
    .....

    self.processData = Some(pd);

    let bd = &self.processData;
    let ss = &bd.unwrap();
let ss = &bd.unwrap();
| ^^ cannot move out of borrowed content
But I am borrowing it?!
Guillaume P.
@TeXitoi
Jun 13 2018 10:39
@trsh let ss = bd.as_ref().unwrap();
bd.unwrap() move out the value, Option::as_ref is exactly what you need
trsh
@trsh
Jun 13 2018 10:44
@TeXitoi tnx, it worked
trsh
@trsh
Jun 13 2018 11:18
This programming language can take weeks to acompilsh simple things :/
muutable, immutable, cant barrow here .. so pissed going on vacation orsmth
Dylan DPC
@Dylan-DPC
Jun 13 2018 11:49
@trsh yeah but all this ensures you write better and safe code :)
trsh
@trsh
Jun 13 2018 12:20
Isn't this a bug?
fn forward_process(&mut self, node: &'a NodeData) -> Box<Future<Item = (), Error = String>> {
    let nodes = self.nodes.expect("Nodes empty, can't process");
    let connection_nodes_flat = node
      .outputs
      .iter()
      .flat_map(|output| {
        output
          .connections
          .iter()
          .flat_map(|c| {
            let c_node = nodes
              .get(&c.node.to_string())
              .expect("Unknown output connection node");

            vec![self.back_process(c_node), self.forward_process(c_node)]
          })
          .collect::<Vec<_>>()
      })
      .collect::<FuturesOrdered<_>>();

    Box::new(connection_nodes_flat.for_each(|_| Ok(())))
  }
Im borrowing nodes immutable, and then mutable! Could set it to None in every moment and references would messed up
Thibault Delor
@thibaultdelor
Jun 13 2018 12:35
As far as i can tell nodes is mutable because it belong to self
trsh
@trsh
Jun 13 2018 12:39
let nodes
Fredrik Portström
@portstrom
Jun 13 2018 14:25

@trsh Well, Rust isn't Yet Another Language that just puts some new syntax on old features from the 60s that every programmer already knows, so learning Rust is challenging in the same way as learning programming in the first place. Python I learned in 30 minutes reading a blog post. Rust I learned in two months making a toy program. After a few more months of Rust, it's as productive as Python, but gives me the same performance and control as C.

I think that Rust will be highly influential, and soon more languages will have ownership, borrowing, controlled mutability and many other features from Rust, and these features will become part of what every programmer knows. The next generation of programmers who will have this knowledge will likely not say that Rust is a particularly difficult language.

Michal 'vorner' Vaner
@vorner
Jun 13 2018 14:32
Well, there's also the other part about Rust being rather low-level. It expects you to know what memory is, the difference between stack and heap, that you need to allocate and free it, when it happens, etc. It's syntax and semantics are rich, which means a lot to learn. You can get away without knowing this in python. Sure, you get something in return after learning all that, but I don't think the next generations will consider Rust one of the easy languages. Anyway, even today, Rust is probably easier to learn than C++ (the difference is, in Rust it's the compiler that complains, with C++ it's the colleagues).
trsh
@trsh
Jun 13 2018 15:15
tnx for this info
Maximilian Alexander
@mbalex99
Jun 13 2018 20:25
Hi all. I'm new to Rust, but what's a good place to learn (besides the rust-book) about Rc, Arc, and Box<T>
Dmitriy
@dpogretskiy
Jun 13 2018 20:34
docs.rs is a good one, you can read sources and all the docs, inluding standard library
Rust -> Standard library API reference, somewhere around there
Ash
@ashthespy
Jun 13 2018 20:36
The tests also helps quite a bit :-)
Dmitriy
@dpogretskiy
Jun 13 2018 20:37
Yeah, use it and see what happens, but if you are obsessed with reading, there is plenty
Maximilian Alexander
@mbalex99
Jun 13 2018 20:40
Thanks a lot!
polypus74
@polypus74
Jun 13 2018 22:07
Should the following fail with a stack overflow, because it is:
fn main() {
    let mut img = [0 as u8; 8000 * 6000];
    for (y, ps) in img.chunks_mut(8000).enumerate() {}
}
Dmitriy
@dpogretskiy
Jun 13 2018 22:22
it's a huge stack allocated array, my bet is yes
polypus74
@polypus74
Jun 13 2018 22:26
doh. when i removed the for loop it was not overflowing, so i was thinking it was some sort of limit of chunks_mut, which being lazy would be odd. but i see now that the for loop was just pushing the stack memory to it's limit probably.