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

9:42 AM
-1
A: Rust: memody deallocation for Strng

Florian WeimerIn such simple cases, Rust will automatically free memory when it us no longer needed. If you want to assign a zero-length string to s, you can use the clear function: s.clear(); This preserves the current capacity (and allocation) of the string. The alternative you cited, s = String::new()...

seriously
the question don't make sense
make an answer
and upvote the question
 
 
2 hours later…
12:02 PM
WTF IS HAPPENING
 
it's April 1st in UTC+12 timezone.
 
 
2 hours later…
1:39 PM
> Just like the '90s, good things have to come to an end. If you want to switch to the current site, you'll find the option here.
Why would I want to do that?
 
I didn't ^^
but opt out is good
I wonder how many time they lose instead of upgrade chat feature...
 
1:56 PM
I want to give up trying to learn Rust and write Haskell instead
 
@trentcl I think I know why...
Never mind, that was something else chewing up my CPU
@littlepootis There's nothing wrong with learning Haskell!
Learning any new language will improve your skills
 
@littlepootis because you have time to code a kernel while you steal try to write the first line of your project in haskell ;)
 
@littlepootis Also, many people have reported success in trying Rust for a while, going away for a while, then coming back. Something clicks for them
 
user6564029
haskell is fun. rust is fun. pick your poison, or double the dose and do both)
 
user6564029
2:15 PM
also, haskell and rust have a lot in common, trying one is likely to be good for learning the other. both have the approach that the type system is there to help and prevent mistakes, and also some other features: ADTs, liberal use of higher-order functions, traits\classes, maybe more.
 
the main problem is that haskell is a language design by mathematician
whereas rust is design by programmer who listen mathematician
and god know how I hate mathematician code
 
user6564029
kinda funny that it was a math thing that prompted me to switch from haskell to rust for general coding. gaussian elimination proved to be a pain.
 
@Shepmaster I don't like this question, you duplicate answer for drop mechanic but I still think the question is unclear "and is it the best way to erase content of the string?" from a security point of view I will advice something else that just let rust do it
 
2:31 PM
@Stargateur I think I agree. It could be answered with "the best way to deallocate a String is to let it go out of scope" and it wouldn't necessarily be a dupe
 
> Do I need to deallocate memory manually in this case:
You don't think that's answered by the dupe?
I'm all ears about making the question better & unique
@Stargateur besides, it was your idea for the dupe ;-)
 
no that a lie from stack overflow !
I vote as unclear
 
I know
@Stargateur I wouldn't be surprised if "erase content of the string" is actually a poor English translation of "free the memory"
 
you probably right
 
But it's certainly possible to be either way
 
2:35 PM
@Shepmaster I think it is answered, but I interpreted the new question as being "how do I ensure this thing is deallocated" whereas the dupe target answers "does overwriting this thing deallocate"
Overwriting a string with a new string does deallocate, but you shouldn't usually do it just for that reason
 
@trentcl I'll admit to not seeing the nuanced difference in the two... care to try bending my brain one more time?
 
@Shepmaster I think the user has an XY problem where X is " I want this string to be deallocated when I'm done with it" and Y is "I'll replace it with a new empty String"
 
well don't forget this user also ask stackoverflow.com/q/55438489/7076153
 
@Stargateur Which might be related:
You can just call string.clear() to reuse the same string. In this kind of IO code, there is really very little impact to allocating a new String each time though. — Peter Hall 4 hours ago
 
To be sure, marking Y as a duplicate is a totally appropriate action, as would be closing it as unclear.
But I think that a question focused on X could be on topic as well and might gather some useful answers / be a good Q to link to
(going unresponsive now, back later today)
 
 
2 hours later…
4:58 PM
Now, seriously
I truly want some feedback here, because I don't understand
Please review how to create a Minimal, Complete, and Verifiable example and then edit your question to include it. We cannot tell what crates (and their versions), types, traits, fields, macros, etc. are present in the code. Try to reproduce your error on the Rust Playground or in a brand new Cargo project. There are Rust-specific MCVE tips you can use to reduce your original code for posting here. — Shepmaster 6 mins ago
I get so many responses that boil down to: "I can't do this in the playground"
How can I make it more clear that it doesn't have to be on the playground?
 
replace "Try" by "for exemple, you could " ?
 
user6564029
maybe putting "new Cargo project" first would help somewhat? doubt it, but still.
 
@Michail It's possible, but I do want people to use the playground when possible (easier for them and us)
 
Ok the OP definitely rush thing, we still don't have the good information
sorry, my bad. i didn't notice that was still there. i fixed it. that was left over from me trying to figure out how to make it a static lifetime in case rust was deleting the pointer while it was in the C-code. — toadzky 29 secs ago
WHAT
I don't understand at all
@Stargateur neither of those variables is causing a problem. that's in the C-code - which i don't have control of and works fine when using other plugin modules written in C. — toadzky 1 min ago
Stay calm
Rust: pub type switch_xml_t = switch_xml; C: typedef struct switch_xml *switch_xml_t;
unbelievable I'm right !
 
5:42 PM
@Stargateur I was pretty sure it was going to be that they did the equivalent of a = NULL; *a = NULL
 
5:55 PM
@Shepmaster yeah but the OP disagree a lot about give information needed to be sure
 
6:12 PM
 
@Shepmaster perfect
 
6:43 PM
0
Q: Rust: Is there a difference between position of a mutable tag?

Thomas BraunWhat is the difference between: fn my_fn(mut my_var_name: &Foo) and fn my_fn(my_var_name: &mut Foo) Is there a difference?

how to thing the duplicate if any
keyword would match anything xd
fount it
@Shepmaster I hate you
 
@Stargateur <3
It's almost the same name
I dunno how SO couldn't find it
 
Indeed
 
@Shepmaster in your edit of my post stackoverflow.com/posts/55389847/revisions, you changed the style of the method call chaining from multi-line to single line. I was under the impression that multi-line chaining is standard. Is there a reference your using for what is the standard format?
 
@timotree Any formatting changes I do are by pasting code here into the playground and running rustfmt. rustfmt has entire RFCs dedicated to what it does.
 
Thanks!
 
6:50 PM
@timotree specifically here, I think it uses single line until it hits the line length
 
7:13 PM
@Shepmaster Thanks for digging into it and finding the GH thread! I guess this stuff is supposed to work? It's just that no one ever tried it before maybe :P
 
@LukasKalbertodt I wonder why the other answerer deleted
 
@Shepmaster That I wondered as well!
" try and rewrite it" -> pfff :P Well, maybe after Tuesday
But yeah, I mean that shouldn't be hard, in theory, right? :/ mhhh now I'm inclined to try.
 
 
1 hour later…
8:23 PM
@LukasKalbertodt What's Tuesday?
 
@Shepmaster Meeting with my supervisor about my master thesis. Want to get stuff done till then. Really excited already to make the project public ^_^
 
@LukasKalbertodt all done after that?
 
By the way, something fairly interesting just happened. I think it's interesting after all:

Compiling my test suite (i.e. `cargo build --tests`) took forever (like 50 seconds fresh, 40s with only touching `lib.rs` -- while my main crate takes about 5 seconds fresh). I investigated a bit and noticed that it's due to my heavy use of macros. Like, unit tests are very repetitive right? I try to write as many helper macros as possible to hide that. But I really choked the compiler with that. Now I've rewritten many macros to call an internal function for the "actual" work. This improved things
Interestingly, it even improved things, when each macro invocation leads to a new instantiation of the function (as in: generic types of the function gets instantiated). That's interesting because Rust saves a bunch of time by checking the function body only once. Rust can do that thanks to trait bounds. C++ has to check a body for validity each time it's instantiated.

Well, I found that interesting and cool ^_^
@Shepmaster Nop. Still roughly 2 months time. Then done.
 
8:55 PM
@LukasKalbertodt This fits with my general opinion to write as much in the "normal" abstractions (types, functions, traits, etc.) and rely on macros for "pure syntax" repetition
 
9:37 PM
@Shepmaster Yep, I always thought that way about public APIs and stuff like that. But I guess I should try to use non-macro solutions for internal stuff as well.
That said, my test macros are not just functions... they do some crazy stuff sometimes. Just a quick example
 

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