From ccfd46cd219058fe738798fa2a5c906257c57ff3 Mon Sep 17 00:00:00 2001 From: _cry64 Date: Sat, 28 Mar 2026 00:35:11 +1000 Subject: [PATCH] too drunk rn idk --- nixide/src/expr/realised_string.rs | 47 +++++++++++------------------- nixide/src/util/lazy_array.rs | 2 +- 2 files changed, 18 insertions(+), 31 deletions(-) diff --git a/nixide/src/expr/realised_string.rs b/nixide/src/expr/realised_string.rs index a3dbc7c..99f9f42 100644 --- a/nixide/src/expr/realised_string.rs +++ b/nixide/src/expr/realised_string.rs @@ -1,6 +1,6 @@ +use std::cell::RefCell; use std::ffi::c_char; use std::ptr::NonNull; -use std::sync::Arc; use crate::errors::ErrorContext; use crate::expr::values::NixString; @@ -11,31 +11,30 @@ use crate::util::LazyArray; use crate::util::{panic_issue_call_failed, wrap}; use crate::{EvalState, NixideResult, StorePath}; -pub struct RealisedString { - inner: NonNull, +pub struct RealisedString<'a> { + inner: RefCell>, pub path: StorePath, - pub children: - LazyArray StorePath>, usize) -> StorePath>, + pub children: LazyArray StorePath>, } -impl AsInnerPtr for RealisedString { +impl<'a> AsInnerPtr for RealisedString<'a> { #[inline] unsafe fn as_ptr(&self) -> *mut sys::nix_realised_string { - self.inner.as_ptr() + self.inner.borrow().as_ptr() } #[inline] unsafe fn as_ref(&self) -> &sys::nix_realised_string { - unsafe { self.inner.as_ref() } + unsafe { self.inner.borrow().as_ref() } } #[inline] unsafe fn as_mut(&mut self) -> &mut sys::nix_realised_string { - unsafe { self.inner.as_mut() } + unsafe { self.inner.borrow_mut().as_mut() } } } -impl Drop for RealisedString { +impl<'a> Drop for RealisedString<'a> { fn drop(&mut self) { unsafe { sys::nix_realised_string_free(self.as_ptr()); @@ -43,7 +42,7 @@ impl Drop for RealisedString { } } -impl RealisedString { +impl<'a> RealisedString<'a> { /// Realise a string context. /// /// This will @@ -64,7 +63,7 @@ impl RealisedString { /// # Returns /// /// NULL if failed, or a new nix_realised_string, which must be freed with nix_realised_string_free - pub fn new(value: &NixString, state: &Arc) -> NixideResult { + pub fn new(value: &NixString, state: &'a EvalState) -> NixideResult> { let inner = wrap::nix_ptr_fn!(|ctx: &ErrorContext| unsafe { sys::nix_string_realise( ctx.as_ptr(), @@ -73,32 +72,20 @@ impl RealisedString { false, // don't copy more ) })?; - - fn delegate( - inner: &LazyArray StorePath>>, - index: usize, - ) -> StorePath { - // XXX: TODO - // inner[index] - StorePath::fake_path(unsafe { state.store_ref() }).unwrap() - } + let cell = RefCell::new(inner); let size = unsafe { sys::nix_realised_string_get_store_path_count(inner.as_ptr()) }; + let delegate = &|_| StorePath::fake_path(unsafe { state.store_ref() }).unwrap(); + Ok(Self { - inner, + inner: cell, path: Self::parse_path(inner.as_ptr(), state), - children: LazyArray:: StorePath>>::new( - size, - Box::new(delegate), - ), + children: LazyArray::new(size, &delegate), }) } - fn parse_path( - realised_string: *mut sys::nix_realised_string, - state: &Arc, - ) -> StorePath { + fn parse_path(realised_string: *mut sys::nix_realised_string, state: &EvalState) -> StorePath { let buffer_ptr = unsafe { sys::nix_realised_string_get_buffer_start(realised_string) }; let buffer_size = unsafe { sys::nix_realised_string_get_buffer_size(realised_string) }; diff --git a/nixide/src/util/lazy_array.rs b/nixide/src/util/lazy_array.rs index 6b4b1a5..74c277e 100644 --- a/nixide/src/util/lazy_array.rs +++ b/nixide/src/util/lazy_array.rs @@ -1,7 +1,7 @@ use std::cell::{Ref, RefCell}; #[derive(Debug)] -pub struct LazyArray +pub struct LazyArray T> where F: Fn(usize) -> T, {