These are chat archives for rust-lang/rust

11th
Oct 2017
matrixbot
@matrixbot
Oct 11 2017 04:28
Zanny Is there any way to compose static &strs from other static &strs? Like I have three strings foo bar and baz and want baz to be foo + bar, but foo and bar are defined elsewhere in the crate and I want to have a single point of change on them.
Alexander Ronald Altman
@pthariensflame
Oct 11 2017 06:48
@Zanny Maybe concat! suits your needs?
samoylovfp
@samoylovfp
Oct 11 2017 09:13
Hi! I'm curious why this line is necessary https://doc.rust-lang.org/src/alloc/vec.rs.html#811 Can someone explain?
Zakarum
@omni-viral
Oct 11 2017 10:18
@samoylovfp My guess - it isn't
But maybe was
David Pedersen
@davidpdrsn
Oct 11 2017 13:31
I am having issues with the postgres crate and connecting to a database on heroku. I believe it has something to do with openssl, but google doesn't give me anything. https://gist.github.com/davidpdrsn/258e584030582f1060d018516bb0957b
and the error is
thread 'main' panicked at 'failed to connect: Error(Tls(Failure(MidHandshakeSslStream { stream: SslStream { stream: TcpStream { addr: V4(192.168.1.12:51332), peer: V4(54.228.220.197:5432), fd: 5 }, ssl: Ssl { state: "error", verify_result: X509VerifyError { code: 18, error: "self signed certificate" } } }, error: Ssl(ErrorStack([Error { code: 337047686, library: "SSL routines", function: "tls_process_server_certificate", reason: "certificate verify failed", file: "ssl/statem/statem_clnt.c", line: 1230 }])) })))', src/libcore/result.rs:859
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
   1: std::panicking::default_hook::{{closure}}
   2: std::panicking::default_hook
   3: std::panicking::rust_panic_with_hook
   4: std::panicking::begin_panic
   5: std::panicking::begin_panic_fmt
   6: rust_begin_unwind
   7: core::panicking::panic_fmt
   8: core::result::unwrap_failed
   9: <core::result::Result<T, E>>::expect
  10: run::main
  11: __rust_maybe_catch_panic
  12: std::rt::lang_start
  13: main
Zakarum
@omni-viral
Oct 11 2017 13:56
{ state: "error", verify_result: X509VerifyError { code: 18, error: "self signed certificate" } }
I think it has something to do with security policy
Zakarum
@omni-viral
Oct 11 2017 14:50

I've just pushed (one minute or something) new crate into crates.io but

Last Updated
3 hours ago

on the page

David Harvey-Macaulay
@alteous
Oct 11 2017 15:43
I'm confused about the behaviour of ops::Index for Copy types. Why isn't the output of this program u32 instead of &u32?
There's a bit of magic in the source code. How does index.index(self) work?
David Harvey-Macaulay
@alteous
Oct 11 2017 16:01
Never mind. Of course it works because the indexed value is stored in the slice itself. In the case of Copy types the reference is implicitly copied to a new concrete value.
Zakarum
@omni-viral
Oct 11 2017 18:02

@tanriol

To derive-based syntax like in derive-error-chain

I like it!

francewar
@francewar
Oct 11 2017 18:07
hey all
I am coming from GO and i have some questions regarding rust
David Harvey-Macaulay
@alteous
Oct 11 2017 18:07
Hi! Fire away. :smile:
francewar
@francewar
Oct 11 2017 18:07
how easy / hard is it to do things in rust compared to C? Can i do everything i could do in C with the same amount / less code in rust?
this might be a little too general of a question
David Harvey-Macaulay
@alteous
Oct 11 2017 18:12
It is quite a general question. Rust is designed to be a systems programming language, so it has many of the capabilities of C, but with modern programming language features that prevent common logic errors (null pointer, unchecked return codes, etc.) as well as memory safety errors (segfaults and data races).
francewar
@francewar
Oct 11 2017 18:13
how productive are you using it compared to c?
I would assume that you are more productive with c initially but then having all those safety guarantees should pay off big?
Steve Klabnik
@steveklabnik
Oct 11 2017 18:14
for me, you have to compare the whole time it takes to work on something
so like, maybe i can knock out a quick thing in C, but then i end up chasing bugs for a while
David Harvey-Macaulay
@alteous
Oct 11 2017 18:14
I'm more productive now writing Rust than writing C, however there was a sharp learning curve.
Steve Klabnik
@steveklabnik
Oct 11 2017 18:14
with rust, it might take me slightly longer (though sometimes I think that it's just straight-up faster), but i spend almost no time debugging
especially with stuff like being able to use packages
francewar
@francewar
Oct 11 2017 18:15
oh yes thats a big plus too
Steve Klabnik
@steveklabnik
Oct 11 2017 18:15
for "real" stuff, much faster with rust these days
David Harvey-Macaulay
@alteous
Oct 11 2017 18:16
If you're writing 'high-level' code then you'll probably be more productive using Rust. For 'low-level' code you might be less productive.
francewar
@francewar
Oct 11 2017 18:16
Can you define what you mean with low level?
David Harvey-Macaulay
@alteous
Oct 11 2017 18:18
Examples of what I'd consider to be 'low-level' are FFI bindings and working with binary data.
^^ I wrote this code and it took a lot longer than it would if I were using C.
francewar
@francewar
Oct 11 2017 18:20
hmm interesting..
David Harvey-Macaulay
@alteous
Oct 11 2017 18:20
See https://github.com/gltf-rs/mikktspace/blob/master/src/lib.rs for FFI binding example too. That's the actual Rust -> C interface.
francewar
@francewar
Oct 11 2017 18:23
what is the deal with WASM? can you do any serious frontend development using rust?
Steve Klabnik
@steveklabnik
Oct 11 2017 18:23
wasm is better for calculation stuff at the moment
than for UI stuff
francewar
@francewar
Oct 11 2017 18:24
do you think in a couple years youll do your frontend development in rust?
Or do you think JS is here to stay
Michal 'vorner' Vaner
@vorner
Oct 11 2017 18:27
I'm pretty sure someone will create bunch of libraries that'll allow you to write everything in Rust whole-stack, from the kernel on the server, to the code running in the browser. Some people are just fanatical enough to do it just because they can. But I also think javascript won't go away any time soon. There are too many developers that use and like JS.
francewar
@francewar
Oct 11 2017 18:28
I really don't like JS :/ i am using react with typescript now which is alright though
Michal 'vorner' Vaner
@vorner
Oct 11 2017 18:31
I don't use JS myself (mostly because I don't do frontend, so I don't have to). But I mean, old code and habits die slowly. Nowadays, nobody tells the beginner „You should really start by learning PHP, that's the best language for you“. Still, there's a lot of PHP development happening even when there are better choices now, simply because it was popular at the time. And JS is definitely easier to learn than Rust, so realistically I think JS won't just disappear in the next 10 years or so.
If you look, there are still companies hiring fortran programmers.
Steve Klabnik
@steveklabnik
Oct 11 2017 18:32
there's one prototype rust frontend web framework
but wasm/asm isn't intended to replace js
francewar
@francewar
Oct 11 2017 18:48
i hear that often
but it kinda does seem to do so
if you look at the proposed specs
and why not? Wouldn't it be amazing if you could write something once and really run it everywhere?
krevativ
@krevativ
Oct 11 2017 20:08

@francewar Hi there, I will use this question to write down something I was thinking about a lot in the last time. I am a JavaScript developer. I can't say much about rust because I still learning it. But I can say something about rust compared to JavaScript. First I really like JavaScript and do it already for many years, before the name web-developer even existed. Because I could freely express my self in this language and because at least for now, it is a single choice where you can write stuff in a one language and reach at least a huge amount of other platforms with a good enough performance. The community is huge. There is rarely the case where you really need to go native now.

I would give my left leg for having one language for everything. And if it is so fast and safe like rust, you can have my right leg too. But there simply can’t be such language. Each language has its benefits. And I don’t think that this will ever change because companies like Microsoft, Apple, Google etc. have a financial interest not to go this way. This is the way how they can bind us as developers to their company. So be careful (Especially if it comes to microsoft products if you ask me). But why do I learn rust? There are many reasons. I was loosing my interest, because you don’t learn anything really new regarding the computer science in the JS world now. Only how to prevent and fix terrible mistakes, how to use a new fancy library or the next overhyped feature. There is a bunch of terrible browsers out there: android stock browsers, safari and THE terrible internet explorer. This is not easy to account them all this days. The community is also not what it was once upon a time. There are a lot of newcomers with low knowledge who are talking a lot of stupid things. And then something becomes a hype and you are forced to use it because it is your job. And there is actually no JavaScript anymore, because such companies like the above, are fragmenting the JavaScript world with such syntax sugar languages like TypeScript, Go, ELM, CoffeeScript etc. And there is the JavaScript Fatigue. All of this things make JavaScript a terrible language for me this days. And because of rust I found my interest again and a lot of new ideas. And when it comes to performance and safety, this is what JavaScript can’t give me. So rust is a good tool to have in your pocket anyway. And even if not for production. With appearance of such type systems like TypeScript and Flow, rust is a good way to learn something about types and programming in general. JavaScript is a bad language to start with. It let you do what you want however you want, so you need to know what you are doing before you are doing it.

And what do I think what rust is missing to make me the happiest developer in the world? First I think a lot of crates are missing more examples on how to use them. They are expecting you also to know what you are doing before you are doing it. I think this is bad to compare things, to learn things and if you want just to discover something new. And there is a C-barrier too. If you know C this is great for you. Otherwise it hard to learn two languages at once. Especially such language like C. But you will find your self in a situation where you need to use some kind of C library that not exists in rust yet. I think rust community need to change it if they want have more success. Next there are some other things that are scaring me. The features for the async stuff scare me for example. But as I know this should change in the future. The lifetimes annotations scare me too. I think they are confusing and redundant in a lot of cases. Why do the compiler can’t figure it out by him self? This is what I ask me very often. And the last thing that I miss, is an easy way to create simple objects and extend them easily, pass them around and modify them by adding and deleting keys. This is what I really like about JavaScript. When it comes to interactive cross platform user interfaces with a lot of data, this is what I need. And I need at least a small amount

of OOP because it is very useful for creating interfaces.

So that all. And don’t forget, the rust community is great too! And sorry for my terrible english I am not a native speaker.

Judson Lester
@nyarly
Oct 11 2017 22:00
Confusing point I've just hit twice quickly:
map() takes a FnMut(Self::Item), but .map on a SocketListener.incoming (which should be an Incoming where the Item is Result<UnixStream>) complains if I call Result methods on the argument, claiming "found struct std::os::ext::net::UnixStream" - but if I for stream in... the stream behaves like a Result.