refactor(nix-compat/nix_daemon): drop Sync requirement for StorePath

By manually writing out the async function, and moving the owned String
we can avoid for S to be Sync in the NixSerialize for StorePath<S> impl.

Co-Authored-By: edef@edef.eu
Change-Id: I8427b38d2bd61de2818088728cbad79cda69d17d
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12764
Reviewed-by: Vladimir Kryachko <v.kryachko@gmail.com>
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: edef <edef@edef.eu>
Tested-by: BuildkiteCI
This commit is contained in:
Florian Klink 2024-11-12 12:32:26 +01:00 committed by flokli
parent 0b8ec03797
commit b1764e1109

View file

@ -1,5 +1,3 @@
use nix_compat_derive::{NixDeserialize, NixSerialize};
use crate::{
narinfo::Signature,
nixhash::CAHash,
@ -9,6 +7,8 @@ use crate::{
ser::{NixSerialize, NixWrite},
},
};
use nix_compat_derive::{NixDeserialize, NixSerialize};
use std::future::Future;
/// Marker type that consumes/sends and ignores a u64.
#[derive(Clone, Debug, NixDeserialize, NixSerialize)]
@ -128,13 +128,14 @@ impl NixDeserialize for StorePath<String> {
// Custom implementation since Display does not use absolute paths.
impl<S> NixSerialize for StorePath<S>
where
S: AsRef<str> + Sync,
S: AsRef<str>,
{
async fn serialize<W>(&self, writer: &mut W) -> Result<(), W::Error>
fn serialize<W>(&self, writer: &mut W) -> impl Future<Output = Result<(), W::Error>> + Send
where
W: NixWrite,
{
writer.write_value(&self.to_absolute_path()).await
let sp = self.to_absolute_path();
async move { writer.write_value(&sp).await }
}
}