Rusty Russell on Nostr: Since I'm taking a few weeks vacation, I've decided to seriously try to learn rust. ...
Since I'm taking a few weeks vacation, I've decided to seriously try to learn rust. My method in this case is to ask ChatGPT to guide me (but not write for me!) a library ("crate") that I've always wanted to write and never got around to.
Of course, I get a lot of feedback on appropriate rust styling, but some of it veers into things I feel are deeper constraints. In this case, I had an open function, which took a struct containing some flags, such as "writeable", "create if didn't exist".
It didn't like the fact that I asserted if you set create and didn't set writeable. Here is my response:
---
Re: assert!(). I dislike APIs which allow misuse. Callers of a library should not rely on such checks in the library, in fact the concept of adding an InvalidOptions error type is offensive. A recoverable error is strictly a worse api than an unignorable error. But a compile time error is better.
We should use an enum READONLY, WRITE_MUST_EXIST, WRITE_MAY_CREATE.
---
Of course, it's a waste of time for me to lecture it on style, but I can't help myself!!
Published at
2025-12-15 05:19:47 UTCEvent JSON
{
"id": "34d3dca8a4641372be1b63188ba57b268140ff9af4ef2a50b856ba76bd9c1f27",
"pubkey": "f1725586a402c06aec818d1478a45aaa0dc16c7a9c4869d97c350336d16f8e43",
"created_at": 1765775987,
"kind": 1,
"tags": [
[
"alt",
"A short note: Since I'm taking a few weeks vacation, I've decide..."
]
],
"content": "Since I'm taking a few weeks vacation, I've decided to seriously try to learn rust. My method in this case is to ask ChatGPT to guide me (but not write for me!) a library (\"crate\") that I've always wanted to write and never got around to. \n\nOf course, I get a lot of feedback on appropriate rust styling, but some of it veers into things I feel are deeper constraints. In this case, I had an open function, which took a struct containing some flags, such as \"writeable\", \"create if didn't exist\".\n\nIt didn't like the fact that I asserted if you set create and didn't set writeable. Here is my response: \n\n---\n\nRe: assert!(). I dislike APIs which allow misuse. Callers of a library should not rely on such checks in the library, in fact the concept of adding an InvalidOptions error type is offensive. A recoverable error is strictly a worse api than an unignorable error. But a compile time error is better.\n\nWe should use an enum READONLY, WRITE_MUST_EXIST, WRITE_MAY_CREATE.\n\n---\n\nOf course, it's a waste of time for me to lecture it on style, but I can't help myself!! ",
"sig": "6a8f99d6f04f5088db80024483ec5046599309a7cb93846c369e48e795b93016094548bbe1f89091a1ce0bf52e9a73b6404b284a706374a31eeb2412459bd019"
}