this post was submitted on 07 Aug 2024
1 points (100.0% liked)

Rust Programming

8011 readers
1 users here now

founded 5 years ago
MODERATORS
 

#rust folks it's supposed to throw this error without lazy_static crate , but it doesn't?
https://git.sr.ht/~carnotweat/morning-rust/tree/main/item/sum.rs#L14
cc @rust @learningrustandlemmy

top 4 comments
sorted by: hot top controversial new old
[–] [email protected] 2 points 1 month ago (1 children)

If you're using an LLM to "learn", stop. Otherwise, I don't understand what lazy_static has to do with anything.

It's hard to tell what you're asking. But maybe you're confused because println! (it's a macro btw) expands to code that involves format_args! which is a compiler built-in that doesn't take ownership of the token expressions that get passed to it. Notice how the bottom of the format_args! page has this to say:

Lifetime limitation

Except when no formatting arguments are used, the produced fmt::Arguments value borrows temporary values, which means it can only be used within the same expression and cannot be stored for later use. This is a known limitation, see #92698.

So, it's kind of a feature and a limitation at the same time.

[–] [email protected] 0 points 1 month ago (1 children)

@BB_C disclaimer - no llm , I am following a book

[–] [email protected] 1 points 1 month ago

Good.

Can you formulate your question better, with a minimal example and properly formatted code?

[–] [email protected] 1 points 1 month ago* (last edited 1 month ago)

@rust @learningrustandlemmy
I might have missed some subtle syntactical difference here, I guess
aas in Vec<...> is a type definition, and Vec::<...> is referring to the struct itself, but with a type parameter given.
context - https://www.reddit.com/r/learnrust/comments/exmqyc/what_are_the_rules_for_turbofish/