infinity_pool/cast.rs
1/// Extends pooled item handles to support casting to a trait object.
2///
3/// This macro generates a trait and an accompanying implementations that adds method
4/// to cast a pooled value pooled value from an unknown concrete type to a trait object
5/// of a specific trait while preserving the semantics of the original handle, returning
6/// a handle that dereferences to the trait object instead of the original concrete type.
7///
8/// The generated cast method allows conversion from `Pooled<T>` to `Pooled<dyn Trait>`
9/// where `T` implements the trait in question (and equivalently for `LocalPooled<T>`,
10/// `RawPooled<T>` and `RawBlindPooled<T>`).
11///
12/// # Parameters
13///
14/// - `trait_name`: The trait to enable casting to (e.g., `Display`, `SendUnitFuture`).
15/// The method name is automatically derived by converting this to `snake_case`
16/// with a `cast_` prefix (e.g. `cast_display()`).
17/// - `trait_name<TypeParams>`: A generic trait with type parameters (e.g., `SomeFuture<T>`).
18/// Generates a generic method like `cast_some_future::<usize>()`.
19///
20/// The trait must have at least `pub(crate)` visibility because the generated code uses that
21/// visibility.
22///
23/// For complex trait bounds, define a trait alias first, to simplify the trait to a single name,
24/// then use this macro with the trait alias name. You may otherwise experience macro parsing
25/// issues.
26///
27/// # Examples
28///
29/// ## Basic usage with simple trait
30///
31/// ```
32/// use std::fmt::Display;
33///
34/// use infinity_pool::{BlindPool, BlindPooledMut, define_pooled_dyn_cast};
35///
36/// // Enable casting to Display trait objects
37/// define_pooled_dyn_cast!(Display);
38///
39/// // Function that accepts trait object handles directly
40/// fn process_displayable(handle: BlindPooledMut<dyn Display>) {
41/// println!("Processing: {}", &*handle);
42/// }
43///
44/// let mut pool = BlindPool::new();
45/// let string_handle = pool.insert("Hello, world!".to_string());
46/// let number_handle = pool.insert(42i32);
47///
48/// // Cast to trait objects and pass to function
49/// process_displayable(string_handle.cast_display());
50/// process_displayable(number_handle.cast_display());
51/// ```
52///
53/// ## Complex trait bounds using trait aliases
54///
55/// ```
56/// use std::future::Future;
57///
58/// use infinity_pool::{BlindPool, BlindPooledMut, define_pooled_dyn_cast};
59///
60/// // Define a trait alias for complex trait bounds
61/// trait MyUsizeFuture: Future<Output = Option<usize>> + Send {}
62///
63/// // Blanket implementation for any type that satisfies the bounds
64/// impl<T> MyUsizeFuture for T where T: Future<Output = Option<usize>> + Send {}
65///
66/// // Enable casting using the trait alias
67/// define_pooled_dyn_cast!(MyUsizeFuture);
68///
69/// // Function that accepts the complex trait object
70/// fn process_future(future: &mut BlindPooledMut<dyn MyUsizeFuture>) {
71/// // Can work with the future as a trait object
72/// println!("Got a future that returns Option<usize>");
73/// }
74///
75/// let mut pool = BlindPool::new();
76///
77/// let my_future = pool.insert(async { Some(1234_usize) });
78/// let mut my_future = my_future.cast_my_usize_future();
79///
80/// process_future(&mut my_future);
81/// ```
82#[macro_export]
83macro_rules! define_pooled_dyn_cast {
84 // Handle simple traits without generic parameters
85 ($trait_name:ident) => {
86 $crate::__private_paste! {
87 /// Extension trait for casting pooled values to trait objects.
88 ///
89 /// This trait is generated by the [`define_pooled_dyn_cast!`] macro and provides
90 /// a method to cast pooled values to the specified trait object type.
91 pub(crate) trait [<PooledCast $trait_name>]<T> {
92 /// Casts this pooled value to a trait object.
93 ///
94 /// This method converts a pooled value from an unknown concrete type to a
95 /// trait object while preserving the reference counting and pool management
96 /// semantics.
97 ///
98 /// The cast is performed through safe reference coercion - if the concrete
99 /// type does not implement the required trait, compilation will fail.
100 fn [<cast_ $trait_name:snake>](self) -> Self::Output;
101
102 /// The output type after casting.
103 type Output;
104 }
105
106 impl<T> [<PooledCast $trait_name>]<T> for $crate::Pooled<T>
107 where
108 T: $trait_name + 'static,
109 {
110 type Output = $crate::Pooled<dyn $trait_name>;
111
112 #[allow(trivial_casts, reason = "necessary for syntax reasons")]
113 fn [<cast_ $trait_name:snake>](self) -> Self::Output {
114 // SAFETY: We guarantee that the closure references the same object
115 // in both its input and output, satisfying the safety requirement.
116 unsafe {
117 self.__private_cast_dyn_with_fn(|x| x as &dyn $trait_name)
118 }
119 }
120 }
121
122 impl<T> [<PooledCast $trait_name>]<T> for $crate::LocalPooled<T>
123 where
124 T: $trait_name + 'static,
125 {
126 type Output = $crate::LocalPooled<dyn $trait_name>;
127
128 #[allow(trivial_casts, reason = "necessary for syntax reasons")]
129 fn [<cast_ $trait_name:snake>](self) -> Self::Output {
130 // SAFETY: We guarantee that the closure references the same object
131 // in both its input and output, satisfying the safety requirement.
132 unsafe {
133 self.__private_cast_dyn_with_fn(|x| x as &dyn $trait_name)
134 }
135 }
136 }
137
138 impl<T> [<PooledCast $trait_name>]<T> for $crate::PooledMut<T>
139 where
140 T: $trait_name + 'static,
141 {
142 type Output = $crate::PooledMut<dyn $trait_name>;
143
144 #[allow(trivial_casts, reason = "necessary for syntax reasons")]
145 fn [<cast_ $trait_name:snake>](self) -> Self::Output {
146 // SAFETY: We guarantee that the closure references the same object
147 // in both its input and output, satisfying the safety requirement.
148 unsafe {
149 self.__private_cast_dyn_with_fn(|x| x as &mut dyn $trait_name)
150 }
151 }
152 }
153
154 impl<T> [<PooledCast $trait_name>]<T> for $crate::LocalPooledMut<T>
155 where
156 T: $trait_name + 'static,
157 {
158 type Output = $crate::LocalPooledMut<dyn $trait_name>;
159
160 #[allow(trivial_casts, reason = "necessary for syntax reasons")]
161 fn [<cast_ $trait_name:snake>](self) -> Self::Output {
162 // SAFETY: We guarantee that the closure references the same object
163 // in both its input and output, satisfying the safety requirement.
164 unsafe {
165 self.__private_cast_dyn_with_fn(|x| x as &mut dyn $trait_name)
166 }
167 }
168 }
169
170 impl<T> [<PooledCast $trait_name>]<T> for $crate::BlindPooled<T>
171 where
172 T: $trait_name + 'static,
173 {
174 type Output = $crate::BlindPooled<dyn $trait_name>;
175
176 #[allow(trivial_casts, reason = "necessary for syntax reasons")]
177 fn [<cast_ $trait_name:snake>](self) -> Self::Output {
178 // SAFETY: We guarantee that the closure references the same object
179 // in both its input and output, satisfying the safety requirement.
180 unsafe {
181 self.__private_cast_dyn_with_fn(|x| x as &dyn $trait_name)
182 }
183 }
184 }
185
186 impl<T> [<PooledCast $trait_name>]<T> for $crate::LocalBlindPooled<T>
187 where
188 T: $trait_name + 'static,
189 {
190 type Output = $crate::LocalBlindPooled<dyn $trait_name>;
191
192 #[allow(trivial_casts, reason = "necessary for syntax reasons")]
193 fn [<cast_ $trait_name:snake>](self) -> Self::Output {
194 // SAFETY: We guarantee that the closure references the same object
195 // in both its input and output, satisfying the safety requirement.
196 unsafe {
197 self.__private_cast_dyn_with_fn(|x| x as &dyn $trait_name)
198 }
199 }
200 }
201
202 impl<T> [<PooledCast $trait_name>]<T> for $crate::BlindPooledMut<T>
203 where
204 T: $trait_name + 'static,
205 {
206 type Output = $crate::BlindPooledMut<dyn $trait_name>;
207
208 #[allow(trivial_casts, reason = "necessary for syntax reasons")]
209 fn [<cast_ $trait_name:snake>](self) -> Self::Output {
210 // SAFETY: We guarantee that the closure references the same object
211 // in both its input and output, satisfying the safety requirement.
212 unsafe {
213 self.__private_cast_dyn_with_fn(|x| x as &mut dyn $trait_name)
214 }
215 }
216 }
217
218 impl<T> [<PooledCast $trait_name>]<T> for $crate::LocalBlindPooledMut<T>
219 where
220 T: $trait_name + 'static,
221 {
222 type Output = $crate::LocalBlindPooledMut<dyn $trait_name>;
223
224 #[allow(trivial_casts, reason = "necessary for syntax reasons")]
225 fn [<cast_ $trait_name:snake>](self) -> Self::Output {
226 // SAFETY: We guarantee that the closure references the same object
227 // in both its input and output, satisfying the safety requirement.
228 unsafe {
229 self.__private_cast_dyn_with_fn(|x| x as &mut dyn $trait_name)
230 }
231 }
232 }
233
234 /// Extension trait for casting pooled values to trait objects.
235 ///
236 /// This trait is generated by the [`define_pooled_dyn_cast!`] macro and provides
237 /// a method to cast pooled values to the specified trait object type.
238 pub(crate) trait [<RawPooledCast $trait_name>]<T> {
239 /// Casts this pooled value to a trait object.
240 ///
241 /// This method converts a pooled value from an unknown concrete type to a
242 /// trait object while preserving the reference counting and pool management
243 /// semantics.
244 ///
245 /// The cast is performed through safe reference coercion - if the concrete
246 /// type does not implement the required trait, compilation will fail.
247 ///
248 /// # Safety
249 ///
250 /// The caller must guarantee that the pool that contains the target object
251 /// remains alive for the duration of this call.
252 unsafe fn [<cast_ $trait_name:snake>](self) -> Self::Output;
253
254 /// The output type after casting.
255 type Output;
256 }
257
258 impl<T> [<RawPooledCast $trait_name>]<T> for $crate::RawPooled<T>
259 where
260 T: $trait_name + 'static,
261 {
262 type Output = $crate::RawPooled<dyn $trait_name>;
263
264 #[allow(trivial_casts, reason = "necessary for syntax reasons")]
265 unsafe fn [<cast_ $trait_name:snake>](self) -> Self::Output {
266 // SAFETY: We guarantee that the closure references the same object
267 // in both its input and output, satisfying the safety requirement.
268 // The pool liveness requirement is forwarded to the caller.
269 unsafe {
270 self.__private_cast_dyn_with_fn(|x| x as &dyn $trait_name)
271 }
272 }
273 }
274
275 impl<T> [<RawPooledCast $trait_name>]<T> for $crate::RawPooledMut<T>
276 where
277 T: $trait_name + 'static,
278 {
279 type Output = $crate::RawPooledMut<dyn $trait_name>;
280
281 #[allow(trivial_casts, reason = "necessary for syntax reasons")]
282 unsafe fn [<cast_ $trait_name:snake>](self) -> Self::Output {
283 // SAFETY: We guarantee that the closure references the same object
284 // in both its input and output, satisfying the safety requirement.
285 // The pool liveness requirement is forwarded to the caller.
286 unsafe {
287 self.__private_cast_dyn_with_fn(|x| x as &mut dyn $trait_name)
288 }
289 }
290 }
291
292 impl<T> [<RawPooledCast $trait_name>]<T> for $crate::RawBlindPooled<T>
293 where
294 T: $trait_name + 'static,
295 {
296 type Output = $crate::RawBlindPooled<dyn $trait_name>;
297
298 #[allow(trivial_casts, reason = "necessary for syntax reasons")]
299 unsafe fn [<cast_ $trait_name:snake>](self) -> Self::Output {
300 // SAFETY: We guarantee that the closure references the same object
301 // in both its input and output, satisfying the safety requirement.
302 // The pool liveness requirement is forwarded to the caller.
303 unsafe {
304 self.__private_cast_dyn_with_fn(|x| x as &dyn $trait_name)
305 }
306 }
307 }
308
309 impl<T> [<RawPooledCast $trait_name>]<T> for $crate::RawBlindPooledMut<T>
310 where
311 T: $trait_name + 'static,
312 {
313 type Output = $crate::RawBlindPooledMut<dyn $trait_name>;
314
315 #[allow(trivial_casts, reason = "necessary for syntax reasons")]
316 unsafe fn [<cast_ $trait_name:snake>](self) -> Self::Output {
317 // SAFETY: We guarantee that the closure references the same object
318 // in both its input and output, satisfying the safety requirement.
319 // The pool liveness requirement is forwarded to the caller.
320 unsafe {
321 self.__private_cast_dyn_with_fn(|x| x as &mut dyn $trait_name)
322 }
323 }
324 }
325 }
326 };
327
328 // Handle generic traits with type parameters
329 ($trait_name:ident<$($type_param:ident),+ $(,)?>) => {
330 $crate::__private_paste! {
331 /// Extension trait for casting pooled values to generic trait objects.
332 ///
333 /// This trait is generated by the [`define_pooled_dyn_cast!`] macro and provides
334 /// a generic method to cast pooled values to the specified trait object type.
335 pub(crate) trait [<PooledCast $trait_name>]<__PooledT> {
336 /// Casts this pooled value to a generic trait object.
337 ///
338 /// This method converts a pooled value from an unknown concrete type to a
339 /// trait object while preserving the reference counting and pool management
340 /// semantics.
341 ///
342 /// The cast is performed through safe reference coercion - if the concrete
343 /// type does not implement the required trait, compilation will fail.
344 ///
345 /// # Type Parameters
346 ///
347 /// The type parameters must be specified at the call site to determine
348 /// the exact trait object type.
349 fn [<cast_ $trait_name:snake>]<$($type_param),+>(self) -> Self::Output<$($type_param),+>
350 where
351 __PooledT: $trait_name<$($type_param),+> + 'static;
352
353 /// The output type after casting.
354 type Output<$($type_param),+>;
355 }
356
357 impl<__PooledT> [<PooledCast $trait_name>]<__PooledT> for $crate::Pooled<__PooledT>
358 where
359 __PooledT: 'static,
360 {
361 type Output<$($type_param),+> = $crate::Pooled<dyn $trait_name<$($type_param),+>>;
362
363 #[allow(trivial_casts, reason = "necessary for syntax reasons")]
364 fn [<cast_ $trait_name:snake>]<$($type_param),+>(self) -> Self::Output<$($type_param),+>
365 where
366 __PooledT: $trait_name<$($type_param),+> + 'static,
367 {
368 // SAFETY: We guarantee that the closure references the same object
369 // in both its input and output, satisfying the safety requirement.
370 unsafe {
371 self.__private_cast_dyn_with_fn(|x| x as &dyn $trait_name<$($type_param),+>)
372 }
373 }
374 }
375
376 impl<__PooledT> [<PooledCast $trait_name>]<__PooledT> for $crate::LocalPooled<__PooledT>
377 where
378 __PooledT: 'static,
379 {
380 type Output<$($type_param),+> = $crate::LocalPooled<dyn $trait_name<$($type_param),+>>;
381
382 #[allow(trivial_casts, reason = "necessary for syntax reasons")]
383 fn [<cast_ $trait_name:snake>]<$($type_param),+>(self) -> Self::Output<$($type_param),+>
384 where
385 __PooledT: $trait_name<$($type_param),+> + 'static,
386 {
387 // SAFETY: We guarantee that the closure references the same object
388 // in both its input and output, satisfying the safety requirement.
389 unsafe {
390 self.__private_cast_dyn_with_fn(|x| x as &dyn $trait_name<$($type_param),+>)
391 }
392 }
393 }
394
395 impl<__PooledT> [<PooledCast $trait_name>]<__PooledT> for $crate::PooledMut<__PooledT>
396 where
397 __PooledT: 'static,
398 {
399 type Output<$($type_param),+> = $crate::PooledMut<dyn $trait_name<$($type_param),+>>;
400
401 #[allow(trivial_casts, reason = "necessary for syntax reasons")]
402 fn [<cast_ $trait_name:snake>]<$($type_param),+>(self) -> Self::Output<$($type_param),+>
403 where
404 __PooledT: $trait_name<$($type_param),+> + 'static,
405 {
406 // SAFETY: We guarantee that the closure references the same object
407 // in both its input and output, satisfying the safety requirement.
408 unsafe {
409 self.__private_cast_dyn_with_fn(|x| x as &mut dyn $trait_name<$($type_param),+>)
410 }
411 }
412 }
413
414 impl<__PooledT> [<PooledCast $trait_name>]<__PooledT> for $crate::LocalPooledMut<__PooledT>
415 where
416 __PooledT: 'static,
417 {
418 type Output<$($type_param),+> = $crate::LocalPooledMut<dyn $trait_name<$($type_param),+>>;
419
420 #[allow(trivial_casts, reason = "necessary for syntax reasons")]
421 fn [<cast_ $trait_name:snake>]<$($type_param),+>(self) -> Self::Output<$($type_param),+>
422 where
423 __PooledT: $trait_name<$($type_param),+> + 'static,
424 {
425 // SAFETY: We guarantee that the closure references the same object
426 // in both its input and output, satisfying the safety requirement.
427 unsafe {
428 self.__private_cast_dyn_with_fn(|x| x as &mut dyn $trait_name<$($type_param),+>)
429 }
430 }
431 }
432
433 impl<__PooledT> [<PooledCast $trait_name>]<__PooledT> for $crate::BlindPooled<__PooledT>
434 where
435 __PooledT: 'static,
436 {
437 type Output<$($type_param),+> = $crate::BlindPooled<dyn $trait_name<$($type_param),+>>;
438
439 #[allow(trivial_casts, reason = "necessary for syntax reasons")]
440 fn [<cast_ $trait_name:snake>]<$($type_param),+>(self) -> Self::Output<$($type_param),+>
441 where
442 __PooledT: $trait_name<$($type_param),+> + 'static,
443 {
444 // SAFETY: We guarantee that the closure references the same object
445 // in both its input and output, satisfying the safety requirement.
446 unsafe {
447 self.__private_cast_dyn_with_fn(|x| x as &dyn $trait_name<$($type_param),+>)
448 }
449 }
450 }
451
452 impl<__PooledT> [<PooledCast $trait_name>]<__PooledT> for $crate::LocalBlindPooled<__PooledT>
453 where
454 __PooledT: 'static,
455 {
456 type Output<$($type_param),+> = $crate::LocalBlindPooled<dyn $trait_name<$($type_param),+>>;
457
458 #[allow(trivial_casts, reason = "necessary for syntax reasons")]
459 fn [<cast_ $trait_name:snake>]<$($type_param),+>(self) -> Self::Output<$($type_param),+>
460 where
461 __PooledT: $trait_name<$($type_param),+> + 'static,
462 {
463 // SAFETY: We guarantee that the closure references the same object
464 // in both its input and output, satisfying the safety requirement.
465 unsafe {
466 self.__private_cast_dyn_with_fn(|x| x as &dyn $trait_name<$($type_param),+>)
467 }
468 }
469 }
470
471 impl<__PooledT> [<PooledCast $trait_name>]<__PooledT> for $crate::BlindPooledMut<__PooledT>
472 where
473 __PooledT: 'static,
474 {
475 type Output<$($type_param),+> = $crate::BlindPooledMut<dyn $trait_name<$($type_param),+>>;
476
477 #[allow(trivial_casts, reason = "necessary for syntax reasons")]
478 fn [<cast_ $trait_name:snake>]<$($type_param),+>(self) -> Self::Output<$($type_param),+>
479 where
480 __PooledT: $trait_name<$($type_param),+> + 'static,
481 {
482 // SAFETY: We guarantee that the closure references the same object
483 // in both its input and output, satisfying the safety requirement.
484 unsafe {
485 self.__private_cast_dyn_with_fn(|x| x as &mut dyn $trait_name<$($type_param),+>)
486 }
487 }
488 }
489
490 impl<__PooledT> [<PooledCast $trait_name>]<__PooledT> for $crate::LocalBlindPooledMut<__PooledT>
491 where
492 __PooledT: 'static,
493 {
494 type Output<$($type_param),+> = $crate::LocalBlindPooledMut<dyn $trait_name<$($type_param),+>>;
495
496 #[allow(trivial_casts, reason = "necessary for syntax reasons")]
497 fn [<cast_ $trait_name:snake>]<$($type_param),+>(self) -> Self::Output<$($type_param),+>
498 where
499 __PooledT: $trait_name<$($type_param),+> + 'static,
500 {
501 // SAFETY: We guarantee that the closure references the same object
502 // in both its input and output, satisfying the safety requirement.
503 unsafe {
504 self.__private_cast_dyn_with_fn(|x| x as &mut dyn $trait_name<$($type_param),+>)
505 }
506 }
507 }
508
509 /// Extension trait for casting pooled values to generic trait objects.
510 ///
511 /// This trait is generated by the [`define_pooled_dyn_cast!`] macro and provides
512 /// a generic method to cast pooled values to the specified trait object type.
513 pub(crate) trait [<RawPooledCast $trait_name>]<__PooledT> {
514 /// Casts this pooled value to a generic trait object.
515 ///
516 /// This method converts a pooled value from an unknown concrete type to a
517 /// trait object while preserving the reference counting and pool management
518 /// semantics.
519 ///
520 /// The cast is performed through safe reference coercion - if the concrete
521 /// type does not implement the required trait, compilation will fail.
522 ///
523 /// # Type Parameters
524 ///
525 /// The type parameters must be specified at the call site to determine
526 /// the exact trait object type.
527 ///
528 /// # Safety
529 ///
530 /// The caller must guarantee that the pool that contains the target object
531 /// remains alive for the duration of this call.
532 unsafe fn [<cast_ $trait_name:snake>]<$($type_param),+>(self) -> Self::Output<$($type_param),+>
533 where
534 __PooledT: $trait_name<$($type_param),+> + 'static;
535
536 /// The output type after casting.
537 type Output<$($type_param),+>;
538 }
539
540 impl<__PooledT> [<RawPooledCast $trait_name>]<__PooledT> for $crate::RawPooled<__PooledT>
541 where
542 __PooledT: 'static,
543 {
544 type Output<$($type_param),+> = $crate::RawPooled<dyn $trait_name<$($type_param),+>>;
545
546 #[allow(trivial_casts, reason = "necessary for syntax reasons")]
547 unsafe fn [<cast_ $trait_name:snake>]<$($type_param),+>(self) -> Self::Output<$($type_param),+>
548 where
549 __PooledT: $trait_name<$($type_param),+> + 'static,
550 {
551 // SAFETY: We guarantee that the closure references the same object
552 // in both its input and output, satisfying the safety requirement.
553 // The pool liveness requirement is forwarded to the caller.
554 unsafe {
555 self.__private_cast_dyn_with_fn(|x| x as &dyn $trait_name<$($type_param),+>)
556 }
557 }
558 }
559
560 impl<__PooledT> [<RawPooledCast $trait_name>]<__PooledT> for $crate::RawPooledMut<__PooledT>
561 where
562 __PooledT: 'static,
563 {
564 type Output<$($type_param),+> = $crate::RawPooledMut<dyn $trait_name<$($type_param),+>>;
565
566 #[allow(trivial_casts, reason = "necessary for syntax reasons")]
567 unsafe fn [<cast_ $trait_name:snake>]<$($type_param),+>(self) -> Self::Output<$($type_param),+>
568 where
569 __PooledT: $trait_name<$($type_param),+> + 'static,
570 {
571 // SAFETY: We guarantee that the closure references the same object
572 // in both its input and output, satisfying the safety requirement.
573 // The pool liveness requirement is forwarded to the caller.
574 unsafe {
575 self.__private_cast_dyn_with_fn(|x| x as &mut dyn $trait_name<$($type_param),+>)
576 }
577 }
578 }
579
580 impl<__PooledT> [<RawPooledCast $trait_name>]<__PooledT> for $crate::RawBlindPooled<__PooledT>
581 where
582 __PooledT: 'static,
583 {
584 type Output<$($type_param),+> = $crate::RawBlindPooled<dyn $trait_name<$($type_param),+>>;
585
586 #[allow(trivial_casts, reason = "necessary for syntax reasons")]
587 unsafe fn [<cast_ $trait_name:snake>]<$($type_param),+>(self) -> Self::Output<$($type_param),+>
588 where
589 __PooledT: $trait_name<$($type_param),+> + 'static,
590 {
591 // SAFETY: We guarantee that the closure references the same object
592 // in both its input and output, satisfying the safety requirement.
593 // The pool liveness requirement is forwarded to the caller.
594 unsafe {
595 self.__private_cast_dyn_with_fn(|x| x as &dyn $trait_name<$($type_param),+>)
596 }
597 }
598 }
599
600 impl<__PooledT> [<RawPooledCast $trait_name>]<__PooledT> for $crate::RawBlindPooledMut<__PooledT>
601 where
602 __PooledT: 'static,
603 {
604 type Output<$($type_param),+> = $crate::RawBlindPooledMut<dyn $trait_name<$($type_param),+>>;
605
606 #[allow(trivial_casts, reason = "necessary for syntax reasons")]
607 unsafe fn [<cast_ $trait_name:snake>]<$($type_param),+>(self) -> Self::Output<$($type_param),+>
608 where
609 __PooledT: $trait_name<$($type_param),+> + 'static,
610 {
611 // SAFETY: We guarantee that the closure references the same object
612 // in both its input and output, satisfying the safety requirement.
613 // The pool liveness requirement is forwarded to the caller.
614 unsafe {
615 self.__private_cast_dyn_with_fn(|x| x as &mut dyn $trait_name<$($type_param),+>)
616 }
617 }
618 }
619 }
620 };
621}