lib.strings: isMoreCoercibleString -> isConvertibleWithToString

Yes, this function name is inconveniently long, but it is important
for the name to explicitly reference the function and not be mistaken
for the implicit string conversions, which only happen for a smaller
set of values.
This commit is contained in:
Robert Hensing 2022-12-31 00:42:22 +01:00
parent 872a24ebbc
commit 834f0d660a
2 changed files with 7 additions and 6 deletions

View File

@ -798,19 +798,20 @@ rec {
in lib.warnIf (!precise) "Imprecise conversion from float to string ${result}"
result;
/* Soft-deprecated name for isMoreCoercibleToString */
/* Soft-deprecated function. While the original implementation is available as
isConvertibleWithToString, consider using isStringLike instead, if suitable. */
isCoercibleToString = lib.warnIf (lib.isInOldestRelease 2305)
"lib.strings.isCoercibleToString is deprecated in favor of either isStringLike or isMoreCoercibleString. Only use the latter if it needs to return true for null, numbers, booleans and list of similarly coercibles."
isMoreCoercibleToString;
"lib.strings.isCoercibleToString is deprecated in favor of either isStringLike or isConvertibleWithToString. Only use the latter if it needs to return true for null, numbers, booleans and list of similarly coercibles."
isConvertibleWithToString;
/* Check whether a list or other value can be passed to toString.
Many types of value are coercible to string this way, including int, float,
null, bool, list of similarly coercible values.
*/
isMoreCoercibleToString = x:
isConvertibleWithToString = x:
elem (typeOf x) [ "path" "string" "null" "int" "float" "bool" ] ||
(isList x && lib.all isMoreCoercibleToString x) ||
(isList x && lib.all isConvertibleWithToString x) ||
x ? outPath ||
x ? __toString;

View File

@ -42,7 +42,7 @@ let
else if isDerivation v then toString v
else if builtins.isPath v then toString v
else if isString v then v
else if strings.isMoreCoercibleToString v then toString v
else if strings.isConvertibleWithToString v then toString v
else abort "The nix conf value: ${toPretty {} v} can not be encoded";
mkKeyValue = k: v: "${escape [ "=" ] k} = ${mkValueString v}";