66// SPDX-License-Identifier: MIT OR Apache-2.0
77//
88
9- use std:: { alloc:: { Layout , handle_alloc_error} , ops:: { Deref , DerefMut } , pin:: Pin , ptr:: NonNull , slice, task:: { Context , Poll } } ;
9+ use std:: {
10+ alloc:: { Layout , handle_alloc_error} ,
11+ ops:: { Deref , DerefMut } ,
12+ pin:: Pin ,
13+ ptr:: NonNull ,
14+ slice,
15+ task:: { Context , Poll } ,
16+ } ;
1017
1118use pin_project:: pin_project;
1219
13- use crate :: { event:: { Event , EventFuture } , usm:: UsmAlloc } ;
20+ use crate :: {
21+ event:: { Event , EventFuture } ,
22+ usm:: UsmAlloc ,
23+ } ;
1424
1525/// The Buffer struct defines a shared array of one, two or three dimensions that can be used
1626/// by the SYCL kernel. Buffers are templated on the type of their data, and the number of
@@ -38,7 +48,7 @@ impl<T, A: UsmAlloc> Buffer<T, A> {
3848 let layout = Layout :: array :: < T > ( len) . unwrap ( ) ;
3949 let ptr = match allocator. allocate ( layout. clone ( ) ) {
4050 Ok ( ptr) => ptr,
41- _ => handle_alloc_error ( layout)
51+ _ => handle_alloc_error ( layout) ,
4252 } ;
4353
4454 Self {
@@ -61,38 +71,33 @@ impl<T, A: UsmAlloc> Buffer<T, A> {
6171impl < T , A : UsmAlloc > Deref for Buffer < T , A > {
6272 type Target = [ T ] ;
6373 fn deref ( & self ) -> & Self :: Target {
64- unsafe {
65- slice:: from_raw_parts ( self . data . as_ptr ( ) , self . len )
66- }
74+ unsafe { slice:: from_raw_parts ( self . data . as_ptr ( ) , self . len ) }
6775 }
6876}
6977
7078impl < T , A : UsmAlloc > DerefMut for Buffer < T , A > {
7179 fn deref_mut ( & mut self ) -> & mut Self :: Target {
72- unsafe {
73- slice:: from_raw_parts_mut ( self . data . as_ptr ( ) , self . len )
74- }
80+ unsafe { slice:: from_raw_parts_mut ( self . data . as_ptr ( ) , self . len ) }
7581 }
7682}
7783
7884impl < T , A : UsmAlloc > Drop for Buffer < T , A > {
7985 fn drop ( & mut self ) {
80- unsafe { self . allocator . deallocate ( self . data . cast ( ) , self . layout ) ; }
86+ unsafe {
87+ self . allocator . deallocate ( self . data . cast ( ) , self . layout ) ;
88+ }
8189 }
8290}
8391
8492/// A [`Buffer`] whose initialization has been enqueued. You need to wait/await it.
8593pub struct EnqueuedBuffer < T , A : UsmAlloc > {
8694 buffer : Buffer < T , A > ,
87- event : Event
95+ event : Event ,
8896}
8997
9098impl < T , A : UsmAlloc > EnqueuedBuffer < T , A > {
9199 pub ( crate ) fn new ( buffer : Buffer < T , A > , event : Event ) -> Self {
92- Self {
93- buffer,
94- event
95- }
100+ Self { buffer, event }
96101 }
97102}
98103
@@ -109,14 +114,16 @@ impl<T, A: UsmAlloc> EnqueuedBuffer<T, A> {
109114pub struct BufferFuture < T , A : UsmAlloc > {
110115 buffer : Option < Buffer < T , A > > ,
111116 #[ pin]
112- event_future : EventFuture
117+ event_future : EventFuture ,
113118}
114119
115120impl < T , A : UsmAlloc > Future for BufferFuture < T , A > {
116121 type Output = Buffer < T , A > ;
117122 fn poll ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
118123 let this = self . project ( ) ;
119- this. event_future . poll ( cx) . map ( |_| this. buffer . take ( ) . unwrap ( ) )
124+ this. event_future
125+ . poll ( cx)
126+ . map ( |_| this. buffer . take ( ) . unwrap ( ) )
120127 }
121128}
122129
@@ -127,7 +134,7 @@ impl<T, A: UsmAlloc> IntoFuture for EnqueuedBuffer<T, A> {
127134 fn into_future ( self ) -> Self :: IntoFuture {
128135 Self :: IntoFuture {
129136 buffer : Some ( self . buffer ) ,
130- event_future : self . event . into_future ( )
137+ event_future : self . event . into_future ( ) ,
131138 }
132139 }
133140}
0 commit comments