|
Look at the type signatures of the from_str and from_slice methods. Both can parse into anything that implements the Deserialize trait. If you then click on that and scroll down, you'll see that hashmap is one of those things. It might be that you need a type annotation like you already have.
|
# ¿ Sep 26, 2023 22:23 |
|
|
# ¿ May 16, 2024 02:51 |
|
Dijkstracula posted:Reading about the From and Into traits is where I would start. While these are good they don't specifically answer the question. Specifically this is the method signature: https://docs.rs/serde_json/latest/serde_json/fn.from_slice.html It returns a type parameter T, where T is a type that implements the trait Deserialize. If you then look at the docs of that trait it lists all the types that implement it, that you can parse into. Also if you used serde_derive on a struct/enum, those types would implement it too. You absolutely would benefit a lot from reading about traits in general, but the shortest version is that they're a collection of methods. If a type implements a trait, you can call one of those methods on that type. Deserialize is a pretty complicated trait, and not a good first one to investigate (From and Into are much better there). It is a bit magical to have a polymorphic return signature that's freeform (subject to the trait) like that and not too many things do it. The other big one you'll know is the collect method. gonadic io fucked around with this message at 23:02 on Sep 26, 2023 |
# ¿ Sep 26, 2023 22:59 |
|
It being nested is a bit annoying. I've made fake little structs likecode:
|
# ¿ Sep 29, 2023 18:41 |
|
Dijkstracula posted:Thanks! No, that you can't use TestSubClass or something like it until you already do the match into the IvySort::Class variant. I would define a get_class method on IvySort that returns an Option<Class> tbh, then in your test you call expect on that , and can then call matches!, that's how the syn library does it.
|
# ¿ Sep 30, 2023 06:12 |
|
One of the things people from dynamic types don't really appreciate about static types at first is how easy it is to do the kind of refactoring like later adding a field. There's not really a need to leave stuff like that lying around in case you need it when it's easy to just add it when you need it. I personally would comment it out and leave little note for when I came back to it.
|
# ¿ Nov 3, 2023 21:48 |
|
Also if you're using an ide, which you should be, removing the underscores is like 2 clicks. The two main ones are vscode with rust analyser plug-in, or jetbrains intellij with rust plugin.
|
# ¿ Nov 3, 2023 22:10 |
|
is locking stdout for a long time like that an issue? I don't really know what its implications are tbh. I personally would be tempted to populate a vec then write out in one go after
|
# ¿ Dec 12, 2023 00:05 |
|
sure yeah, thanks
|
# ¿ Dec 12, 2023 00:18 |
|
You definitely want to lock rather than call print in a loop because each print call locks and then unlocks stdout anyway. I meant writing to a vec and then calling write on the vec as you did inside your inner loop. But it's probably a pretty moot point if locking stdout for your program is not an issue
|
# ¿ Dec 12, 2023 00:35 |
|
being babysat by a compiler owns
|
# ¿ Dec 12, 2023 00:44 |
|
there's also a -Z for inexact matching
|
# ¿ Dec 13, 2023 19:52 |
|
|
# ¿ May 16, 2024 02:51 |
|
my aoc hot tip is the include_str macro (or include_bytes when you want to shave some microseconds). gently caress reading from files at runtime
|
# ¿ Dec 14, 2023 23:51 |