A Rust API Inspired by Python, Powered by Serde
11–20 of 27 posts
Re: A Rust API Inspired by Python, Powered by Serde
#12Re: A Rust API Inspired by Python, Powered by Serde
#13The 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.
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
#14Re: A Rust API Inspired by Python, Powered by Serde
#15Pardon 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…
Re: A Rust API Inspired by Python, Powered by Serde
#16This 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…
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
#17It might feel more natural, and less magical if this used a turbofish instead
let res = query::();
Very neatRe: A Rust API Inspired by Python, Powered by Serde
#18Pardon 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
#19Pardon 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…
Re: A Rust API Inspired by Python, Powered by Serde
#20Pardon 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?