1 use core::ops::Range; 2 3 use crate::traits::Sealed; 4 5 #[cfg(__standback_since_1_36)] 6 pub(crate) mod future { 7 use core::future::Future; 8 use core::pin::Pin; 9 use core::task::{Context, Poll}; 10 11 pub struct Ready<T>(Option<T>); 12 13 impl<T> Unpin for Ready<T> {} 14 15 impl<T> Future for Ready<T> { 16 type Output = T; 17 18 #[inline] poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<T>19 fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<T> { 20 Poll::Ready(self.0.take().expect("Ready polled after completion")) 21 } 22 } 23 ready<T>(t: T) -> Ready<T>24 pub fn ready<T>(t: T) -> Ready<T> { 25 Ready(Some(t)) 26 } 27 28 #[derive(Debug)] 29 #[must_use = "futures do nothing unless you `.await` or poll them"] 30 pub struct Pending<T> { 31 _data: core::marker::PhantomData<T>, 32 } 33 pending<T>() -> Pending<T>34 pub fn pending<T>() -> Pending<T> { 35 Pending { 36 _data: core::marker::PhantomData, 37 } 38 } 39 40 impl<T> Future for Pending<T> { 41 type Output = T; 42 poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<T>43 fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<T> { 44 Poll::Pending 45 } 46 } 47 48 impl<T> Unpin for Pending<T> {} 49 50 impl<T> Clone for Pending<T> { clone(&self) -> Self51 fn clone(&self) -> Self { 52 pending() 53 } 54 } 55 } 56 57 pub trait Slice_v1_48<T>: Sealed<[T]> { as_ptr_range(&self) -> Range<*const T>58 fn as_ptr_range(&self) -> Range<*const T>; as_mut_ptr_range(&mut self) -> Range<*mut T>59 fn as_mut_ptr_range(&mut self) -> Range<*mut T>; 60 } 61 62 impl<T> Slice_v1_48<T> for [T] { 63 #[inline] as_ptr_range(&self) -> Range<*const T>64 fn as_ptr_range(&self) -> Range<*const T> { 65 let start = self.as_ptr(); 66 let end = unsafe { start.add(self.len()) }; 67 start..end 68 } 69 70 #[inline] as_mut_ptr_range(&mut self) -> Range<*mut T>71 fn as_mut_ptr_range(&mut self) -> Range<*mut T> { 72 let start = self.as_mut_ptr(); 73 let end = unsafe { start.add(self.len()) }; 74 start..end 75 } 76 } 77