Coverage Report

Created: 2025-11-16 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/mesa3d_util-0.1.75/descriptor.rs
Line
Count
Source
1
// Copyright 2025 Google
2
// SPDX-License-Identifier: MIT
3
4
use crate::OwnedDescriptor;
5
use crate::RawDescriptor;
6
7
/// Trait for forfeiting ownership of the current raw descriptor, and returning the raw descriptor
8
pub trait IntoRawDescriptor {
9
    fn into_raw_descriptor(self) -> RawDescriptor;
10
}
11
12
/// Trait for returning the underlying raw descriptor, without giving up ownership of the
13
/// descriptor.
14
pub trait AsRawDescriptor {
15
    /// Returns the underlying raw descriptor.
16
    ///
17
    /// Since the descriptor is still owned by the provider, callers should not assume that it will
18
    /// remain open for longer than the immediate call of this method. In particular, it is a
19
    /// dangerous practice to store the result of this method for future use: instead, it should be
20
    /// used to e.g. obtain a raw descriptor that is immediately passed to a system call.
21
    ///
22
    /// If you need to use the descriptor for a longer time (and particularly if you cannot reliably
23
    /// track the lifetime of the providing object), you should probably consider using
24
    /// `OwnedDescriptor` (possibly along with `IntoRawDescriptor`) to get full ownership
25
    /// over a descriptor pointing to the same resource.
26
    fn as_raw_descriptor(&self) -> RawDescriptor;
27
}
28
29
pub trait FromRawDescriptor {
30
    /// # Safety
31
    /// Safe only if the caller ensures nothing has access to the descriptor after passing it to
32
    /// `from_raw_descriptor`
33
    unsafe fn from_raw_descriptor(descriptor: RawDescriptor) -> Self;
34
}
35
36
impl IntoRawDescriptor for i64 {
37
0
    fn into_raw_descriptor(self) -> RawDescriptor {
38
0
        self as RawDescriptor
39
0
    }
40
}
41
42
pub trait AsBorrowedDescriptor {
43
    fn as_borrowed_descriptor(&self) -> &OwnedDescriptor;
44
}