Accept ip_port and net_id as Option<String> or Option<&str> for sbot::init() #52
Loading…
Reference in New Issue
No description provided.
Delete Branch "string_str_ip_port"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fairly simple change that gives us more flexibility when calling
sbot::init()
by allowing theip_port
andnet_id
parameters to be passed asOption<String>
orOption<&str>
.This makes it possible to define
const
values for the parameters required bysbot::init()
, for example:Then any
sbot
initialisation can reuse those values:The downside is that
None
parameters need to be annotated when the function is called. For example:Notice the
None::<&str>
annotation.@notplants What do you think? I'm happy to make the required changes to
peach-web
andpeach-config
, along with the various documentation, but wanted to check-in with you because this represents a breaking change.This was prompted by my work on
lykin
, specifically wanting to be able to quickly define a custom port for go-sbot.Interesting, it seems like a natural thing to want to be able to define, but that None::<&str> syntax is pretty bizarre. But it seems like thats the way to do "optional" arguments in rust so looks good.
fwiw, the pattern I would probably use in the application code is to define a separate utility function with no arguments init_sbot(), which calls Sbot::init(KEYSTORE, IP_PORT, NET_ID) inside of it, rather than calling Sbot::init in multiple places passing the same constant arguments (and thus avoiding the code duplication of needing the same arguments to be passed)
Haha yeah the turbofish is definitely one of the weirder pieces of Rust syntax.
Perfect, thanks for the tip. I'll do that.
I'll get some other PR's ready before merging this.
Step 1:
From your project repository, check out a new branch and test the changes.Step 2:
Merge the changes and update on Gitea.