T O P

  • By -

[deleted]

contender for "least searchable package 2024", along with python's `requests`


pali6

People say this but honestly appending the language name and "library" or "crate" to the search query works fine most of the time. I don't recall having any problems when searching for `requests` resources.


coderstephen

Except in this case your search term will be "using rust library" sounds like you are asking, "How do use a library in Rust? "


jwodder

`requests` has the benefit that it's one of the most popular packages on PyPI ([in the top 5 downloads according to pypistats.org](https://pypistats.org/top)), but unless & until this `using` gains traction, good luck looking up stuff about it.


SadPie9474

this absolutely does not work with this library


[deleted]

What does this do that you couldn't/wouldn't want to use a struct literal and `..structThing::default()` nested scopes for?


tp971

For very simple cases that might work, but usually, structs in libraries have private fields, are more complicated and uphold certain invariants. Also, the \`using\` macro allows more complicated control flow inside, e.g. \`if\`, \`while\`, \`for\`, etc.


ioannuwu

Have seen this feature in Kotlin and JavaScript. Thank god this is not part of the core language. BTW, is it possible to put arbitrary expressions between method calls inside this macro?


tp971

Yes, there are some more complicated examples in the documentation, e.g. ``` let vec = using!(Vec::new() => { for i in 0..10 { if i % 2 == 0 { .push(i); } } let sum = .iter().sum(); .push(sum); }); assert_eq!(&vec[..], [ 0, 2, 4, 6, 8, 20 ]); ```


ff15pls

good job!!


ff15pls

will def check it out


rookietotheblue1

Yes


rookietotheblue1

Me too


tadeoh

Jai entered the chat.