These are chat archives for rust-lang/rust

9th
Jan 2019
thojest
@thojest
Jan 09 01:14
hi guys
i want to deploy an AWS lambda function which is able to write into dynamoDB
what is the best way to instantiate the client
generally i want to instantiate on startup and then use it. But how should I do it
zodiake
@zodiake
Jan 09 01:28
@aohan237 yes,I did not notice that "String Literals Are Slices". This is very different from other language.Thanks
thojest
@thojest
Jan 09 03:21
decided to use lazy_static!
Jan Hlavatý
@hlavaatch
Jan 09 13:51
I have a Vec<u8> full of generated data i need to pass to two threads as read only &[u8], how would I do it? I'm having trouble with lifetimes...
Denis Lisov
@tanriol
Jan 09 13:52
Why are you sure that it will be freed only after the threads no longer can access it?
Jan Hlavatý
@hlavaatch
Jan 09 13:53
Yes I control the threads and wait for them to die
But am not able to tell Rust that
Could I somehow fake 'static thru unsafe code?
toxicafunk
@toxicafunk
Jan 09 13:54
can u show some code? what r u trying actually?
Zakarum
@omni-viral
Jan 09 13:54
Denis Lisov
@tanriol
Jan 09 13:54
You can, but this is not a good idea. How about sending copies of Arc<Vec<u8>> instead?
Jan Hlavatý
@hlavaatch
Jan 09 13:55
The code is a mess using tokio and futures ;)
toxicafunk
@toxicafunk
Jan 09 13:56
i agree Arc seems like a good fit here
Jan Hlavatý
@hlavaatch
Jan 09 13:56
tried that, but was not able to pass that to write_all()
Arc vec to threads is a giood start i think
I'm failing at using tokio_io::io::write_all, I guess I need to pass the slice along somehow
Tim Robinson
@1tgr
Jan 09 14:00
The bytes crate is good for this, it behaves like an Arc<Vec<u8>> but you can use it directly with write_all
Jan Hlavatý
@hlavaatch
Jan 09 14:00
Will take a look, thanks
Jan Hlavatý
@hlavaatch
Jan 09 14:36
Excellent advice @1tgr exactly what I needed, thanks again
verilog15
@verilog15
Jan 09 18:08
image.png
Hi guys, new to Rust. I go an assignment to fix the following code in minimal steps so it will print 1-9 numbers twice
How to do it?
Mark Renten
@rentenmark
Jan 09 18:11
hey guys I'm looking for a windows friendly mmap crate that abstracts over mmap in unixes and "file mapping" in windows
I found this old thread that talks about some problems that Piston had with it https://www.reddit.com/r/rust/comments/3t7m42/what_is_happening_piston/
liyuntao
@liyuntao
Jan 09 18:13
@verilog15 for i in &vec {}
Jan Hlavatý
@hlavaatch
Jan 09 18:13
two issues - vec needs to be mut and first for consumes values
so put &vec in the for
and let mut vec =
thojest
@thojest
Jan 09 18:16
hey guys i have a problem with rusoto_db on AWS
match db_client.query(query_input).sync() {
        Ok(query_output) => Ok(query_output
            .items
            .unwrap_or_else(|| vec![])
            .into_iter()
            .map(|item| from_hashmap(item).unwrap())
            .collect()),
        Err(e) => Err(From::from(e.description())),
    }
.collect()),
| ^^^^^^^ a collection of type rusoto_dynamodb::QueryOutput cannot be built from `std::iter::Iterator<Item=_>
can you please help me :) im new to rust
Denis Lisov
@tanriol
Jan 09 18:19
@thojest What are you doing with the result?
thojest
@thojest
Jan 09 18:23
@tanriol thx alot :D
the code annotation was so misleading...
reason was wrong return type in function
Farhan Ahmed
@IMacronaut_twitter
Jan 09 21:49
Hi. I am trying to implement the Add trait on a very simple struct. Is it possible for the trait method signature to take a read only (immutable borrow) for the rhs parameter?
mtak-
@mtak-
Jan 09 21:54
yes. it's possible
struct Foo(i8);
impl<'a> Add<&'a Foo> for Foo {
    type Output = Foo;
    fn add(self, rhs: &'a Foo) -> Foo {
        Foo(self.0 + rhs.0)
    }
}
Farhan Ahmed
@IMacronaut_twitter
Jan 09 21:57
@mtak- Cool. Thank you. 🙇‍♂️