@@ -10,14 +10,13 @@ use crate::{
1010 bindings, error:: code:: * , error:: from_kernel_result, str:: CString , to_result,
1111 types:: PointerWrapper , Result , ScopeGuard ,
1212} ;
13+ use macros:: vtable;
1314
1415use core:: { cell:: UnsafeCell , fmt, marker:: PhantomData , pin:: Pin } ;
1516
1617/// This trait is implemented in order to provide callbacks to `struct hwrng`.
18+ #[ vtable]
1719pub trait Operations {
18- /// The methods to use to populate [`struct hwrng`].
19- const TO_USE : ToUse ;
20-
2120 /// The pointer type that will be used to hold user-defined data type.
2221 type Data : PointerWrapper + Send + Sync = ( ) ;
2322
@@ -122,12 +121,12 @@ impl<T: Operations> Registration<T> {
122121 ) {
123122 hwrng. name = name. as_char_ptr ( ) ;
124123
125- hwrng. init = if T :: TO_USE . init {
124+ hwrng. init = if T :: HAS_INIT {
126125 Some ( Self :: init_callback)
127126 } else {
128127 None
129128 } ;
130- hwrng. cleanup = if T :: TO_USE . cleanup {
129+ hwrng. cleanup = if T :: HAS_CLEANUP {
131130 Some ( Self :: cleanup_callback)
132131 } else {
133132 None
@@ -190,38 +189,6 @@ impl<T: Operations> Default for Registration<T> {
190189 }
191190}
192191
193- /// Represents which callbacks of [`struct hwrng`] should be populated with pointers.
194- pub struct ToUse {
195- /// The `init` field of [`struct hwrng`].
196- pub init : bool ,
197-
198- /// The `cleanup` field of [`struct hwrng`].
199- pub cleanup : bool ,
200- }
201-
202- /// A constant version where all values are to set to `false`, that is, all supported fields will
203- /// be set to null pointers.
204- pub const USE_NONE : ToUse = ToUse {
205- init : false ,
206- cleanup : false ,
207- } ;
208-
209- /// Defines the [`Operations::TO_USE`] field based on a list of fields to be populated.
210- #[ macro_export]
211- macro_rules! declare_hwrng_operations {
212- ( ) => {
213- const TO_USE : $crate:: hwrng:: ToUse = $crate:: hwrng:: USE_NONE ;
214- } ;
215- ( $( $i: ident) ,+) => {
216- #[ allow( clippy:: needless_update) ]
217- const TO_USE : kernel:: hwrng:: ToUse =
218- $crate:: hwrng:: ToUse {
219- $( $i: true ) ,+ ,
220- ..$crate:: hwrng:: USE_NONE
221- } ;
222- } ;
223- }
224-
225192// SAFETY: `Registration` does not expose any of its state across threads.
226193unsafe impl < T : Operations > Sync for Registration < T > { }
227194
0 commit comments