1
Fork 0
mirror of https://github.com/RGBCube/dix synced 2025-07-28 12:17:45 +00:00

feat: delete &StorePath, make StorePathBuf owned and remove Buf suffix

This commit is contained in:
RGBCube 2025-05-08 22:40:25 +03:00 committed by bloxx12
parent 078bc91cf8
commit fc73fa9722
2 changed files with 23 additions and 15 deletions

View file

@ -1,37 +1,46 @@
use std::{ use std::{
path::{ path::PathBuf,
Path,
PathBuf,
},
sync, sync,
}; };
use anyhow::{ use anyhow::{
Context as _, Context as _,
Error,
Result, Result,
anyhow, anyhow,
bail, bail,
}; };
use derive_more::Deref; use derive_more::Deref;
use ref_cast::RefCast;
pub mod error; // pub mod diff;
pub mod print; // pub mod print;
pub mod store; pub mod store;
mod version; mod version;
use ref_cast::RefCast as _;
pub use version::Version; pub use version::Version;
#[derive(Deref, Debug, Clone, Copy, PartialEq, Eq, Hash)] #[derive(Deref, Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct DerivationId(i64); pub struct DerivationId(i64);
#[derive(Deref, Debug, Clone, PartialEq, Eq)] #[derive(Deref, Debug, Clone, PartialEq, Eq)]
pub struct StorePathBuf(PathBuf); pub struct StorePath(PathBuf);
#[derive(RefCast, Deref, Debug, PartialEq, Eq)] impl TryFrom<PathBuf> for StorePath {
#[repr(transparent)] type Error = Error;
pub struct StorePath(Path);
fn try_from(path: PathBuf) -> Result<Self> {
if !path.starts_with("/nix/store") {
bail!(
"path {path} must start with /nix/store",
path = path.display(),
);
}
Ok(StorePath(path))
}
}
impl StorePath { impl StorePath {
/// Parses a Nix store path to extract the packages name and possibly its /// Parses a Nix store path to extract the packages name and possibly its

View file

@ -13,7 +13,6 @@ use rustc_hash::{
use crate::{ use crate::{
DerivationId, DerivationId,
StorePath, StorePath,
StorePathBuf,
}; };
macro_rules! path_to_str { macro_rules! path_to_str {
@ -53,7 +52,7 @@ impl Connection {
pub fn query_depdendents( pub fn query_depdendents(
&mut self, &mut self,
path: &StorePath, path: &StorePath,
) -> Result<Vec<(DerivationId, StorePathBuf)>> { ) -> Result<Vec<(DerivationId, StorePath)>> {
const QUERY: &str = " const QUERY: &str = "
WITH RECURSIVE WITH RECURSIVE
graph(p) AS ( graph(p) AS (
@ -70,12 +69,12 @@ impl Connection {
path_to_str!(path); path_to_str!(path);
let packages: result::Result<Vec<(DerivationId, StorePathBuf)>, _> = self let packages: result::Result<Vec<(DerivationId, StorePath)>, _> = self
.prepare_cached(QUERY)? .prepare_cached(QUERY)?
.query_map([path], |row| { .query_map([path], |row| {
Ok(( Ok((
DerivationId(row.get(0)?), DerivationId(row.get(0)?),
StorePathBuf(row.get::<_, String>(1)?.into()), StorePath(row.get::<_, String>(1)?.into()),
)) ))
})? })?
.collect(); .collect();