refactor(nix-compat/store_path): consistently use SP as type param

We also use S in other places in the same file, but that's for the
string-like references.

SP is now consistently used as the type parameter for StorePath<_> (and
build_output_path) gets support for it).

By being a bit more careful in the order of assignments in nix-compat/
src/derivation, we can nudge the compiler to use the type we want.

Change-Id: Ia7c298e110dff98d3b113d2388674ce9e22b80e8
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12590
Reviewed-by: flokli <flokli@flokli.de>
Reviewed-by: Marijan Petričević <marijan.petricevic94@gmail.com>
Tested-by: BuildkiteCI
This commit is contained in:
Florian Klink 2024-10-11 00:45:34 +03:00 committed by flokli
parent e8040ec61f
commit 48fa320cf4
3 changed files with 13 additions and 10 deletions

View file

@ -134,11 +134,14 @@ pub fn build_nar_based_store_path<'a>(
///
/// Input-addresed store paths are always derivation outputs, the "input" in question is the
/// derivation and its closure.
pub fn build_output_path<'a>(
pub fn build_output_path<'a, SP>(
drv_sha256: &[u8; 32],
output_name: &str,
output_path_name: &'a str,
) -> Result<StorePathRef<'a>, Error> {
) -> Result<StorePath<SP>, Error>
where
SP: std::cmp::Eq + std::ops::Deref<Target = str> + std::convert::From<&'a str>,
{
build_store_path_from_fingerprint_parts(
&(String::from("output:") + output_name),
drv_sha256,
@ -156,13 +159,13 @@ pub fn build_output_path<'a>(
/// bytes.
/// Inside a StorePath, that digest is printed nixbase32-encoded
/// (32 characters).
fn build_store_path_from_fingerprint_parts<'a, S>(
fn build_store_path_from_fingerprint_parts<'a, SP>(
ty: &str,
inner_digest: &[u8; 32],
name: &'a str,
) -> Result<StorePath<S>, Error>
) -> Result<StorePath<SP>, Error>
where
S: std::cmp::Eq + std::ops::Deref<Target = str> + std::convert::From<&'a str>,
SP: std::cmp::Eq + std::ops::Deref<Target = str> + std::convert::From<&'a str>,
{
let fingerprint = format!(
"{ty}:sha256:{}:{STORE_DIR}:{name}",