snix_glue/builtins/
utils.rs1use bstr::ByteSlice;
2use snix_eval::{
3 CatchableErrorKind, CoercionKind, ErrorKind, NixAttrs, NixString, Value,
4 generators::{self, GenCo},
5 try_cek,
6};
7
8pub(super) async fn strong_importing_coerce_to_string(
9 co: &GenCo,
10 val: Value,
11) -> Result<NixString, CatchableErrorKind> {
12 let val = generators::request_force(co, val).await;
13 generators::request_string_coerce(
14 co,
15 val,
16 CoercionKind {
17 strong: true,
18 import_paths: true,
19 },
20 )
21 .await
22}
23
24pub(super) async fn select_string(
25 co: &GenCo,
26 attrs: &NixAttrs,
27 key: &str,
28) -> Result<Result<Option<String>, CatchableErrorKind>, ErrorKind> {
29 if let Some(attr) = attrs.select(key) {
30 let str = try_cek!(strong_importing_coerce_to_string(co, attr.clone()).await);
31 return Ok(Ok(Some(str.to_str()?.to_owned())));
32 }
33
34 Ok(Ok(None))
35}