These are chat archives for rust-lang/rust

18th
Dec 2018
aohan237
@aohan237
Dec 18 2018 08:51
hello how to find all matches' location using regex?
re.find only returns one match start() and end()
and re.capture only returns captured text,but there is no match location infomation
so how to get all captures' location such as start() and end()?
Michal 'vorner' Vaner
@vorner
Dec 18 2018 09:23
Isn't there some method called matches around?
aohan237
@aohan237
Dec 18 2018 09:26
sorry, found there is an find_iter
this may be solved...
Stefan Lendl
@stfl
Dec 18 2018 10:34

Hi. I have a question I can't figure out: I am using protobuf in rust. I have my Message (MyMsg) types autogenerated.
These impl protobuf::Message but only implement a subset of the trait methods. some methods, like write_to_bytes() are implemented in the trait itself. I cannot call these methods on MyMsg because the compiler tells me that the method does not exist. How can I call these trait functions? Or how is the syntax for that type inference?
I have done this with type inference on a method like:

pub fn send_msg<Msg: protobuf::Message>(&self, msg: Msg) {
info!("sending Msg {:?}", msg);
let msg_bytes = msg.write_to_bytes().unwrap();
self.socket.send(&msg_bytes, 0).unwrap()
}

In this case I can simply call write_to_bytes from msg because rust knows that it is a protobuf::Message.
Is it also possible to write this inline without declaring a function?
Ali Shirvani
@alishir
Dec 18 2018 11:32
Hi guys, how can I convert bytes::Bytes to str, I want to resolve expected str, found struct bytes::Bytes error
resolved by using str::from_utf8(..)
cynom
@cynom
Dec 18 2018 15:37
Iter and map to_string won’t work here?
Cayle Sharrock
@CjS77
Dec 18 2018 15:38

Hey guys, I have a question about sub-dependencies. Say my Cargo.toml looks like this

[dependencies]
libcrate = "0.1.0"

i.e. For security reasons, I've fixed the version my code uses to a specific version (I could even fix it to a given github commit; I think the same applies).

but now, if you go and look in libcrate's Cargo.toml, they have

[dependencies]
naughtylib = "^1.0"

Currently, naughtlylib is on v1.0.10, which is what my Cargo.lock says I've currently built against.

Now in the meantime, the naughtylib developer inserts some nasty code into his library and releases it as 1.0.11.

After this release, I do a cargo clean; cargo build on my source code. What version of naughtylib will be built? 1.0.11, right?

Ingvar Stepanyan
@RReverser
Dec 18 2018 15:38
no, entire lib, including naughtylib is stored in Cargo.lock
so you won't get new version until you update either naughtylib itself or libcrate
Cayle Sharrock
@CjS77
Dec 18 2018 15:40
cargo build will respect the current state of Cargo.lock?
Ingvar Stepanyan
@RReverser
Dec 18 2018 15:40
yes
Cayle Sharrock
@CjS77
Dec 18 2018 15:40
and cargo update? Will that write a new Cargo.lock
Ingvar Stepanyan
@RReverser
Dec 18 2018 15:41
yes
Cayle Sharrock
@CjS77
Dec 18 2018 15:42
Ok, so tl;dr, to fix all versions of code, incl sub-dependencies:
  • Check in Cargo.lock -- presumably you can hand-tweak this for sub-dependencies if desired
  • Be very careful with cargo update
Ingvar Stepanyan
@RReverser
Dec 18 2018 15:42

presumably you can hand-tweak this for sub-dependencies if desired

Better not, just use cargo update -p ...

Cayle Sharrock
@CjS77
Dec 18 2018 15:43
I see. Thanks for the quick reply @RReverser
Diggory Blake
@Diggsey
Dec 18 2018 16:52
is it possible to strip debug symbols for a subset of dependencies?