|
1 | | -/// Custom code to free a handle. |
| 1 | +/// Custom code to free a resource. |
2 | 2 | /// |
3 | | -/// This is similar to the [`Drop`] trait, and may be used to implement [`Drop`], but allows handles |
4 | | -/// to be dropped depending on context. |
| 3 | +/// This is similar to the [`Drop`] trait, and may be used to implement [`Drop`], but allows resources |
| 4 | +/// to be freed depending on context. |
5 | 5 | pub trait Free : Clone { |
6 | | - /// Calls the handle's free function. |
| 6 | + /// Calls the resource's free function. |
7 | 7 | /// |
8 | 8 | /// # Safety |
9 | | - /// The handle must be owned by the caller and safe to free. |
| 9 | + /// The resource must be owned by the caller and safe to free. |
10 | 10 | unsafe fn free(&mut self); |
11 | 11 | } |
12 | 12 |
|
13 | | -/// A wrapper to provide ownership for handles to automatically drop via the handle's [`Free`] trait. |
| 13 | +/// A wrapper to provide ownership for resources to automatically drop via the resource's [`Free`] trait. |
14 | 14 | #[repr(transparent)] |
15 | 15 | #[derive(PartialEq, Eq, Default, Debug)] |
16 | 16 | pub struct Owned<T: Free>(T); |
17 | 17 |
|
18 | 18 | impl<T: Free> Owned<T> { |
19 | | - /// Takes ownership of the handle. |
| 19 | + /// Takes ownership of the resource. |
20 | 20 | /// |
21 | 21 | /// # Safety |
22 | 22 | /// |
23 | | - /// The handle must be owned by the caller and safe to free. |
| 23 | + /// The resource must be owned by the caller and safe to free. |
24 | 24 | pub unsafe fn new(x: T) -> Self { |
25 | 25 | Self(x) |
26 | 26 | } |
27 | 27 |
|
28 | | - /// Consumes the `Owned<T>` and relinquishes ownership of the handle. |
29 | | - /// The caller is now responsible for freeing the returned handle. |
30 | | - #[must_use = "losing the handle will leak it"] |
| 28 | + /// Consumes the `Owned<T>` and relinquishes ownership of the resource. |
| 29 | + /// The caller is now responsible for freeing the returned resource. |
| 30 | + #[must_use = "losing the resource will leak it"] |
31 | 31 | pub fn into_raw(o: Self) -> T { |
32 | 32 | let o = core::mem::ManuallyDrop::new(o); |
33 | 33 | o.0.clone() |
|
0 commit comments