Debian Codegraph @

src/memory_format_selection.rs

raw symbols SCIP
1 use craterust-analyzer cargo glycin-common 1.0.4 crate/::{MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#, MemoryFormatInforust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormatInfo#};
2
3 /// Selection of memory formats the API user accepts
4 #[cfg(feature = "gobject")]
5 #[glibrust-analyzer cargo glib 0.22.2 crate/::flagsrust-analyzer cargo glib-macros 0.22.2 flags:(name = "GlyMemoryFormatSelection")]
6 pub enum MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection# {
7 B8g8r8a8Premultipliedrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]B8g8r8a8Premultiplied. = (1 <<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). 0),
8 A8r8g8b8Premultipliedrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]A8r8g8b8Premultiplied. = (1 <<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). 1),
9 R8g8b8a8Premultipliedrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]R8g8b8a8Premultiplied. = (1 <<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). 2),
10 B8g8r8a8rust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]B8g8r8a8. = (1 <<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). 3),
11 A8r8g8b8rust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]A8r8g8b8. = (1 <<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). 4),
12 R8g8b8a8rust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]R8g8b8a8. = (1 <<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). 5),
13 A8b8g8r8rust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]A8b8g8r8. = (1 <<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). 6),
14 R8g8b8rust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]R8g8b8. = (1 <<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). 7),
15 B8g8r8rust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]B8g8r8. = (1 <<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). 8),
16 R16g16b16rust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]R16g16b16. = (1 <<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). 9),
17 R16g16b16a16Premultipliedrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]R16g16b16a16Premultiplied. = (1 <<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). 10),
18 R16g16b16a16rust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]R16g16b16a16. = (1 <<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). 11),
19 R16g16b16Floatrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]R16g16b16Float. = (1 <<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). 12),
20 R16g16b16a16Floatrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]R16g16b16a16Float. = (1 <<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). 13),
21 R32g32b32Floatrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]R32g32b32Float. = (1 <<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). 14),
22 R32g32b32a32FloatPremultipliedrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]R32g32b32a32FloatPremultiplied. = (1 <<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). 15),
23 R32g32b32a32Floatrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]R32g32b32a32Float. = (1 <<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). 16),
24 G8a8Premultipliedrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]G8a8Premultiplied. = (1 <<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). 17),
25 G8a8rust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]G8a8. = (1 <<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). 18),
26 G8rust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]G8. = (1 <<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). 19),
27 G16a16Premultipliedrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]G16a16Premultiplied. = (1 <<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). 20),
28 G16a16rust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]G16a16. = (1 <<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). 21),
29 G16rust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]G16. = (1 <<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). 22),
30 }
31
32 #[cfg(not(feature = "gobject"))]
33 bitflagsrust-analyzer cargo bitflags 2.11.0 crate/::bitflagsrust-analyzer cargo bitflags 2.11.0 bitflags!! {
34 /// Selection of memory formats the API user accepts
35 #[derive(Debug, Clone, Copy)]
36 pub struct MemoryFormatSelection: u32 {
37 const B8g8r8a8Premultiplied = (1 << 0);
38 const A8r8g8b8Premultiplied = (1 << 1);
39 const R8g8b8a8Premultiplied = (1 << 2);
40 const B8g8r8a8 = (1 << 3);
41 const A8r8g8b8 = (1 << 4);
42 const R8g8b8a8 = (1 << 5);
43 const A8b8g8r8 = (1 << 6);
44 const R8g8b8 = (1 << 7);
45 const B8g8r8 = (1 << 8);
46 const R16g16b16 = (1 << 9);
47 const R16g16b16a16Premultiplied = (1 << 10);
48 const R16g16b16a16 = (1 << 11);
49 const R16g16b16Float = (1 << 12);
50 const R16g16b16a16Float = (1 << 13);
51 const R32g32b32Float = (1 << 14);
52 const R32g32b32a32FloatPremultiplied = (1 << 15);
53 const R32g32b32a32Float = (1 << 16);
54 const G8a8Premultiplied = (1 << 17);
55 const G8a8 = (1 << 18);
56 const G8 = (1 << 19);
57 const G16a16Premultiplied = (1 << 20);
58 const G16a16 = (1 << 21);
59 const G16 = (1 << 22);
60 }
61 }
62
63 impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection# {
64 fn defaultrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection][Default]default().() -> Selfrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection][Default] {
65 Selfrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection][Default]::allrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]all().()
66 }
67 }
68
69 impl MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection# {
70 const Xrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]X.: [(MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection#, MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#); 23] = [
71 (
72 MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection#::B8g8r8a8Premultipliedrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]B8g8r8a8Premultiplied.,
73 MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#::B8g8r8a8Premultipliedrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#B8g8r8a8Premultiplied#,
74 ),
75 (
76 MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection#::A8r8g8b8Premultipliedrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]A8r8g8b8Premultiplied.,
77 MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#::A8r8g8b8Premultipliedrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#A8r8g8b8Premultiplied#,
78 ),
79 (
80 MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection#::R8g8b8a8Premultipliedrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]R8g8b8a8Premultiplied.,
81 MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#::R8g8b8a8Premultipliedrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#R8g8b8a8Premultiplied#,
82 ),
83 (MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection#::B8g8r8a8rust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]B8g8r8a8., MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#::B8g8r8a8rust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#B8g8r8a8#),
84 (MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection#::A8r8g8b8rust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]A8r8g8b8., MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#::A8r8g8b8rust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#A8r8g8b8#),
85 (MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection#::R8g8b8a8rust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]R8g8b8a8., MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#::R8g8b8a8rust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#R8g8b8a8#),
86 (MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection#::A8b8g8r8rust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]A8b8g8r8., MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#::A8b8g8r8rust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#A8b8g8r8#),
87 (MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection#::R8g8b8rust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]R8g8b8., MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#::R8g8b8rust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#R8g8b8#),
88 (MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection#::B8g8r8rust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]B8g8r8., MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#::B8g8r8rust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#B8g8r8#),
89 (MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection#::R16g16b16rust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]R16g16b16., MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#::R16g16b16rust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#R16g16b16#),
90 (
91 MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection#::R16g16b16a16Premultipliedrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]R16g16b16a16Premultiplied.,
92 MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#::R16g16b16a16Premultipliedrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#R16g16b16a16Premultiplied#,
93 ),
94 (
95 MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection#::R16g16b16a16rust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]R16g16b16a16.,
96 MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#::R16g16b16a16rust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#R16g16b16a16#,
97 ),
98 (
99 MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection#::R16g16b16Floatrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]R16g16b16Float.,
100 MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#::R16g16b16Floatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#R16g16b16Float#,
101 ),
102 (
103 MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection#::R16g16b16a16Floatrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]R16g16b16a16Float.,
104 MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#::R16g16b16a16Floatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#R16g16b16a16Float#,
105 ),
106 (
107 MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection#::R32g32b32Floatrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]R32g32b32Float.,
108 MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#::R32g32b32Floatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#R32g32b32Float#,
109 ),
110 (
111 MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection#::R32g32b32a32FloatPremultipliedrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]R32g32b32a32FloatPremultiplied.,
112 MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#::R32g32b32a32FloatPremultipliedrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#R32g32b32a32FloatPremultiplied#,
113 ),
114 (
115 MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection#::R32g32b32a32Floatrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]R32g32b32a32Float.,
116 MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#::R32g32b32a32Floatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#R32g32b32a32Float#,
117 ),
118 (
119 MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection#::G8a8Premultipliedrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]G8a8Premultiplied.,
120 MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#::G8a8Premultipliedrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#G8a8Premultiplied#,
121 ),
122 (MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection#::G8a8rust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]G8a8., MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#::G8a8rust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#G8a8#),
123 (MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection#::G8rust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]G8., MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#::G8rust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#G8#),
124 (
125 MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection#::G16a16Premultipliedrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]G16a16Premultiplied.,
126 MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#::G16a16Premultipliedrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#G16a16Premultiplied#,
127 ),
128 (MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection#::G16a16rust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]G16a16., MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#::G16a16rust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#G16a16#),
129 (MemoryFormatSelectionrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/MemoryFormatSelection#::G16rust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]G16., MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#::G16rust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#G16#),
130 ];
131
132 /// List of selected memory formats
133 pub fn memory_formatsrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]memory_formats().(self) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#> {
134 let mut vec = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
135 for (selection, format) in Selfrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]::Xrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]X. {
136 if self.containsrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]contains().(selection) {
137 vec.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(format);
138 }
139 }
140
141 vec
142 }
143
144 /// Select the best contained format to represent `src`
145 ///
146 /// The function returns `None` if no formats are selected.
147 ///
148 /// ```
149 /// # use glycin_common::{MemoryFormatSelection, MemoryFormat};
150 ///
151 /// assert_eq!(
152 /// (MemoryFormatSelection::R8g8b8 | MemoryFormatSelection::R8g8b8a8)
153 /// .best_format_for(MemoryFormat::A8b8g8r8),
154 /// Some(MemoryFormat::R8g8b8a8)
155 /// );
156 ///
157 /// assert_eq!(
158 /// (MemoryFormatSelection::R8g8b8 | MemoryFormatSelection::R8g8b8a8)
159 /// .best_format_for(MemoryFormat::B8g8r8),
160 /// Some(MemoryFormat::R8g8b8)
161 /// );
162 ///
163 /// assert_eq!(
164 /// (MemoryFormatSelection::R8g8b8 | MemoryFormatSelection::R16g16b16)
165 /// .best_format_for(MemoryFormat::B8g8r8),
166 /// Some(MemoryFormat::R8g8b8)
167 /// );
168 ///
169 /// assert_eq!(
170 /// (MemoryFormatSelection::R8g8b8 | MemoryFormatSelection::R16g16b16)
171 /// .best_format_for(MemoryFormat::R16g16b16Float),
172 /// Some(MemoryFormat::R16g16b16)
173 /// );
174 ///
175 /// assert_eq!(
176 /// MemoryFormatSelection::empty().best_format_for(MemoryFormat::R16g16b16Float),
177 /// None
178 /// );
179 /// ```
180 pub fn best_format_forrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]best_format_for().(self, src: MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#> {
181 let formats: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<MemoryFormatrust-analyzer cargo glycin-common 1.0.4 memory_format/MemoryFormat#> = self.memory_formatsrust-analyzer cargo glycin-common 1.0.4 memory_format_selection/impl#[MemoryFormatSelection]memory_formats().();
182
183 // Shortcut if format itself is supported
184 if formats.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&src) {
185 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(src);
186 }
187
188 let mut formats_categorized = formats
189 .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()
190 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|x| {
191 (
192 // Prioritize formats by how good they can represent the original format
193 (
194 x.has_alpharust-analyzer cargo glycin-common 1.0.4 memory_format/impl#[MemoryFormat]has_alpha().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[bool][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[bool][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[bool][`PartialEq<Self>`]eq().src.has_alpharust-analyzer cargo glycin-common 1.0.4 memory_format/impl#[MemoryFormat]has_alpha().(),
195 x.n_channelsrust-analyzer cargo glycin-common 1.0.4 memory_format/impl#[MemoryFormat][MemoryFormatInfo]n_channels().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]ge().src.n_channelsrust-analyzer cargo glycin-common 1.0.4 memory_format/impl#[MemoryFormat][MemoryFormatInfo]n_channels().(),
196 x.channel_typerust-analyzer cargo glycin-common 1.0.4 memory_format/impl#[MemoryFormat]channel_type().() rust-analyzer cargo glycin-common 1.0.4 memory_format/impl#[ChannelType][`PartialEq<Self>`]eq().==rust-analyzer cargo glycin-common 1.0.4 memory_format/impl#[ChannelType][`PartialEq<Self>`]eq(). rust-analyzer cargo glycin-common 1.0.4 memory_format/impl#[ChannelType][`PartialEq<Self>`]eq().src.channel_typerust-analyzer cargo glycin-common 1.0.4 memory_format/impl#[MemoryFormat]channel_type().(),
197 x.channel_typerust-analyzer cargo glycin-common 1.0.4 memory_format/impl#[MemoryFormat]channel_type().().sizerust-analyzer cargo glycin-common 1.0.4 memory_format/impl#[ChannelType]size().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().src.channel_typerust-analyzer cargo glycin-common 1.0.4 memory_format/impl#[MemoryFormat]channel_type().().sizerust-analyzer cargo glycin-common 1.0.4 memory_format/impl#[ChannelType]size().(),
198 // Don't have unnecessary many channels
199 -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][Neg]neg().(x.n_channelsrust-analyzer cargo glycin-common 1.0.4 memory_format/impl#[MemoryFormat][MemoryFormatInfo]n_channels().() as i8),
200 // Don't have unnecessary large types
201 -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][Neg]neg().(x.channel_typerust-analyzer cargo glycin-common 1.0.4 memory_format/impl#[MemoryFormat]channel_type().().sizerust-analyzer cargo glycin-common 1.0.4 memory_format/impl#[ChannelType]size().() as i8),
202 ),
203 x,
204 )
205 })
206 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>();
207
208 formats_categorized.sort_by_keyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]sort_by_key().(|x| x.0);
209
210 // The best format is the highest ranked, i.e. the last one
211 formats_categorized.lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|x| x.1)
212 }
213 }