These are chat archives for rust-lang/rust

9th
Sep 2017
Alexander.Positivinn
@ailjushkin_twitter
Sep 09 2017 15:54
Hi, could you please point on rust style guidelines
David Harvey-Macaulay
@alteous
Sep 09 2017 15:55

@ailjushkin_twitter

Here's a good starting point. https://rust-lang-nursery.github.io/api-guidelines/ :smile:

For code style you might want to check rustfmt out.
Although it won't catch naming practices.
Alexander.Positivinn
@ailjushkin_twitter
Sep 09 2017 15:57
Thanks, I'm a one-day learner, and I found that there's N ways of how to do simple tasks. I simply complicated of what approach to use
Robert Peters
@r2p2
Sep 09 2017 16:01
stick to one until your project works, if it works, test the other ones. in that order
Alexander.Positivinn
@ailjushkin_twitter
Sep 09 2017 16:03
Thank you @r2p2
Robert Peters
@r2p2
Sep 09 2017 17:06
Is there a way to get the last element of a vec as mutable reference and the second last element of a vec as immutable reference? split_last and split_last_mut just return &,& and &mut, &mut but I need some sort of &, mut&
Aleksey Kladov
@matklad
Sep 09 2017 17:41
@r2p2 I think you can split_last_mut and then coerce the first&mut to &
Robert Peters
@r2p2
Sep 09 2017 17:47
It is amazing what the borrow checker does. It feels like I is impossible to implement bugs.
Aleksey Kladov
@matklad
Sep 09 2017 17:48
Only memory safety/data-races related bugs :)
Alexander.Positivinn
@ailjushkin_twitter
Sep 09 2017 18:03
Ha) your customer won't think so ;)
Robert Peters
@r2p2
Sep 09 2017 18:03
hrhr
David Harvey-Macaulay
@alteous
Sep 09 2017 18:19
And type errors, and null pointer bugs...
Oh we're only talking about the borrow checker :smile:
Alexander.Positivinn
@ailjushkin_twitter
Sep 09 2017 18:24
For me it looks like that demotivator, saying "you can't just simply start programming" 😊
Robert Peters
@r2p2
Sep 09 2017 18:30
Yea, you think you've got a solution and it says: "Nope, think again about reordering and restructuring your damn variables". I see the point, its just sometimes not that obvious for a beginner. Don't know if that becomes easier after some weeks?
Oh look, par_iter_mut() does not support take(n) :worried:
David Harvey-Macaulay
@alteous
Sep 09 2017 20:00
Is it possible to write doc tests that call macros from the host crate?
That is, if I export a macro foo! in my crate, can I use it in doc tests elsewhere in my crate?
David Harvey-Macaulay
@alteous
Sep 09 2017 20:06

I have the following situation.

/// # Example
///
/// '''rust
/// let x = foo!();
/// '''

error: cannot find macro foo! in this scope

Alexander.Positivinn
@ailjushkin_twitter
Sep 09 2017 20:41
@alteous seems like this is separate contexts. So you should import this macro inside your doc. https://users.rust-lang.org/t/how-to-use-a-macro-in-the-doc-test/3664
David Harvey-Macaulay
@alteous
Sep 09 2017 20:54

@ailjushkin_twitter

Thanks! I made the following changes and it worked ok.

/// # #[macro_use] extern crate foo;
/// # fn main() {
/// let x = foo!();
/// # }