1
Fork 0
mirror of https://github.com/RGBCube/dix synced 2025-07-28 04:07:46 +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::{
path::{
Path,
PathBuf,
},
path::PathBuf,
sync,
};
use anyhow::{
Context as _,
Error,
Result,
anyhow,
bail,
};
use derive_more::Deref;
use ref_cast::RefCast;
pub mod error;
pub mod print;
// pub mod diff;
// pub mod print;
pub mod store;
mod version;
use ref_cast::RefCast as _;
pub use version::Version;
#[derive(Deref, Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct DerivationId(i64);
#[derive(Deref, Debug, Clone, PartialEq, Eq)]
pub struct StorePathBuf(PathBuf);
pub struct StorePath(PathBuf);
#[derive(RefCast, Deref, Debug, PartialEq, Eq)]
#[repr(transparent)]
pub struct StorePath(Path);
impl TryFrom<PathBuf> for StorePath {
type Error = Error;
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 {
/// Parses a Nix store path to extract the packages name and possibly its

View file

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