feat(tvix/nix-compat): have StorePath accept bytes

The primary constructor for this is now from_bytes, from_string is
simply calling .as_bytes() on the string, passing it along.

The InvalidName error now contains a Vec<u8>, to encode the invalid name
(which might not be a string anymore).

from_absolute_path now accepts a &[u8] (even though we might want to
make this a OSString of some sort).

StorePath::validate_name has been degraded to a pub(crate) function.
It's still used in src/derivation, even though it probably shouldn't at
all - that cleanup is left for cl/8412 though.

Change-Id: I6b4e62a6fa5c4bec13b535279e73444f0b83ad35
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8973
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
This commit is contained in:
Florian Klink 2023-07-18 21:34:52 +03:00 committed by clbot
parent 5364fcb127
commit 42dc18353d
8 changed files with 84 additions and 68 deletions

View file

@ -1,5 +1,6 @@
#![allow(clippy::derive_partial_eq_without_eq)]
// https://github.com/hyperium/tonic/issues/1056
use std::str::FromStr;
use std::{collections::HashSet, iter::Peekable};
use thiserror::Error;
@ -97,7 +98,7 @@ fn parse_node_name_root<E>(
name: &str,
err: fn(String, store_path::Error) -> E,
) -> Result<StorePath, E> {
match StorePath::from_string(name) {
match StorePath::from_str(name) {
Ok(np) => Ok(np),
Err(e) => Err(err(name.to_string(), e)),
}