pinpoint

Crate for pinned references

3 releases

0.1.2 Sep 28, 2018
0.1.1 Sep 14, 2018
0.1.0 Sep 14, 2018

#2 in #containg

Download history 2/week @ 2023-11-02 2/week @ 2023-11-09 4/week @ 2023-11-16 6/week @ 2023-11-23 11/week @ 2023-11-30 3/week @ 2023-12-14 6/week @ 2023-12-21 3/week @ 2023-12-28 1/week @ 2024-01-11 3/week @ 2024-01-18 3/week @ 2024-01-25 3/week @ 2024-02-01 5/week @ 2024-02-08 41/week @ 2024-02-15

54 downloads per month

MIT license

19KB
395 lines

pinpoint

This crate provides the IntoPin trait. IntoPin is powerfull for creating coerced, pinned references.

Example

#![feature(pin)]

extern crate pinpoint;

use std::pin::Pin;
use pinpoint::IntoPin;

fn example<'a, P>(item: P)
where
    P: IntoPin<&'a mut [u8]>
{
    let mut pin: Pin<&mut [u8]> = item.into_pin();
    pin.reverse();
}

let mut v = vec![1, 2, 3, 4];
example(&mut v);
assert_eq!(v, [4, 3, 2, 1]);

let mut b: Box<[u8]> = Box::new([4, 3, 2, 1]);
example(&mut b);
assert_eq!(*b, [1, 2, 3, 4]);

lib.rs:

This crate provides the IntoPin trait. IntoPin can be used to wrap any type in a Pin, but is powerfull in creating coerced, pinned references.

Examples

#![feature(pin)]

extern crate pinpoint;
use std::pin::Pin;
use pinpoint::IntoPin;

let v = vec![1, 2, 3, 4, 5];

let pinned_slice: Pin<&[u32]> = (&v).into_pin();

An example using generics:

#![feature(pin)]

extern crate pinpoint;
use std::pin::Pin;
use pinpoint::IntoPin;

fn example<'a, P>(item: P)
where
    P: IntoPin<&'a mut [u8]>
{
    let mut pin = item.into_pin();

    pin.reverse();
}

let mut v = vec![1, 2, 3, 4];
example(&mut v);
assert_eq!(v, [4, 3, 2, 1]);

let mut b: Box<[u8]> = Box::new([4, 3, 2, 1]);
example(&mut b);
assert_eq!(*b, [1, 2, 3, 4]);

Features

In order to use the IntoPin trait, this crate should be used with the feature pinned of this crate turned on. In order to create a pinned slice containg Cell types from a Cell containing a slice, use the slice_of_cells feature of this crate.

No runtime deps

Features