Skip to content

Follow latest pinning API #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 24, 2018
Merged
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
24 changes: 12 additions & 12 deletions src/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/// ```
/// # #![feature(pin, arbitrary_self_types)]
/// # use pin_utils::unsafe_pinned;
/// # use std::pin::PinMut;
/// # use std::pin::Pin;
/// # use std::marker::Unpin;
/// struct Foo<T> {
/// field: T,
Expand All @@ -18,8 +18,8 @@
/// impl<T> Foo<T> {
/// unsafe_pinned!(field: T);
///
/// fn baz(mut self: PinMut<Self>) {
/// let _: PinMut<T> = self.field(); // Pinned reference to the field
/// fn baz(mut self: Pin<&mut Self>) {
/// let _: Pin<&mut T> = self.field(); // Pinned reference to the field
/// }
/// }
///
Expand All @@ -32,11 +32,11 @@
macro_rules! unsafe_pinned {
($f:tt: $t:ty) => (
fn $f<'__a>(
self: &'__a mut $crate::core_reexport::pin::PinMut<Self>
) -> $crate::core_reexport::pin::PinMut<'__a, $t> {
self: &'__a mut $crate::core_reexport::pin::Pin<&mut Self>
) -> $crate::core_reexport::pin::Pin<&'__a mut $t> {
unsafe {
$crate::core_reexport::pin::PinMut::map_unchecked(
self.reborrow(), |x| &mut x.$f
$crate::core_reexport::pin::Pin::map_unchecked_mut(
self.as_mut(), |x| &mut x.$f
)
}
}
Expand All @@ -53,7 +53,7 @@ macro_rules! unsafe_pinned {
/// ```
/// # #![feature(pin, arbitrary_self_types)]
/// # use pin_utils::unsafe_unpinned;
/// # use std::pin::PinMut;
/// # use std::pin::Pin;
/// # struct Bar;
/// struct Foo {
/// field: Bar,
Expand All @@ -62,7 +62,7 @@ macro_rules! unsafe_pinned {
/// impl Foo {
/// unsafe_unpinned!(field: Bar);
///
/// fn baz(mut self: PinMut<Self>) {
/// fn baz(mut self: Pin<&mut Self>) {
/// let _: &mut Bar = self.field(); // Normal reference to the field
/// }
/// }
Expand All @@ -71,11 +71,11 @@ macro_rules! unsafe_pinned {
macro_rules! unsafe_unpinned {
($f:tt: $t:ty) => (
fn $f<'__a>(
self: &'__a mut $crate::core_reexport::pin::PinMut<Self>
self: &'__a mut $crate::core_reexport::pin::Pin<&mut Self>
) -> &'__a mut $t {
unsafe {
&mut $crate::core_reexport::pin::PinMut::get_mut_unchecked(
self.reborrow()
&mut $crate::core_reexport::pin::Pin::get_mut_unchecked(
self.as_mut()
).$f
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/stack_pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
/// ```
/// # #![feature(pin)]
/// # use pin_utils::pin_mut;
/// # use core::pin::PinMut;
/// # use core::pin::Pin;
/// # struct Foo {}
/// let foo = Foo { /* ... */ };
/// pin_mut!(foo);
/// let _: PinMut<Foo> = foo;
/// let _: Pin<&mut Foo> = foo;
/// ```
#[macro_export]
macro_rules! pin_mut {
Expand All @@ -18,7 +18,7 @@ macro_rules! pin_mut {
// ever again.
#[allow(unused_mut)]
let mut $x = unsafe {
$crate::core_reexport::pin::PinMut::new_unchecked(&mut $x)
$crate::core_reexport::pin::Pin::new_unchecked(&mut $x)
};
)* }
}
4 changes: 2 additions & 2 deletions tests/projection.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![feature(pin, arbitrary_self_types)]
use pin_utils::{unsafe_pinned, unsafe_unpinned, pin_mut};
use std::pin::PinMut;
use std::pin::Pin;
use std::marker::Unpin;

struct Foo<T1, T2> {
Expand All @@ -20,7 +20,7 @@ fn projection() {
let foo = Foo { field1: 1, field2: 2 };
pin_mut!(foo);

let x1: PinMut<i32> = foo.field1();
let x1: Pin<&mut i32> = foo.field1();
assert_eq!(*x1, 1);

let x2: &mut i32 = foo.field2();
Expand Down
4 changes: 2 additions & 2 deletions tests/stack_pin.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#![feature(pin)]
use pin_utils::pin_mut;
use core::pin::PinMut;
use core::pin::Pin;

#[test]
fn stack_pin() {
struct Foo {}
let foo = Foo {};
pin_mut!(foo);
let _: PinMut<Foo> = foo;
let _: Pin<&mut Foo> = foo;
}