mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 22:45:27 +01:00
Breaking changes here. This improves the semantics of `ConfigOption` and `options::Value` drastically. We've been using `options::Value` for 2 purposes 1. To specify the type and default value of an option 2. Coummunicate how a user configured an option We fall here in the pit-fall of being poor at both purposes. I've edited the code to ensure - `options::Value` -> To read or specify the value of an option - `option::ValueType` -> To specify the type of an option **Configure an option** Let's create an string-typed option create an option named `"required-string-opt"` the developer has to use the following code. ```rust let option = ConfigOption::new("required-string", Value::OptString, "description"); ``` The semantics of `OptString` might falsely suggest that it is optional to specify the config. However, we use `OptString` to say we are not providing a default-value. After this commit we can use instead ```rust let option = ConfigOption::new_str_no_default("required-string", "description"); ``` For reading a configured value the `option::Value` is somewhat cumbersome. The old version of had 6 different types of value ```rust let value = plugin.option("required-string"); match value { String(s) => {}, // User has configured string value or default Integer(i) => {}, // User has configured int value or default Boolean(b) => {}, // User has configured bool value or default OptString => {}, // User has not configured value and no default OptInteger = {}, // User has not configured value and no default OptBOolean => {}, // User has not configured value and no default } ``` This has been changed to ```rust let value = plugin.option("required-string"); match value { Some(String(s)) => {}, Some(Integer(i)) => {}, Some(Boolean(b)) => {}, None => {}, } ``` |
||
---|---|---|
.. | ||
cln-plugin-reentrant.rs | ||
cln-plugin-startup.rs |