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