Skip to content

Commit

Permalink
Switch to ergo-pin for pinning expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo157 committed Feb 5, 2019
1 parent 8ef433a commit 089fb6f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ authors = ["Wim Looman <wim@nemo157.com>"]
edition = "2018"

[dependencies]
pin-utils = "0.1.0-alpha.3"
pin-project = "0.1.8"
ergo-pin = { git = "https://github.com/Nemo157/ergo-pin-rs" }
6 changes: 3 additions & 3 deletions src/iter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use {
core::pin::Pin,
pin_utils::pin_mut,
ergo_pin::ergo_pin,
};

existential type PinIterator__Iter<I: PinIterator>: Iterator<Item = I::Item>;
Expand Down Expand Up @@ -46,9 +46,9 @@ where
I: PinIterator,
F: FnMut(I::Item) -> R,
{
#[ergo_pin]
gen_iter! {
pin_mut!(iter);
for item in iter.iter() {
for item in pin!(iter).iter() {
yield f(item);
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
existential_type,
generators,
generator_trait,
proc_macro_hygiene,
)]

#[doc(hidden)]
#[macro_use]
pub mod gen_iter;

#[doc(hidden)]
#[macro_use]
mod utils;

pub mod iter;
pub use self::iter::{FusedPinIterator, PinIterator};

Expand Down
11 changes: 6 additions & 5 deletions src/list.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use {
core::{pin::Pin, ptr},
pin_project::unsafe_project,
ergo_pin::ergo_pin,
};

use crate::{gen_iter, pin_let, PinIterator};
use crate::{gen_iter, PinIterator};

#[unsafe_project]
pub struct List<T> {
Expand Down Expand Up @@ -31,6 +32,7 @@ impl<T> List<T> {
*this.head = node.as_ptr();
}

#[ergo_pin]
pub fn remove(mut self: Pin<&mut Self>, mut to_remove: Pin<&mut Node<T>>) -> bool {
let this = self.as_mut().project();
if *this.head == to_remove.as_mut().as_ptr() {
Expand All @@ -39,8 +41,7 @@ impl<T> List<T> {
return true;
}

pin_let!(nodes = self.iter_nodes());
for node in nodes.as_mut().iter() {
for node in pin!(self.iter_nodes()).iter() {
if node.next == to_remove.as_mut().as_ptr() {
*node.project().next = *to_remove.as_mut().project().next;
to_remove.on_detached();
Expand All @@ -64,9 +65,9 @@ impl<T> List<T> {
}

pub fn iter<'a>(self: Pin<&'a mut Self>) -> impl PinIterator<Item = &'a mut T> + 'a {
#[ergo_pin]
gen_iter! {
pin_let!(nodes = self.iter_nodes());
for node in nodes.as_mut().iter() {
for node in pin!(self.iter_nodes()).iter() {
yield node.project().value;
}
}
Expand Down
9 changes: 0 additions & 9 deletions src/utils.rs

This file was deleted.

0 comments on commit 089fb6f

Please sign in to comment.