Live data from Hacker News

A Rust API Inspired by Python, Powered by Serde

ohadravid.github.io

11–20 of 27 posts

Re: A Rust API Inspired by Python, Powered by Serde

#12
The title is vague in my opinion. What kind of API? What problem does it hope to solve? The article uses querying system data as examples, but after skimming it, I’m not sure why I would care. My comment is also a criticism of the article, since I couldn’t skim in quickly to figure out if I should spend more time on it.

Re: A Rust API Inspired by Python, Powered by Serde

#13
post #12

The title is vague in my opinion. What kind of API? What problem does it hope to solve? The article uses querying system data as examples, but after skimming it, I’m not sure why I would care. My comment is also a criticism of the article, since I couldn’t skim in quickly to figure out if I should spend more time on it.

(Author here) Thanks! That's useful feedback.

I also agree - the final article isn't skim-friendly enough, which drives away some readers.

Re: A Rust API Inspired by Python, Powered by Serde

#15

Pardon me, but I prefer the original by 1 million miles. let res = raw_api::query("SELECT * FROM Win32_Fan"); for obj in res { if obj.get_attr("ActiveCooling") == Value::Bool(true) { if let Value::String(name) = obj.get_attr("Name") { if let Value::UI8(speed) = obj.get_attr("DesiredSpeed") { println!("Fan `{name}` is running at {speed} RPM"); } } } } If actually concerned about the need to know UI8, then create a typ…

I wrote typedload in python. Once they show you an API with hundreds of types you appreciate not having to do like that all the time.

Re: A Rust API Inspired by Python, Powered by Serde

#16
post #6

This kind of sells the reason not to wrap things behind an object interface, doesn't it? for fan in c.query("SELECT * FROM Win32_Fan"): if fan.wmi_property("ActiveCooling").value is True: print(f"Fan `{fan.wmi_property('Name').value}` is running at {fan.wmi_property('DesiredSpeed').value} RPM") vs "SELECT Name, DesiredSpeed from Win32_Fan where ActiveCooling" Obviously, this doesn't matter when you have 5 fans, but i…

> Obviously, this doesn't matter when you have 5 fans, but in general, you want to push your restrictions as deeply into the query as possible from an optimization standpoint.

Depends where the database lives. If it's an in-process SQLite DB instance, there's no difference & doing this in code is easier to understand than more complicated SQL queries (of course not necessarily in this case but in general). But in all other cases you are correct about efficiency in general (although again other effects can dominate & make it irrelevant).

Re: A Rust API Inspired by Python, Powered by Serde

#18
post #15

Pardon me, but I prefer the original by 1 million miles. let res = raw_api::query("SELECT * FROM Win32_Fan"); for obj in res { if obj.get_attr("ActiveCooling") == Value::Bool(true) { if let Value::String(name) = obj.get_attr("Name") { if let Value::UI8(speed) = obj.get_attr("DesiredSpeed") { println!("Fan `{name}` is running at {speed} RPM"); } } } } If actually concerned about the need to know UI8, then create a typ…

I wrote typedload in python. Once they show you an API with hundreds of types you appreciate not having to do like that all the time.

I don't see the issue with just using an equivalent to `impl Deserializer for ValueDeserializer` then.

Re: A Rust API Inspired by Python, Powered by Serde

#19

Pardon me, but I prefer the original by 1 million miles. let res = raw_api::query("SELECT * FROM Win32_Fan"); for obj in res { if obj.get_attr("ActiveCooling") == Value::Bool(true) { if let Value::String(name) = obj.get_attr("Name") { if let Value::UI8(speed) = obj.get_attr("DesiredSpeed") { println!("Fan `{name}` is running at {speed} RPM"); } } } } If actually concerned about the need to know UI8, then create a typ…

Why? It's much more verbose and error prone (e.g. "stringly typed"). Do you never deserialize JSON?

Re: A Rust API Inspired by Python, Powered by Serde

#20

Pardon me, but I prefer the original by 1 million miles. let res = raw_api::query("SELECT * FROM Win32_Fan"); for obj in res { if obj.get_attr("ActiveCooling") == Value::Bool(true) { if let Value::String(name) = obj.get_attr("Name") { if let Value::UI8(speed) = obj.get_attr("DesiredSpeed") { println!("Fan `{name}` is running at {speed} RPM"); } } } } If actually concerned about the need to know UI8, then create a typ…

Why? It's much more verbose and error prone (e.g. "stringly typed"). Do you never deserialize JSON?

What's the difference between mistyping in the string here and mistyping in the struct definition? And yes I have.
Post reply on HN