« first day (1814 days earlier)      last day (1895 days later) » 

06:45
Shouldn't this work ? play.rust-lang.org/…
> This is a generic function, so by definition the size of T can vary and not a compile-time constant
Isn't it a compile time constant if we don't use dyn ? I probably need more coffee
if you apply help suggestion (fn i_from_slice<T: Trait>(slice: &[u8]) -> Option<T>)
it gives another help suggesiont ->
fn i_from_slice<T: Trait +Trait>(slice: &[u8]) -> Option<T>
it looks interesting, even you can't implement trait without that constant, so it should know that T has a S
So probably it only gets Associated Type from a Generic Type, you can define associated type with a same name with the constant one
07:02
I'm a little lost here. I don't know exactly what's available in associated types & consts. And I'm precoffee
 
1 hour later…
08:13
@DenysSéguret I would easily say it is a bug. It accepts T::S in the match's arm, but not in the array's initialisation-length position. And even if you tell the compiler explicitly where to look (i.e. <T as Trait>::S) it still has no clue what's going on. Moreover you can get into an infinite-loop of following the suggestion of the compiler: T: Trait + Trait + Trait + Trait + Trait + ...
That's my take on it too
well, unless there's a clear-cut compile-time definition order -- which I'm unaware of -- this has to be a bug/implementation constraint
08:39
-1
Q: Rust - AWS - rusoto_polly

user12152615I have been a real "user" of this site for many years. I have just spent the last few days (seriously) trying to rewrite a little library I wrote in a few hours in C# in Rust using the rusoto library. Nowhere on the great God google could I find a code example that would get me to first base. ...

Need moderator help for this one :)
@Websterix that's a simple , I don't think mod intervention is required
I do not know how to cv yet. I just put a flag for mod intervention, What should I do?
Retracted my flag
08:55
I voted
@Websterix You need 3k to do that!
@PeterVaro I need 500 to go :)
@DenysSéguret thanks
 
1 hour later…
10:22
FYI @Shepmaster a slightly bit different take on the matter: medium.com/p/a3907b25b4c7
11:02
So many libraries decide to implement their own thread pool
I'm making a PoC project for balena, a very simple discord bot that plays MIDI when it receives certain messages
MIDI lib has its own thread pool and blocks the main thread
`serenity` (the discord lib) has its own thread pool and blocks the main thread
@SébastienRenauld Isn't software engineering fun? ;)
btw, I'm not against implementing things on your own (and I'm not talking about academic purposes) and I'm not a hardcore 'reuse as much as you can from others' -- but I do believe that packages should be more modular and smaller in complexity
i.e., each big feature of a lib should be a separate lib
and so users can opt-out/in if they like
11:41
I'm just going to run a thread pool to rule them all
There was a remote job listing with the tag. I mentioned my interest. Now I'm answered this:
> Just so we do not start with wrong expectations. The rust part has not seen (needed) a whole lot of further development. Maybe I should in fact not have listed rust in the ad at all...
well...
@DenysSéguret :epic_face_palm:
which one was this?
11:56
That sure sounds like a job you want to work on
where somebody goes "I'm not sure I should have listed your specialization at all"
shows clear identification of needs ;-)
@DenysSéguret That's what I see everywhere -- even look at the "production users" on rust-lang -- most of the companies used it for a smaller (usually internal) project and then basically that's it. Once that's finished they don't touch it just build on top of it in other languages..
that's the only reason I wish Rust's adoption would be more widespread
Hello
My company uses it full-scale
shame we ship 200 devices a month to a single customer
I didn't say every single company in the world now, did I?
I said, "most of the companies"
@PeterVaro He didn't say you were wrong, either ;)
@DenysSéguret fair ;)
@SébastienRenauld why is it a shame?
because it is "just" a single customer?
12:11
Because it's largely irrelevant work
On an unrelated note, last night I discovered that Iterator is actually implemented for &mut Iterator -- which makes it utterly flexible, as in, you can reuse your iterator at a later point in time even if by default it would've been "consumed/moved" to other fancy iterator wrappers. This is not something you usually need or want but last night this was exactly what I was looking for!
something like: play.rust-lang.org/…
There are so many really, really cool details like this in the standard library and somehow they are not easy to discover from the documentation
(ofc you could say by_ref is there, but that's not necessarily the name I would look..)
It works
I can play MIDI notes from discord
time to quickly transcribe mission impossible, tie it to my discord infra failure notifications and get fucking blasted by the pi that I've put beside my bed
what could possibly go wrong
And then you'll just have to plan a failure of your infra to have an alarm clock ?
This man gets me.
OH man, I'm so tempted to make this 16-channel and then properly do it
but it's only for a PoC for balena
 
1 hour later…
13:34
0
Q: How to bind reference lifetime to a function local scope

TheofI want to write a function A which takes as parameter a function B which takes as parameter a type which is parameterized by a reference type which lifetime is at least the lifetime of the local variables in A’s body. Consider the following example: struct Foo {} fn consume(mut v: Vec<&Foo>) {...

This guy is having the usual misunderstanding of lifetimes in vectors
because you push something with a lesser lifetime and then remove it from the vector mid way, does not mean rust magically knows that this lifetime will be different just for that element
 
2 hours later…
15:24
4 posts, all misusing unsafe
ooooffffff
@Shepmaster Not mine
I wonder why people keep using unsafe when it is not needed -_-
Well I have a bad unsafe usage, but that's a C/P of the OP's solution to show that I get the same result without unsafe (that's the point).
@FrenchBoiethios Yes yours ;-) IMO, it's worth pointing out memory safety problems in the original. Yours could contain a line like // This unsafe` usage is invalid, but copied from the original post`
Quick question about rust by example: doc.rust-lang.org/stable/rust-by-example/scope/lifetime/… It says "T: 'a: All references in T must outlive lifetime 'a." E.g., struct Ref<'a, T: 'a>(&'a T);. My question is, is "T:'a" redundant? Seems struct Ref<'a, T>(&'a T); works too.
@Shepmaster Fair enough
@HelinWang AFAIK, it is optional since the compiler can infer it
15:40
23
Q: Why is the bound `T: 'a` required in order to store a reference `&'a T`?

Lukas KalbertodtGiven this code: struct RefWrapper<'a, T> { r: &'a T, } ... the compiler complains: error: the parameter type T may not live long enough consider adding an explicit lifetime bound T: 'a so that the reference type &'a T does not outlive the data it points at. I've seen this error...

Thanks folks!
Make sure to read both answers
Shepmaster, thanks for the Rust in motion course :) It was great. Any plan for more course like it?
sure
@HelinWang We don't have any concrete plans, no. There was originally going to be a companion course, but that author had other commitments. If you are indeed interested, the best course might be to ask Manning for a follow up.
I've thought a little about how I could do (monetized?) videos based on Stack Overflow Q&A
Thanks for the info. You mean based on SO questions? That's an interesting idea. It would be helpful for me to see some video that walk through Rust std packages' code and documentation. I have spent plenty of time of Rust, but still not confident reading the std package implementations myself. But I think it would be very helpful for beginners.
15:48
@Shepmaster Huh, the old Rust was so noisy :(
My idea would basically be to show how I solve some specific Q&A. Generally, people only see my "perfect" final answer, but there's usually a lot of iteration and research. It would be my hope that watching that process would give people more confidence ("oh, Shepmaster gets a bunch of compiler errors too!") and teach some techniques.
Btw, you use emacs, right? How was the experience for you developing Rust with emacs? I personally found it's hard to navigate through the (std library) code base because impl is scattered all over the places. Not sure if it's an issue / an emacs issue. But if you know some emacs package that helps this situation that would be very helpful.
My brain really works well with the Q&A style format. An open-ended "walk through a library" is tough for me because there's not much of a concrete goal.
Now I can't navigate Rust source code with emacs, to understand something, I have to use the web base documentation.
Yeah, I use emacs + RLS integration.
TBH, I'm not sure I've ever tried to jump into the standard library. It does appear to work.
15:52
I see, I would be interested in the Q&A style. Interested in learning how experienced Rust programmers approach a question.
I also don't use method-name autocompletion, which it looks like the LSP mode supports
I use emacs + RLS too, I can jump to std lib, but I am really not accustomed to the code arrangement, it's really hard to find out all the methods / trait implementations of a type. Maybe because Rust support generics and allow impl to be located in different places? I come from Go background, reading std lib was really easy.
So how do you learn a new type / function in std lib? By reading the doc? The Rust doc is indeed very good.
yeah, the multiple impl blocks is great from a functionality point of view, but I can see how it's hard from a "what can this do" aspect
Generally, I'll collapse all the methods to see just the names and arguments
I feel like that gives a good sense of the capabilities of a type
@FrenchBoiethios ooooh, nice slice pattern matching
How to "collapse all the methods" in emacs?
@Shepmaster I've just discovered that it is a thing
I just don't like the [a, b, c, d] repetition, but I cannot find how to bind it with @
array @ &[a, b, c, d] => Some(i32::from_ne_bytes(array)) does not work
15:59
There's also
    use std::convert::TryInto;
    bytes.try_into().map(i32::from_ne_bytes).ok()
@Shepmaster So much better! I didn't know that there was an implementation from slices to arrays
I'll steal that :P
31
Q: How to get a slice as an array in Rust?

Jeroen BollenI have an array of an unknown size, and I would like to get a slice of that array and convert it to a statically sized array: fn pop(barry: &[u8]) -> [u8; 3] { barry[0..3] // mismatched types: expected `[u8, ..3]` but found `&[u8]` } How would I do this?

I don't understand why clone isn't needed tho
Oh because it is copy, nevermind
I really think that the num traits should be in std. That's tiring to write all those traits by hand only to have genericity over int types
16:52
@FrenchBoiethios The glib response is to write up an RFC to add them
I have a feeling that the problem is that there's no One True Way to organize the traits
People complain about the distinction of PartialOrd / Ord, so I can't imagine what they'd think of the traits that go into Integer.
17:15
This question is a duplicate of How to access current cargo profile (build, test, bench, doc, …) from the build script (build.rs), which doesn't have an answer (because there is no way). — Shepmaster 2 hours ago
The dupe now has an answer, so if anyone cares up updoot it we can close as duuup
 
3 hours later…
20:07
Someone mentioned to me "the new .Net Core 3/C# 8 pivot" — anyone have any background for me?
semi-related; @FrenchBoiethios you were doing some work on futures in a FFI world, right? Is that public anywhere?

« first day (1814 days earlier)      last day (1895 days later) »