use crate::internal::*;
pub struct Info<'a> {
pub ptr: *mut IrminInfo,
pub(crate) repo: UntypedRepo<'a>,
}
impl<'a> Info<'a> {
pub fn new<T: Contents>(
repo: &Repo<T>,
author: impl AsRef<str>,
message: impl AsRef<str>,
) -> Result<Info, Error> {
let message = cstring(message);
let author = cstring(author);
let ptr = unsafe {
irmin_info_new(
repo.ptr,
author.as_ptr() as *mut _,
message.as_ptr() as *mut _,
)
};
check!(repo.ptr, ptr);
Ok(Info {
ptr,
repo: UntypedRepo::new(repo),
})
}
pub fn date(&self) -> i64 {
unsafe { irmin_info_date(self.repo.ptr, self.ptr) }
}
pub fn author(&self) -> Result<IrminString, Error> {
let ptr = unsafe { irmin_info_author(self.repo.ptr, self.ptr) };
IrminString::wrap(ptr)
}
pub fn message(&self) -> Result<IrminString, Error> {
let ptr = unsafe { irmin_info_message(self.repo.ptr, self.ptr) };
IrminString::wrap(ptr)
}
}
impl<'a> Drop for Info<'a> {
fn drop(&mut self) {
unsafe { irmin_info_free(self.ptr) }
}
}