« first day (1861 days earlier)      last day (1620 days later) » 

owl
7:27 AM
@PeterVaro Lovely article didn't know that you can use rust on the nrf52
 
 
3 hours later…
10:02 AM
@owl In case you're not familiar with this repo which lists all the supported boards, related crates and articles, and which is at the centre of the embedded Rust community: Awesome Embedded Rust
So far I mostly done embedded Rust on STM32 boards (discovery, bluepill) but I can honestly tell you, it is a rather enjoyable and nice experience, incomparable to C/C++/Arduino :)
 
10:52 AM
Can concur on that, but make sure that if you're working on this as a newbie to embedded, pick a board that has all the HAL done for you
 
On that note, I would recommend the STM32F3DISCOVERY as it is reasonably priced, has loads of built in sensors and LEDs and whatnot, but most importantly, The Embedded Rust Book introducing the main concepts of embedded development through this board.
(IMO for newcomers reading this book should be just as essential and mandatory as reading The Book for anyone who's about to learn Rust)
 
 
5 hours later…
4:15 PM
Lol, this C++ question currently featured. C++ is definitely not statically typed :P
 
4:35 PM
@Stargateur I was literally LOL in the office -- this is brilliant
 
@PeterVaro ^^
 
The making a sandwich exercise is a common (in my circles, at least) exercise for testing-related events, like code retreat
But I am indeed excited to try it with Vivian when she's older
 
patience patience :p
 
@PeterVaro I wonder about reddit.com/r/wokekids
 
@Shepmaster it's not that bad, c'mon
 
my experience with 6 years olds is non-existent, really
 
@Shepmaster the whole thread is
 
That's so hard to speak to a kid: for example, yesterday, I was listening to a piece of music and shouted to my wife "this interpretation is so shitty!". Then my 2yo: "what is an interpretation, Dad". I was like: "Huuuuuuh..."
That's exactly the "Never one to shrink from a pedagogical challenge" from the article :P
 
5:03 PM
I found kid very simple to understand, but very annoying :p
 
@Stargateur That's the opposite: they're asking very interesting stuff because their mind are far less "determined" than adult's.
 
@FrenchBoiethios I'm literally a kid like that myself, I just ask question, I think it's easy to me to understand kid because I think like them. Still I'm annoying, asking too many question, always talk...
 
5:48 PM
Who was talking about automatic Ok wrapping recently? @SébastienRenauld? @DenysSéguret?
 
@Shepmaster me
 
6:02 PM
@Shepmaster Am I getting this right: people who argue for or against Ok-wrapping thinking that it could/should work outside of the try block?
 
@PeterVaro I wouldn't say I'm fully caught up on the arguments.
I'm personally -1 on the concept
that is, I think you should have to say try { Ok(1) }
 
Yeah, I'm on the same page as you are
 
For consistency. I say this as someone who still is bitten by forgetting to put Ok in every required spot
 
that would certainly make things more consistent
 
also, if I read correctly while skimming, return inside of a try block exits the function? not excited about that either
I guess it's closer to a flow operator
 
6:06 PM
not sold at all on the entire thing, for similar reasons
there's way too many gotchas
 
the general idea of "I want to use ? more" is reasonable
I've hacked it the few times I've really needed it with an IIFE
 
7:02 PM
Hey all. I have a question, I have this code: play.rust-lang.org/…. I am curious, does the *num calls deref or deref_mut? Breakpoints do not work for Rust's source code in CLion. Meanwhile, I am wondering: how can Rust know I changed the inner value? *num returns a plain i32 and I am literally saying: 5 (original value in the mutex) = 1. I tried assigning *num to a mutable reference without luck
So I am curious what *num returns. I can assign to to a plain i32, but not a ref to it
I thought it would call deref_mut, since a new value is assigned, but the learning book says it calls deref: doc.rust-lang.org/book/…
 
@Shepmaster They just edited the question to be almost completely different :P
RIP your answer
I feel like OP wants a const fn. Their code compiles as const fn actually...
 
@LukasKalbertodt RIP their points
thoughts?
@J.Doe You have to undo multiple levels of syntax
 
@Shepmaster Sure, why not. Never seen that happen but yeah
Altho I'm not sure OP will ask again...
 
11
Q: Why is the return type of Deref::deref itself a reference?

corazzaI was reading the docs for Rust's Deref trait: pub trait Deref { type Target: ?Sized; fn deref(&self) -> &Self::Target; } The type signature for the deref function seems counter-intuitive to me; why is the return type a reference? If references implement this trait so they can be deref...

152
Q: What are Rust's exact auto-dereferencing rules?

kFYatekI'm learning/experimenting with Rust, and in all the elegance that I find in this language, there is one peculiarity that baffles me and seems totally out of place. Rust automatically dereferences pointers when making method calls. I made some tests to determine the exact behaviour: struct X { ...

And AddAssign takes a mutable reference, so it kind of "undoes" the explicit dereference
@J.Doe The book does not say it calls Deref either
 
7:20 PM
@Shepmaster That beast of a question
 
> The MutexGuard smart pointer implements Deref to point at our inner data
Which is true
It also implements DerefMut
 
I just wanted to give you that quote, hehe
I am a noob, and I know deref does do something with *. So when they show me an example with * and says it implements deref, I thought they are referring to eachother
Thanks for the questions, will read them now :)
 
@J.Doe Yes, it's tricky. Generally a "smart pointer" in Rust implements Drop and Deref
 
@J.Doe Have fun with "Rust's exact auto-dereferencing rules" :D Not sure if that is really helpful for a beginner
@Shepmaster FYI, gonna invite OP to chat
 
I'm guessing that's why the book calls out those two here.
@LukasKalbertodt sure. If they change their title, I'll delete my answer / move it to self Q&A
@J.Doe I do think it's worth looking for / filing an issue on the book (or submitting a PR to fix it!) to expand.
 
7:24 PM
Omg wow that second question is indeed a beast 0___0
 
@J.Doe And a recent answer really cleared things up stares at @LukasKalbertodt
 
@Shepmaster :P I can at least say: writing that answer cleared things up for me :P
 
The trick is that the actual method-finding reference / dereference algorithm is pretty simple
Just the number of * and & is overwhelming
 
I must say I don't have the knowledge atm in rust to understand all of it :(
 
@Shepmaster Yip, I agree. I think the Rust reference I quote described it fairly well.
 
7:27 PM
But in short, *num = 1 doesn't really say 5 = 1 right?
 
@J.Doe Don't worry ^_^ That's more than natural
 
(In the code example I provided)
 
@J.Doe don't feel you need to, either. Rust generally Does The Right Thing
 
Ok :) references and dereferences are all new concepts for me :)
 
@Shepmaster The Right Thing™
 
7:28 PM
For your case, the expanded code with no magic would be something like
AddAssign::add(&mut *x, 6)
The &mut coming from the algorithm
 
So from deref_mut?
 
@J.Doe You might also be interested in this Q&A: https://stackoverflow.com/questions/42311825/what-is-exactly-lvalue-context-in-rust

The concept of "rvalue" and "lvalue" expressions is new to many programmers. The difference between these kinds of expressions is what makes `*x = 6` work, but makes `5 = 6;` not compile.
@J.Doe Yes. The += expr desugars into what Shepmaster wrote. And then the *x in that larger expression desugars into *DerefMut::deref_mut(&mut x), so everything becomes AddAssign::add(&mut *DerefMut::deref_mut(&mut x), 6)
@Shepmaster Wait, you need rep to talk in chat?
Mh, 20 rep apparently.
 
@LukasKalbertodt Maybe not if you trigger the "you commented too much"?
 
@Shepmaster Already triggered. That could be a solution. But I just temporarily upvoted their question so now they have enough rep.
Wanted to do the dishes 30 minutes ago already. And once again, StackOverflow is preventing me from living my life :P
 
ok, i'm here
 
7:40 PM
@LukasKalbertodt yeah, but dishes
Does anyone want to do dishes
 
Hehe, thanks a lot (and Shepmaster) of helping me out :D
 
@NilsAndré Ah perfect
 
@LukasKalbertodt
 
@Shepmaster I don't :P
 
@J.Doe np, it's what we like to do
 
7:41 PM
@NilsAndré So ok, then tell us... what are you trying to do? Like originally? What was your usecase?
 
0
Q: Deserialize file using serde_json at compile time

Nils AndréAt the beginning of my program, I read data from a file: let file = std::fs::File::open("data/games.json").unwrap(); let data: Games = serde_json::from_reader(file).unwrap(); I would like to know how it would be possible to do this at compile time for the following reasons: Performance: no n...

I'm trying to do what the answer from that question proposed
The idea would be to de-serialize inside the proc macro, And then represent the object so that I can return it to main (or any function)
 
@NilsAndré Mhhhhhhhhhhh interesting. Ok I see.
So first of all, I'm gonna repeat what @SébastienRenauld already said: it's probably not worth it and a bad idea. With that disclaimer out of the way...
Ok I actually think that would make a great question. Could you create a new question on the main site? Just thinking about how best to ask this.
 
we can retitle the current one
I don't mind deleting my answer
 
yes, I have not found anywhere anything that explains how to return a token stream that represents a struct or any variable for that matter
 
@Shepmaster Or that, yes. You said you wanted to move your answer to a self Q&A right?
 
7:47 PM
My answer literally shows how to return a value of 5
 
@Shepmaster That's almost random! </meta>
 
@LukasKalbertodt delete, move, it's all good
 
@NilsAndré Would you mind if I edit your current question in a way that I think makes it more clear and better? You can then undo the changes you didn't like.
 
"5".parse().unwrap() is morally the same as "Struct(5)".parse().unwrap() is morally the same a "Another { foo: 5 }".parse().unwrap(), etc.
 
how would you like it to be changed?
 
7:49 PM
@NilsAndré I'll just edit, that's way easier than explaining. You can still unroll my changes.
 
ok fine :)
 
@NilsAndré Why would you follow that answer? It's not accepted...
 
Follow what answer?
The one about serde_json?
What does follow mean?
I didn't accept the answer because it didn't fully answer my question (the one about serde_json and deserialization at compile time).
 
"follow" as in "follow the instructions laid out in the answer"
 
@NilsAndré Ok done. Let me know what you think :) If you are ok with that, I would write an answer.
 
7:57 PM
Well because it gave a clue on how to do it
 
Or @Shepmaster do you wanna answer again?
 
@LukasKalbertodt The same answer applies.
s/5/Foo { whatever: 5 }/
 
@NilsAndré I also removed my comments about getting you into this chat. They are not useful anymore. Would be great if you could also remove your comments only related to the chat.
@Shepmaster :D k
 
It's just more complicated than the original formulation that used a 5
Unless the problem is "I don't know how to create the string 5 from a variable containing 5"
 
7:59 PM
@Shepmaster Well not quite. For a 5, the obvious solution is to use a literal. For an unknown, potentially complex type Foo, it's different
 
Has @NilsAndré approved these changes? Is Foo truly in a third crate? Is it unknown / private what Foo is defined as?
And Foo has no methods or traits?
 
It doesn't really matter I think
 
@LukasKalbertodt "This might involve heavy computations, file access, or other stuff only procedural macros can do," — I still point out build scripts.
 
@Shepmaster Oh right. True that.
 
@NilsAndré If there's no public constructors of Foo, then the answer is easy — it's impossible.
 
8:02 PM
why?
Can't it just be like you described it?
 
> The users of my proc macros
This is a third crate. It has no ability to create Foo instances.
Thus a macro cannot create an instance
 
why? I'm a rust noob. Do you need to have public fields?
 
@NilsAndré I will try to write an answer that explains all that confusion
 
Although I notice my brain becoming tired, so apologies in advance for potential lack of quality :P
 
8:07 PM
it's fine hahaha
 
@NilsAndré to be clear, you have read the book on procedural macros, yes?
 
there's a book on procedural macros?
Or do you mean the chapter from the book?
 
The book chapter I linked to
(There's also a book on declarative macros, but not super relevant here)
 
yes, i've read the chapter
The only examples I could find of procedural macros were procedural macros that generated other functions
 
@NilsAndré What do you believe a macro does?
 
8:17 PM
it "expands" at compile time into other code
but for a proc macro, you have code, that changes code (tokenstream) into other code (tokenstream)
 
yep
Which is the same between the kinds of macros
 
Ok, finished my answer. Not happy with it but hopefully better than nothing.
 
@LukasKalbertodt I think there's a "!" (to show it's a macro) missing in your answer
In the second block of code
 
@NilsAndré Thanks, fixed
@Shepmaster Sure doesn't like the "proc macro" abbreviation :P
Thanks tho. My answer showed that I am tired :P
And the dishes are still waiting. Joy!
 
Also what do you mean by "you can't return the value directly"?
 
8:29 PM
@LukasKalbertodt indeed
 
@NilsAndré Not to sound rude or to discourage you, but I think you are still missing a fundamental and complete understand of how procedural macros actually work. Maybe I'm wrong, but it sounds a bit like that. Think about how exactly you would imagine a procedural macro to return a "value". There is just no way that could ever work. Macros, by definition, do not return values.
And I'm actually sorry that my brain is not in the state anymore to properly explain this. You are probably best of reading external resources for now :/
 
Ok, yes. That is why in my original question, return was in brackets.
 
That's what I was attempting to suss out via my questions
 
I thought returning directly was referring to something else
 
And hopefully it's more obvious why I'm adamant that my answer was an answer.
 
8:35 PM
your answer was an answer to my bad question
yes
hahaha. I really didn't make myself clear about what I wanted
 
No, seriously, it's an answer to your current question
 
yes
> "5".parse().unwrap() is morally the same as "Struct(5)".parse().unwrap() is morally the same a "Another { foo: 5 }".parse().unwrap(), etc.
but I didn't see it that way
 
#[proc_macro]
pub fn a_proc_macro(_input: TokenStream) -> TokenStream {
    "Foo { data: vec![1, 2, 3] }".parse().unwrap()
}
How you create that string is up to you
 
9:05 PM
This code is in the book where it uses a mutable vector: play.rust-lang.org/…. Let's say I don't want to mutable vector (actually, I don't want to assign the vector to a variable at all). I tried searching for a native forEach method in iterator/Range, but it is available only as a crate I believe (github.com/rust-lang/rfcs/pull/582, last comment). Now I have a not-compiling immutable vec: (next msg)
play.rust-lang.org/…. But the type of handles is somehow Vec<()> or something, where I would expect it is JoinHandle.
 
but... snake_case, not camelCase
 
Omg
 
But a for loop is more idiomatic than this method
 
O wait I have to try something out
Ok, but do you think a mutable vec is more desired than a non-mutable one, even in the code example they provided?
I think it can be fairly easy rewritten to a non-mutable one
 
I try to minimize the amount of mutable variables, yes. That doesn't mean having them is bad.
This is a perfect example for map / collect
12
A: How to put a type annotation in an iterator's collect statement?

Vladimir MatveevIn fact your problem was slightly less noticeable. This does not compile (your initial piece of code): use std::fs::File; use std::io::{BufRead, BufReader}; fn load_file() -> Vec<String> { let file = BufReader::new(File::open("foo.txt").unwrap()); file.lines().map(|x| x.unwrap()).collec...

 
9:09 PM
Aa darn the semicolon!!
Thanks it now works :D
 
In general though, yeah, try to reduce pieces that are mutable, but don't overly stress about it
You can also minimize the scope that something is mutable
Via a function or rebinding the variable
let mut foo =  1;
foo += 1;
let foo = foo;
there's a good Q&A about that but I can't find it
 
O that's interesting
@Shepmaster what IDE do you use to develop rust in?
clion didn't autocomplete me when I typed 'for' (when I wanted the for_each method). It's a decent IDE but the Rust plugin needs some work though
 
9:37 PM
@J.Doe emacs + RLS
I don't have any real autocomplete setup
 
O wauw :) okay
 
9:49 PM
FWIW, I'm not sure how good the experience is in CLion, but I use base IDEA or Rider, with the rust plugin, and autocomplete works pretty well for the there
Unfortunately, it can be a little slow to resolve.
So if you need direct hand-holding (which I do, sometimes), you may have to wait for it to catch up to you.
Sadly, I think a lot of that is IDEA trying to keep in some RAM limit, so it's constantly loading and then purging autocomplete lists for different types.
If you're on windows, I found (oddly enough) Visual Studio's debugging experience to still be pretty superior. I haven't tried to get it set up again recently, but I found it less of a pain than VSCode or CLion, and better in terms of functionality.
 
 
1 hour later…
11:06 PM
What is wrong with people
@SébastienRenauld According to the benchmarks I have done, locks haven't a big impact on performance. However, using mulitple threads have a bigger impact and should be used only when there are a lot of elements in the iterators, or when we want to execute a heavy operation for each element. It has also to be noted that the lock will be done only once per iteration and per type, and my library will be done in a way that the user cannot borrow at the same time the same structure. — Nicolas Ferré 23 mins ago
three locks
 
@SĂ©bastienRenauld There's a huge life-lesson somewhere there -- one should/could only help on a fellow developer if they actually ask for it and they actually let it. Otherwise the attempt is more than likely a waste of attention and time.
;)
 
Yeah, I'll give that question a hard pass
I have a cube drone comic about this somewhere...
 
don't hesitate sharing it!
 
mhm-mhm
 

« first day (1861 days earlier)      last day (1620 days later) »