From 7d2be237297c16628cb3d58774e808cac9c92fc1 Mon Sep 17 00:00:00 2001 From: Dirk Van Haerenborgh Date: Thu, 1 Nov 2018 21:55:00 +0100 Subject: improve lifetime management with supercow --- src/utils.rs | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) (limited to 'src/utils.rs') diff --git a/src/utils.rs b/src/utils.rs index 5db8957..5cce04d 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,16 +1,5 @@ -use std::{ - ffi, - str, -}; use libc; - -pub trait FromPtr { - fn from_ptr(ptr: T) -> Self; -} - -// pub trait NewFromPtr { -// fn new(ptr: T, parent: Rc

) -> Self; -// } +use std::{ffi, str}; pub trait ToStr { fn to_str<'a>(&self) -> Result<&'a str, str::Utf8Error>; @@ -18,9 +7,7 @@ pub trait ToStr { impl ToStr for *const libc::c_char { fn to_str<'a>(&self) -> Result<&'a str, str::Utf8Error> { - str::from_utf8(unsafe { - ffi::CStr::from_ptr(*self) - }.to_bytes()) + str::from_utf8(unsafe { ffi::CStr::from_ptr(*self) }.to_bytes()) } } @@ -30,13 +17,13 @@ pub trait ToString { impl ToString for *const libc::c_char { fn to_string(&self) -> String { - unsafe { - ffi::CStr::from_ptr(*self).to_string_lossy().into_owned() - } + unsafe { ffi::CStr::from_ptr(*self).to_string_lossy().into_owned() } } } - -pub struct Owner; - - +/// A streaming iterator, as found in https://github.com/emk/rust-streaming +pub trait StreamingIterator<'a, T> { + /// Return either the next item in the sequence, or `None` if all items + /// have been consumed. + fn next(&'a mut self) -> Option; +} -- cgit v1.2.1