These are chat archives for rust-lang/rust

3rd
Sep 2018
Robert
@rw
Sep 03 2018 01:21
announcing official support for flatbuffers in rust: https://users.rust-lang.org/t/official-rust-flatbuffers-port-is-merged/20089
if I have a Vec<Foo>, and I want a Vec<Bar>, and there's an impl of From<Foo> for Bar, is the idiomatic way to do the conversion let bars: Vec<Bar> = foos.into_iter().map(Into::into).collect(); ?
thought there might be a built-in iterator adapter for this, or something in itertools, but didn't find anything
Krys
@Krysme
Sep 03 2018 05:25
into iter then map them
normally I would just map and use the Bars
instead of creating another vector
but, it depends
yes, indeed; in this case I need the vector
Krys
@Krysme
Sep 03 2018 05:33
however, it's trivial to write one yourself that collect the into'd type from the source type
Kelly Thomas Kline
@kellytk
Sep 03 2018 06:45
I'm viewing a Rust project with the latest Mac VS Code. How can I cause actix of use actix::prelude::*; to become a hyperlink into its code? Holding the command key while hovering usually does that but not in this case for some reason. (I asked this question in the VS Code channel however I think it's perhaps more relevant here)
Zakarum
@omni-viral
Sep 03 2018 06:56
This is called "Go to definition" I guess
Zakarum
@omni-viral
Sep 03 2018 07:01
@kellytk Do you use Rust (rls) extension?
Kelly Thomas Kline
@kellytk
Sep 03 2018 07:05
@omni-viral Yes I do. BTW "Go to definition" gives the message that "No definition found for 'actix'". The crate is installed locally via cargo install and I can see other code elements' definitions
I'm testing the behavior and it seems that the only use components which can show/go to their declarations are the last of each item unless it's a "*" which also does nothing. For example, in use std::fs; only fs would show/go to its definition
Zakarum
@omni-viral
Sep 03 2018 07:08
Try to Cmd+Shift+P and preform "Rust: Update the RLS"
Hmm. Yes. I see the same behaviour
Kelly Thomas Kline
@kellytk
Sep 03 2018 07:09
It would be helpful for learning and code exploration if that was expanded
Zakarum
@omni-viral
Sep 03 2018 07:10
You can change use xxx::*; to use xxx::{self, *};
And use go to definition on self
Also you can create an issue for rls. I don't think it is too hard to fix
Kelly Thomas Kline
@kellytk
Sep 03 2018 07:23
@omni-viral rust-lang-nursery/rls#1035 however I've noticed that there's a rls-vscode repo. I'm not familiar enough with the RLS architecture to know if I should I move or cross post the issue, do you know?
Zakarum
@omni-viral
Sep 03 2018 07:24
Not sure which, but I guess, rls-vscode integration causes the bug.
Kelly Thomas Kline
@kellytk
Sep 03 2018 07:25
I'll delete the issue and submit it to rls-vscode then
Zakarum
@omni-viral
Sep 03 2018 07:25
You can leave it there until someone more familiar with architecture come along and tell you the issue doesn't belong to the rls core
Kelly Thomas Kline
@kellytk
Sep 03 2018 07:28
I saw your message after I created rust-lang-nursery/rls-vscode#418 and closed the other :-)
Zakarum
@omni-viral
Sep 03 2018 07:29
¯\_(ツ)_/¯
Zakarum
@omni-viral
Sep 03 2018 12:59
If linter suggest an action that cause code to not compile is it a bug or a feature?
Michal 'vorner' Vaner
@vorner
Sep 03 2018 14:13
It depends. If that code that would compile would be unsecure or against the humanity, then it's a feature :-P. But in general, it sounds like a bug.
Sylwester Rąpała
@xoac
Sep 03 2018 14:16
Hi,
I would like to mark some structs with sth like this:
trait A {
    const MEM_ADDR: u32 ;
    const MEM_LEN: u32 ;
}

impl A for MutEnum {
    const MEM_ADDR: u32 = 45;
    const MEM_LEN: u32 = 100;
}

fn print_A(x: impl A) {
    println!("{}", <A as x>::MEM_ADDR);
}
is it possible with rust?
Zakarum
@omni-viral
Sep 03 2018 14:20
@xoac You can do this without impl Trait
fn print_A<X: A>(x: X) {
    println!("{}", <X as A>::MEM_ADDR);
}
Semantically your and my print_A are almost the same thing
Sylwester Rąpała
@xoac
Sep 03 2018 14:24
@omni-viral almost the same :) Your work my not :)
Thank you!
Zakarum
@omni-viral
Sep 03 2018 14:25
@xoac I mean the signature fn foo<T: Trait>(T) is almost the same as foo(impl Trait)
You're welcome
Krys
@Krysme
Sep 03 2018 15:13
hello
x
do I get UB if I cast a pointer like this info.as_ptr() as *const libc::c_char
where variable info is of type str
on the C side, casting between signed and unsigned chars is valid from what I know
Zakarum
@omni-viral
Sep 03 2018 15:36
@Krysme You won't get UB by the casting itself.
And IIRC if you stay in bounds you shouldn't get UB since char is alowed to alias anything
Yet if you intend to put the the pointer in C function that expect null-terminated string you will trigger UB since str is not null-terminated
If you just want to create char const* from string-literal - use byte-literal instead and ensure that there is \0 at the end.
Otherwise use CString
Krys
@Krysme
Sep 03 2018 15:38
OK, as long as the casting is alright
I know, on the C side I'm using a pointer with a length
Zakarum
@omni-viral
Sep 03 2018 15:39
Then it should be ok
Krys
@Krysme
Sep 03 2018 15:39
Thanks man