Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions nix-bindings-store/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,20 @@ impl Store {
r
}

#[doc(alias = "nix_store_get_version")]
pub fn get_version(&mut self) -> Result<String> {
let mut r = result_string_init!();
unsafe {
check_call!(raw::store_get_version(
&mut self.context,
self.inner.ptr(),
Some(callback_get_result_string),
callback_get_result_string_data(&mut r)
))
}?;
r
}

#[doc(alias = "nix_store_parse_path")]
pub fn parse_store_path(&mut self, path: &str) -> Result<StorePath> {
let path = CString::new(path)?;
Expand Down Expand Up @@ -521,6 +535,15 @@ mod tests {
}
}

#[test]
fn version() {
let mut store = crate::store::Store::open(Some("dummy://"), []).unwrap();
assert_eq!(store.get_version().unwrap(), String::new());

let mut store = crate::store::Store::open(None, []).unwrap();
assert_ne!(store.get_version().unwrap(), String::new());
}

#[test]
fn weak_ref() {
let mut store = Store::open(None, HashMap::new()).unwrap();
Expand Down
39 changes: 39 additions & 0 deletions nix-bindings-util/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use crate::raw_sys as raw;
use anyhow::Result;
use std::ffi::{c_char, CStr};

pub mod context;
pub mod settings;
#[macro_use]
Expand All @@ -6,3 +10,38 @@ pub mod nix_version;

// Re-export for use in macros
pub use nix_bindings_util_sys as raw_sys;

#[doc(alias = "nix_libutil_init")]
pub fn init() -> Result<()> {
let mut ctx = context::Context::new();
unsafe {
check_call!(raw::libutil_init(&mut ctx))?;
}
Ok(())
}

#[doc(alias = "nix_version_get")]
pub fn get_version() -> Result<&'static str> {
let c_str = unsafe {
let ptr = raw::version_get();
CStr::from_ptr(ptr as *const c_char)
};

Ok(c_str.to_str()?)
}

#[cfg(test)]
mod tests {
use super::*;
use crate::nix_version::parse_version;

#[test]
fn init() {
super::init().unwrap();
}

#[test]
fn version() {
assert!(parse_version(get_version().unwrap()) > (0, 0, 0));
}
}
7 changes: 1 addition & 6 deletions nix-bindings-util/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,11 @@ pub fn get(key: &str) -> Result<String> {

#[cfg(test)]
mod tests {
use crate::check_call;

use super::*;

#[ctor::ctor]
fn setup() {
let mut ctx = context::Context::new();
unsafe {
check_call!(nix_bindings_util_sys::libutil_init(&mut ctx)).unwrap();
}
crate::init().unwrap();
}

#[test]
Expand Down