drawing_api/
lib.rs

1mod common;
2use std::ops::Deref;
3
4pub use common::*;
5
6mod gl;
7pub use gl::*;
8
9mod vulkan;
10pub use vulkan::*;
11
12pub mod dyn_api;
13
14/// Represents either an owned or borrowed T.
15/// Useful to pass `T` or `&'a T` to a function when used as `Into<OptRef<'a, T>>`.
16///
17/// It is defined in this crate, so the From trait can be implemented for foreigin types.
18pub enum OptRef<'a, T> {
19    Borrowed(&'a T),
20    Owned(T),
21}
22
23impl<T> Deref for OptRef<'_, T> {
24    type Target = T;
25
26    fn deref(&self) -> &T {
27        match self {
28            Self::Owned(v) => v,
29            Self::Borrowed(v) => *v,
30        }
31    }
32}
33
34impl<'a, T: Clone> OptRef<'a, T> {
35    pub fn to_owned(self) -> T {
36        match self {
37            OptRef::Borrowed(v) => v.clone(),
38            OptRef::Owned(v) => v,
39        }
40    }
41}
42
43/// Represents owned T.
44/// Useful to pass `T` to a function when used as `Into<Owned<T>>`.
45///
46/// It is defined in this crate, so the From trait can be implemented for foreigin types.
47pub struct Owned<T>(T);