metal-rust 1.0.0

Safe Rust interfaces for Apple Metal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
//! Safe binary-archive, function-stitching, and function-table APIs.

use super::{
    Argument, ArgumentEncoder, Attribute, BinaryArchive, BinaryArchiveDescriptor, Binding, Buffer,
    ComputePipelineDescriptor, Counter, CounterSampleBuffer, CounterSet, DepthStencilDescriptor,
    DepthStencilState, DynamicLibrary, Function, FunctionDescriptor, FunctionHandle,
    FunctionLogDebugLocation, FunctionReflection, FunctionStitchingAttribute,
    FunctionStitchingAttributeAlwaysInline, FunctionStitchingFunctionNode, FunctionStitchingGraph,
    FunctionStitchingInputNode, FunctionStitchingNode, IntersectionFunctionSignature,
    IntersectionFunctionTable, Library, MeshRenderPipelineDescriptor, PipelineBufferDescriptor,
    PipelineBufferDescriptorArray, RenderPipelineDescriptor, ResourceID, SamplerAddressMode,
    SamplerDescriptor, SamplerState, StitchedLibraryDescriptor, TileRenderPipelineDescriptor,
    VertexAttribute, VisibleFunctionTable,
};
use crate::Error;
use std::ops::Range;
use std::path::{Path, PathBuf};

/// A borrowed function-stitching node accepted by slice-based APIs.
#[derive(Clone, Copy)]
pub enum StitchingNodeRef<'a> {
    /// An input node.
    Input(&'a FunctionStitchingInputNode),
    /// A function-call node.
    Function(&'a FunctionStitchingFunctionNode),
    /// An opaque node returned by Metal.
    Node(&'a FunctionStitchingNode),
}

/// A borrowed function-stitching attribute accepted by slice-based APIs.
#[derive(Clone, Copy)]
pub enum StitchingAttributeRef<'a> {
    /// An always-inline attribute.
    AlwaysInline(&'a FunctionStitchingAttributeAlwaysInline),
    /// An opaque attribute returned by Metal.
    Attribute(&'a FunctionStitchingAttribute),
}

impl BinaryArchiveDescriptor {
    /// Sets or clears the archive source using a Rust file path.
    pub fn set_file_path(&self, path: Option<&Path>) -> Result<(), Error> {
        self.inner.set_file_path(path).map_err(Error::from_ffi)
    }

    /// Returns the optional archive source as an owned Rust path.
    pub fn file_path(&self) -> Result<Option<PathBuf>, Error> {
        self.inner.file_path().map_err(Error::from_ffi)
    }
}

impl BinaryArchive {
    /// Adds functions selected by a compute-pipeline descriptor.
    pub fn add_compute_pipeline_functions(
        &self,
        descriptor: &ComputePipelineDescriptor,
    ) -> Result<(), Error> {
        self.inner
            .add_compute_pipeline_functions(&descriptor.inner)
            .map_err(Error::from_ffi)
    }

    /// Adds one function selected from a library.
    pub fn add_function(
        &self,
        descriptor: &FunctionDescriptor,
        library: &Library,
    ) -> Result<(), Error> {
        self.inner
            .add_function(&descriptor.inner, &library.inner)
            .map_err(Error::from_ffi)
    }

    /// Adds functions selected by a stitched-library descriptor.
    pub fn add_stitched_library(
        &self,
        descriptor: &StitchedLibraryDescriptor,
    ) -> Result<(), Error> {
        self.inner
            .add_stitched_library(&descriptor.inner)
            .map_err(Error::from_ffi)
    }

    /// Adds functions selected by a mesh render-pipeline descriptor.
    pub fn add_mesh_render_pipeline_functions(
        &self,
        descriptor: &MeshRenderPipelineDescriptor,
    ) -> Result<(), Error> {
        self.inner
            .add_mesh_render_pipeline_functions(&descriptor.inner)
            .map_err(Error::from_ffi)
    }

    /// Adds functions selected by a render-pipeline descriptor.
    pub fn add_render_pipeline_functions(
        &self,
        descriptor: &RenderPipelineDescriptor,
    ) -> Result<(), Error> {
        self.inner
            .add_render_pipeline_functions(&descriptor.inner)
            .map_err(Error::from_ffi)
    }

    /// Adds functions selected by a tile render-pipeline descriptor.
    pub fn add_tile_render_pipeline_functions(
        &self,
        descriptor: &TileRenderPipelineDescriptor,
    ) -> Result<(), Error> {
        self.inner
            .add_tile_render_pipeline_functions(&descriptor.inner)
            .map_err(Error::from_ffi)
    }

    /// Serializes this archive to a Rust file path.
    pub fn serialize_to_file(&self, path: impl AsRef<Path>) -> Result<(), Error> {
        self.inner
            .serialize_to_file(path.as_ref())
            .map_err(Error::from_ffi)
    }

    /// Sets or clears the diagnostic label.
    pub fn set_optional_label(&self, label: Option<&str>) -> Result<(), Error> {
        self.inner
            .set_optional_label(label)
            .map_err(Error::from_ffi)
    }
}

impl FunctionStitchingInputNode {
    /// Creates an input node for one argument index.
    pub fn with_argument_index(argument_index: usize) -> Result<Self, Error> {
        metal_rust_ffi::__private::objects::metal::FunctionStitchingInputNode::with_argument_index(
            argument_index,
        )
        .map(Self::from_ffi)
        .map_err(Error::from_ffi)
    }
}

fn ffi_nodes<'a>(values: &[StitchingNodeRef<'a>]) -> Vec<metal_rust_ffi::StitchingNodeRef<'a>> {
    values
        .iter()
        .map(|value| match value {
            StitchingNodeRef::Input(value) => metal_rust_ffi::StitchingNodeRef::Input(&value.inner),
            StitchingNodeRef::Function(value) => {
                metal_rust_ffi::StitchingNodeRef::Function(&value.inner)
            }
            StitchingNodeRef::Node(value) => metal_rust_ffi::StitchingNodeRef::Node(&value.inner),
        })
        .collect()
}

fn ffi_attributes<'a>(
    values: &[StitchingAttributeRef<'a>],
) -> Vec<metal_rust_ffi::StitchingAttributeRef<'a>> {
    values
        .iter()
        .map(|value| match value {
            StitchingAttributeRef::AlwaysInline(value) => {
                metal_rust_ffi::StitchingAttributeRef::AlwaysInline(&value.inner)
            }
            StitchingAttributeRef::Attribute(value) => {
                metal_rust_ffi::StitchingAttributeRef::Attribute(&value.inner)
            }
        })
        .collect()
}

impl FunctionStitchingFunctionNode {
    /// Creates a fully initialized function-call node from Rust slices.
    pub fn with_details(
        name: &str,
        arguments: &[StitchingNodeRef<'_>],
        control_dependencies: &[FunctionStitchingFunctionNode],
    ) -> Result<Self, Error> {
        let arguments = ffi_nodes(arguments);
        let dependencies = control_dependencies
            .iter()
            .map(|value| value.inner.clone())
            .collect::<Vec<_>>();
        metal_rust_ffi::__private::objects::metal::FunctionStitchingFunctionNode::with_details(
            name,
            &arguments,
            &dependencies,
        )
        .map(Self::from_ffi)
        .map_err(Error::from_ffi)
    }

    /// Returns argument nodes as owned safe wrappers.
    pub fn arguments_vec(&self) -> Result<Vec<FunctionStitchingNode>, Error> {
        self.inner
            .arguments_vec()
            .map(|values| {
                values
                    .into_iter()
                    .map(FunctionStitchingNode::from_ffi)
                    .collect()
            })
            .map_err(Error::from_ffi)
    }

    /// Replaces argument nodes from a safe Rust slice.
    pub fn set_arguments_slice(&self, values: &[StitchingNodeRef<'_>]) -> Result<(), Error> {
        self.inner
            .set_arguments_slice(&ffi_nodes(values))
            .map_err(Error::from_ffi)
    }

    /// Returns control dependencies as owned safe wrappers.
    pub fn control_dependencies_vec(&self) -> Result<Vec<FunctionStitchingFunctionNode>, Error> {
        self.inner
            .control_dependencies_vec()
            .map(|values| {
                values
                    .into_iter()
                    .map(FunctionStitchingFunctionNode::from_ffi)
                    .collect()
            })
            .map_err(Error::from_ffi)
    }

    /// Replaces control dependencies from a safe Rust slice.
    pub fn set_control_dependencies_slice(
        &self,
        values: &[FunctionStitchingFunctionNode],
    ) -> Result<(), Error> {
        let values = values
            .iter()
            .map(|value| value.inner.clone())
            .collect::<Vec<_>>();
        self.inner
            .set_control_dependencies_slice(&values)
            .map_err(Error::from_ffi)
    }
}

impl FunctionStitchingGraph {
    /// Creates a fully initialized function graph from Rust slices.
    pub fn with_details(
        function_name: &str,
        nodes: &[FunctionStitchingFunctionNode],
        output_node: &FunctionStitchingFunctionNode,
        attributes: &[StitchingAttributeRef<'_>],
    ) -> Result<Self, Error> {
        let nodes = nodes
            .iter()
            .map(|value| value.inner.clone())
            .collect::<Vec<_>>();
        let attributes = ffi_attributes(attributes);
        metal_rust_ffi::__private::objects::metal::FunctionStitchingGraph::with_details(
            function_name,
            &nodes,
            &output_node.inner,
            &attributes,
        )
        .map(Self::from_ffi)
        .map_err(Error::from_ffi)
    }

    /// Returns graph nodes as owned safe wrappers.
    pub fn nodes_vec(&self) -> Result<Vec<FunctionStitchingFunctionNode>, Error> {
        self.inner
            .nodes_vec()
            .map(|values| {
                values
                    .into_iter()
                    .map(FunctionStitchingFunctionNode::from_ffi)
                    .collect()
            })
            .map_err(Error::from_ffi)
    }

    /// Replaces graph nodes from a safe Rust slice.
    pub fn set_nodes_slice(&self, values: &[FunctionStitchingFunctionNode]) -> Result<(), Error> {
        let values = values
            .iter()
            .map(|value| value.inner.clone())
            .collect::<Vec<_>>();
        self.inner.set_nodes_slice(&values).map_err(Error::from_ffi)
    }

    /// Returns graph attributes as owned safe wrappers.
    pub fn attributes_vec(&self) -> Result<Vec<FunctionStitchingAttribute>, Error> {
        self.inner
            .attributes_vec()
            .map(|values| {
                values
                    .into_iter()
                    .map(FunctionStitchingAttribute::from_ffi)
                    .collect()
            })
            .map_err(Error::from_ffi)
    }

    /// Replaces graph attributes from a safe Rust slice.
    pub fn set_attributes_slice(&self, values: &[StitchingAttributeRef<'_>]) -> Result<(), Error> {
        self.inner
            .set_attributes_slice(&ffi_attributes(values))
            .map_err(Error::from_ffi)
    }
}

impl StitchedLibraryDescriptor {
    /// Returns function graphs as owned safe wrappers.
    pub fn function_graphs_vec(&self) -> Result<Vec<FunctionStitchingGraph>, Error> {
        self.inner
            .function_graphs_vec()
            .map(|values| {
                values
                    .into_iter()
                    .map(FunctionStitchingGraph::from_ffi)
                    .collect()
            })
            .map_err(Error::from_ffi)
    }

    /// Replaces function graphs from a safe Rust slice.
    pub fn set_function_graphs_slice(
        &self,
        values: &[FunctionStitchingGraph],
    ) -> Result<(), Error> {
        let values = values
            .iter()
            .map(|value| value.inner.clone())
            .collect::<Vec<_>>();
        self.inner
            .set_function_graphs_slice(&values)
            .map_err(Error::from_ffi)
    }

    /// Returns source functions as owned safe wrappers.
    pub fn functions_vec(&self) -> Result<Vec<Function>, Error> {
        self.inner
            .functions_vec()
            .map(|values| values.into_iter().map(Function::from_ffi).collect())
            .map_err(Error::from_ffi)
    }

    /// Replaces source functions from a safe Rust slice.
    pub fn set_functions_slice(&self, values: &[Function]) -> Result<(), Error> {
        let values = values
            .iter()
            .map(|value| value.inner.clone())
            .collect::<Vec<_>>();
        self.inner
            .set_functions_slice(&values)
            .map_err(Error::from_ffi)
    }

    /// Returns binary archives as owned safe wrappers.
    pub fn binary_archives_vec(&self) -> Result<Vec<BinaryArchive>, Error> {
        self.inner
            .binary_archives_vec()
            .map(|values| values.into_iter().map(BinaryArchive::from_ffi).collect())
            .map_err(Error::from_ffi)
    }

    /// Replaces binary archives from a safe Rust slice.
    pub fn set_binary_archives_slice(&self, values: &[BinaryArchive]) -> Result<(), Error> {
        let values = values
            .iter()
            .map(|value| value.inner.clone())
            .collect::<Vec<_>>();
        self.inner
            .set_binary_archives_slice(&values)
            .map_err(Error::from_ffi)
    }
}

impl VisibleFunctionTable {
    /// Returns the opaque GPU resource identifier.
    pub fn gpu_resource_id(&self) -> Result<ResourceID, Error> {
        self.inner.gpu_resource_id().map_err(Error::from_ffi)
    }

    /// Binds or clears one function-table slot.
    pub fn set_function(
        &self,
        function: Option<&FunctionHandle>,
        index: usize,
    ) -> Result<(), Error> {
        self.inner
            .set_function(function.map(|value| &value.inner), index)
            .map_err(Error::from_ffi)
    }

    /// Safe slice substitute for Metal's function-handle pointer array.
    pub fn set_functions(
        &self,
        functions: &[Option<&FunctionHandle>],
        start_index: usize,
    ) -> Result<(), Error> {
        let functions = functions
            .iter()
            .map(|value| value.map(|value| &value.inner))
            .collect::<Vec<_>>();
        self.inner
            .set_functions(&functions, start_index)
            .map_err(Error::from_ffi)
    }
}

impl IntersectionFunctionTable {
    /// Returns the opaque GPU resource identifier.
    pub fn gpu_resource_id(&self) -> Result<ResourceID, Error> {
        self.inner.gpu_resource_id().map_err(Error::from_ffi)
    }

    /// Binds or clears a checked buffer region.
    pub fn set_buffer(
        &self,
        buffer: Option<&Buffer>,
        offset: usize,
        index: usize,
    ) -> Result<(), Error> {
        self.inner
            .set_buffer(buffer.map(|value| &value.inner), offset, index)
            .map_err(Error::from_ffi)
    }

    /// Safe slice substitute for Metal's parallel buffer/offset arrays.
    pub fn set_buffers(
        &self,
        bindings: &[(Option<&Buffer>, usize)],
        start_index: usize,
    ) -> Result<(), Error> {
        let bindings = bindings
            .iter()
            .map(|(buffer, offset)| (buffer.map(|value| &value.inner), *offset))
            .collect::<Vec<_>>();
        self.inner
            .set_buffers(&bindings, start_index)
            .map_err(Error::from_ffi)
    }

    /// Binds or clears one function-table slot.
    pub fn set_function(
        &self,
        function: Option<&FunctionHandle>,
        index: usize,
    ) -> Result<(), Error> {
        self.inner
            .set_function(function.map(|value| &value.inner), index)
            .map_err(Error::from_ffi)
    }

    /// Safe slice substitute for Metal's function-handle pointer array.
    pub fn set_functions(
        &self,
        functions: &[Option<&FunctionHandle>],
        start_index: usize,
    ) -> Result<(), Error> {
        let functions = functions
            .iter()
            .map(|value| value.map(|value| &value.inner))
            .collect::<Vec<_>>();
        self.inner
            .set_functions(&functions, start_index)
            .map_err(Error::from_ffi)
    }

    /// Installs an opaque triangle function at one slot.
    pub fn set_opaque_triangle_function(
        &self,
        signature: IntersectionFunctionSignature,
        index: usize,
    ) -> Result<(), Error> {
        self.inner
            .set_opaque_triangle_function(signature, index)
            .map_err(Error::from_ffi)
    }

    /// Installs an opaque triangle function across a checked Rust range.
    pub fn set_opaque_triangle_function_range(
        &self,
        signature: IntersectionFunctionSignature,
        range: Range<usize>,
    ) -> Result<(), Error> {
        self.inner
            .set_opaque_triangle_function_range(signature, range)
            .map_err(Error::from_ffi)
    }

    /// Installs an opaque curve function at one slot.
    pub fn set_opaque_curve_function(
        &self,
        signature: IntersectionFunctionSignature,
        index: usize,
    ) -> Result<(), Error> {
        self.inner
            .set_opaque_curve_function(signature, index)
            .map_err(Error::from_ffi)
    }

    /// Installs an opaque curve function across a checked Rust range.
    pub fn set_opaque_curve_function_range(
        &self,
        signature: IntersectionFunctionSignature,
        range: Range<usize>,
    ) -> Result<(), Error> {
        self.inner
            .set_opaque_curve_function_range(signature, range)
            .map_err(Error::from_ffi)
    }

    /// Binds or clears one visible-function table at a buffer index.
    pub fn set_visible_function_table(
        &self,
        table: Option<&VisibleFunctionTable>,
        buffer_index: usize,
    ) -> Result<(), Error> {
        self.inner
            .set_visible_function_table(table.map(|value| &value.inner), buffer_index)
            .map_err(Error::from_ffi)
    }

    /// Safe slice substitute for Metal's visible-function-table pointer array.
    pub fn set_visible_function_tables(
        &self,
        tables: &[Option<&VisibleFunctionTable>],
        start_buffer_index: usize,
    ) -> Result<(), Error> {
        let tables = tables
            .iter()
            .map(|value| value.map(|value| &value.inner))
            .collect::<Vec<_>>();
        self.inner
            .set_visible_function_tables(&tables, start_buffer_index)
            .map_err(Error::from_ffi)
    }
}

impl FunctionDescriptor {
    /// Returns associated binary archives as owned safe wrappers.
    pub fn binary_archives_vec(&self) -> Result<Vec<BinaryArchive>, Error> {
        self.inner
            .binary_archives_vec()
            .map(|values| values.into_iter().map(BinaryArchive::from_ffi).collect())
            .map_err(Error::from_ffi)
    }

    /// Replaces associated binary archives from a safe Rust slice.
    pub fn set_binary_archives_slice(&self, values: &[BinaryArchive]) -> Result<(), Error> {
        let values = values
            .iter()
            .map(|value| value.inner.clone())
            .collect::<Vec<_>>();
        self.inner
            .set_binary_archives_slice(&values)
            .map_err(Error::from_ffi)
    }
}

impl PipelineBufferDescriptorArray {
    /// Returns one optional pipeline-buffer descriptor at a checked index.
    pub fn buffer(&self, index: usize) -> Result<Option<PipelineBufferDescriptor>, Error> {
        self.inner
            .buffer(index)
            .map(|value| value.map(PipelineBufferDescriptor::from_ffi))
            .map_err(Error::from_ffi)
    }

    /// Replaces or clears one pipeline-buffer descriptor at a checked index.
    pub fn set_buffer(
        &self,
        index: usize,
        value: Option<&PipelineBufferDescriptor>,
    ) -> Result<(), Error> {
        self.inner
            .set_buffer(index, value.map(|value| &value.inner))
            .map_err(Error::from_ffi)
    }
}

impl SamplerDescriptor {
    /// Returns the R-coordinate address mode after availability checks.
    pub fn r_address_mode(&self) -> Result<SamplerAddressMode, Error> {
        self.inner.r_address_mode().map_err(Error::from_ffi)
    }

    /// Sets a checked R-coordinate address mode.
    pub fn set_r_address_mode(&self, value: SamplerAddressMode) -> Result<(), Error> {
        self.inner
            .set_r_address_mode(value)
            .map_err(Error::from_ffi)
    }
}

impl DepthStencilDescriptor {
    /// Safe canonical alias for Metal's deprecated depth-write getter.
    pub fn depth_write_enabled(&self) -> Result<bool, Error> {
        self.inner.depth_write_enabled().map_err(Error::from_ffi)
    }
}

macro_rules! facade_gpu_resource_id {
    ($type:ty) => {
        impl $type {
            /// Returns the opaque GPU resource identifier.
            pub fn gpu_resource_id(&self) -> Result<ResourceID, Error> {
                self.inner.gpu_resource_id().map_err(Error::from_ffi)
            }
        }
    };
}

facade_gpu_resource_id!(DepthStencilState);
facade_gpu_resource_id!(SamplerState);
facade_gpu_resource_id!(FunctionHandle);

impl CounterSet {
    /// Returns the counters in this set as owned wrappers.
    pub fn counters_vec(&self) -> Result<Vec<Counter>, Error> {
        self.inner
            .counters_vec()
            .map(|values| values.into_iter().map(Counter::from_ffi).collect())
            .map_err(Error::from_ffi)
    }
}

impl CounterSampleBuffer {
    /// Resolves a checked counter sample range into owned bytes when available.
    pub fn resolve_counter_range(&self, range: Range<usize>) -> Result<Option<Vec<u8>>, Error> {
        self.inner
            .resolve_counter_range(range)
            .map_err(Error::from_ffi)
    }
}

impl DynamicLibrary {
    /// Serializes this dynamic library to a Rust file path.
    pub fn serialize_to_file(&self, path: impl AsRef<Path>) -> Result<(), Error> {
        self.inner
            .serialize_to_file(path.as_ref())
            .map_err(Error::from_ffi)
    }
}

impl FunctionLogDebugLocation {
    /// Returns the source URL as an owned absolute string.
    pub fn source_url(&self) -> Result<Option<String>, Error> {
        self.inner.source_url().map_err(Error::from_ffi)
    }
}

impl FunctionReflection {
    /// Returns reflected bindings as owned safe wrappers.
    pub fn bindings_vec(&self) -> Result<Vec<Binding>, Error> {
        self.inner
            .bindings_vec()
            .map(|values| values.into_iter().map(Binding::from_ffi).collect())
            .map_err(Error::from_ffi)
    }
}

macro_rules! facade_deprecated_attribute_getters {
    ($type:ty) => {
        impl $type {
            /// Safe canonical alias for Metal's deprecated `active` getter.
            pub fn active(&self) -> Result<bool, Error> {
                self.inner.active().map_err(Error::from_ffi)
            }

            /// Safe canonical alias for Metal's deprecated patch-control-point getter.
            pub fn patch_control_point_data(&self) -> Result<bool, Error> {
                self.inner
                    .patch_control_point_data()
                    .map_err(Error::from_ffi)
            }

            /// Safe canonical alias for Metal's deprecated patch-data getter.
            pub fn patch_data(&self) -> Result<bool, Error> {
                self.inner.patch_data().map_err(Error::from_ffi)
            }
        }
    };
}

facade_deprecated_attribute_getters!(VertexAttribute);
facade_deprecated_attribute_getters!(Attribute);

impl Function {
    /// Creates an argument encoder for a checked buffer binding index.
    pub fn new_argument_encoder(&self, buffer_index: usize) -> Result<ArgumentEncoder, Error> {
        self.inner
            .new_argument_encoder(buffer_index)
            .map(ArgumentEncoder::from_ffi)
            .map_err(Error::from_ffi)
    }

    /// Creates an argument encoder and returns its optional owned reflection.
    pub fn new_argument_encoder_with_reflection(
        &self,
        buffer_index: usize,
    ) -> Result<(ArgumentEncoder, Option<Argument>), Error> {
        self.inner
            .new_argument_encoder_with_reflection(buffer_index)
            .map(|(encoder, reflection)| {
                (
                    ArgumentEncoder::from_ffi(encoder),
                    reflection.map(Argument::from_ffi),
                )
            })
            .map_err(Error::from_ffi)
    }
}