These are chat archives for rust-lang/rust

23rd
Jul 2018
Akos Vandra
@axos88
Jul 23 2018 04:59
cargo check --color=always --all --all-targets will spit out every error twice if i have multiple targets configured. is there a way around this?
Talden
@Talden
Jul 23 2018 07:14

I started playing with syn to walk the syntax of a rust file to extract structural information.

My goal is to identify the endpoints and structs of a rocket restful-api and generate TypeScript client for the API that a frontend can use in comparative type-safety. Generated from Reflection on a Spring/Java API this workflow makes the process of exposing new endpoints and API changes easy but it's proving a little more challenging to extract what I want from rust (my lack of rust experience no doubt).

Of course syn possibly isn't what I'm looking for, as it's a very literal tokenisation of a single Rust file rather than a tool for structural reflection of a project.

I'd appreciate any thoughts on how others would tackle this in rust.

Note: I'm also really missing my Java IDE completion support - the IntelliJ Rust plugin doesn't seem to help much at all with syn so I'm digging into the API docs for each and every method/struct available which is a productivity suck when you're unfamiliar with a crate. Is IntelliJ where it's at with IDE support for Rust at the moment? I tried VS Code months ago and just had many spurious RLS has failed errors - maybe that's improved now.

trsh
@trsh
Jul 23 2018 07:32
Is there a short way to check for multi vec value without stepping on index out of bounds?
now I have to x.get(0).unwrap or, then on that again and again
Talden
@Talden
Jul 23 2018 09:00
@trsh Can you reword that? Not sure what you're asking. It sounds like you just want to know if some Vec<> has at least one element before trying to fetch values from it - vec.is_empty() or vec.len() against some expected size perhaps.
trsh
@trsh
Jul 23 2018 09:10
@Talden xx[0][1][4][1]
I have to check like every dimension of the arr
To avoid out of bounds
That generates huge code
Denis Lisov
@tanriol
Jul 23 2018 09:40
Is it too big or too slow? What kind of problem are you solving so that this is significant?
Talden
@Talden
Jul 23 2018 10:00
I presume the concern is just the amount of code to check all each of the four dimensions against each of the supplied indices - however if the indices can be dynamically provided I don't see how you can avoid the checks.
Dmitriy
@dpogretskiy
Jul 23 2018 10:01
first.nth(x).and_then(|second| second.nth(y).and_then(|third| third.nth(z).and_then(|fourth| fourth.nth(zz)))))
something like this?
Justin Kilpatrick
@jkilpatr
Jul 23 2018 13:32
has anyone ever tried to bind a udp socket to a rust ipv6 multicast address? I need to bind to ff02:0:0:0:0:0:0:7 but no matter what address parsing succeeds but bind fails with "invalid argument"
Dmitriy
@dpogretskiy
Jul 23 2018 13:33
which library do you use?
tokio?
Justin Kilpatrick
@jkilpatr
Jul 23 2018 13:33
std
and tokio
same error
so I'll just ask about std
Dmitriy
@dpogretskiy
Jul 23 2018 13:38
nah, no ideas :)
how does the code look exactly?
Justin Kilpatrick
@jkilpatr
Jul 23 2018 13:43
let ipaddr: IpAddr = "ff02:0:0:0:0:0:0:7"
    .parse()
    .expect("Failed to parse multicast addr");
let link_local_multicast_socket =
    UdpSocket::bind((ipaddr, 5111)).expect("Failed to bind to peer discovery address!");
thread 'main' panicked at 'Failed to bind to peer discovery address!: Os { code: 22, kind: InvalidInput, message: "Invalid argument" }', libcore/result.rs:945:5 stack backtrace: 0: main at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49 1: main at libstd/sys_common/backtrace.rs:71 2: main at libstd/panicking.rs:227 at libstd/panicking.rs:475 3: main at libstd/panicking.rs:390 4: main at libstd/panicking.rs:325 5: main at libcore/panicking.rs:77 6: main at /checkout/src/libcore/macros.rs:26 7: _ftext at /checkout/src/libcore/result.rs:809 at rita/src/client.rs:195 8: _ftext at /checkout/src/libstd/rt.rs:74 9: main at libstd/rt.rs:59 at libstd/sys_common/backtrace.rs:136 10: main at libstd/rt.rs:59 at libstd/panicking.rs:310 11: main 12: main at libpanic_unwind/lib.rs:106 13: _ftext at /checkout/src/libstd/panicking.rs:289 14: main 15: <unknown>
Dmitriy
@dpogretskiy
Jul 23 2018 13:44
oh, okay
Justin Kilpatrick
@jkilpatr
Jul 23 2018 13:45
ah ha!
rust-lang/rust#15688
I think I need to construct the socket addr very carefully
Dmitriy
@dpogretskiy
Jul 23 2018 13:46
yeah, it's a bit messy in there :)