This commit is contained in:
Chris West (Faux) 2017-07-13 15:37:17 +01:00
parent 06a3c497e7
commit 6b164f172d
4 changed files with 16 additions and 13 deletions

View File

@ -16,16 +16,19 @@ fn main() {
if let Some(view) = found.next() {
println!("{}:{}:", view.name(), view.arch());
let installed_version = view.current_version().unwrap_or("(none)".to_string());
let installed_version = view.current_version().unwrap_or_else(|| "(none)".to_string());
println!(" Installed: {}", installed_version);
println!(" Candidate: {}", view.candidate_version().unwrap_or("(none)".to_string()));
println!(" Candidate: {}", view.candidate_version().unwrap_or_else(|| "(none)".to_string()));
println!(" Version table:");
for version in view.versions().map(simple::Version::from_iter) {
for version in view.versions().map(simple::Version::new) {
println!(" {} {} {}",
if version.version == installed_version { "***" } else { " " },
version.version,
version.priority,
);
println!(" TODO: urls");
}
} else {

View File

@ -1,7 +1,7 @@
/// In general:
/// * *mut c_void are to be released by the appropriate function
/// * *const c_chars are short-term borrows
/// * *mut c_chars are to be freed by libc::free.
/// * `*mut c_void` are to be released by the appropriate function
/// * `*const c_chars` are short-term borrows
/// * `*mut c_chars` are to be freed by `libc::free`.
use libc::c_void;
use libc::c_char;

View File

@ -73,7 +73,7 @@ impl<'c> Drop for PkgIterator<'c> {
/// Iterator-like interface.
/// Can't implement Iterator due to the mutation / lifetime constraints?
impl<'c> PkgIterator<'c> {
pub fn next<'i>(&'i mut self) -> Option<&'i Self> {
pub fn next(&mut self) -> Option<&Self> {
unsafe {
// we were at the end last time, leave us alone!
if self.is_empty() {
@ -155,7 +155,7 @@ impl<'c> PkgIterator<'c> {
.expect("package names are always low-ascii")
.to_string();
libc::free(ptr as *mut libc::c_void);
return result;
result
}
}
@ -199,7 +199,7 @@ impl<'c> Drop for VerIterator<'c> {
}
impl<'c> VerIterator<'c> {
pub fn next<'i>(&'i mut self) -> Option<&'i Self> {
pub fn next(&mut self) -> Option<&Self> {
unsafe {
// we were at the end last time, leave us alone!
if self.is_empty() {

View File

@ -2,12 +2,12 @@ use sane;
#[derive(Clone, Debug)]
pub struct BinaryPackage {
name: String,
arch: String,
pub name: String,
pub arch: String,
}
impl BinaryPackage {
pub fn from_iter(iter: &sane::PkgIterator) -> Self {
pub fn new(iter: &sane::PkgIterator) -> Self {
BinaryPackage {
name: iter.name(),
arch: iter.arch(),
@ -27,7 +27,7 @@ pub struct Version {
impl Version {
pub fn from_iter(iter: &sane::VerIterator) -> Self {
pub fn new(iter: &sane::VerIterator) -> Self {
Version {
version: iter.version(),
arch: iter.arch(),