Skip to main content

maplibre_native_ffi/generated/
resource_request.rs

1// Generated from C headers by tools/bindgen. Do not edit.
2use super::*;
3
4native_owner! {
5    /// Owns one native handle.
6    ///
7    /// A resource load that a resource provider answers.
8    ///
9    /// See `mln_resource_request` in the
10    /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/base_8h.html).
11    pub struct ResourceRequestHandle(mln_resource_request) dispose |raw| { unsafe { sys::mln_resource_request_release(raw) }; Ok(()) };
12    /// Returns the native handle value.
13    fn id;
14}
15
16impl ResourceRequestHandle {
17    /// Answers a resource request.
18    ///
19    /// A failed answer fails the request with `ResourceErrorReason::Other`, as
20    /// `ResourceRequestHandle::release()` does.
21    ///
22    /// See `mln_resource_request_complete` in the
23    /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/runtime_8h.html).
24    ///
25    /// # Errors
26    ///
27    /// - `Status::InvalidState` when the library cancelled the request.
28    pub fn complete(self, response: &ResourceResponse<'_>) -> Result<()> {
29        self.consume_always(|handle| {
30            let mut call = Call::new(handle);
31            let response = call.reference(&response)?;
32            call.status(|handle, out_diagnostic| unsafe {
33                sys::mln_resource_request_complete(handle, response, out_diagnostic)
34            })
35        })
36    }
37
38    /// Reads whether the library cancelled a resource request.
39    ///
40    /// See `mln_resource_request_is_cancelled` in the
41    /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/runtime_8h.html).
42    pub fn is_cancelled(&self) -> Result<bool> {
43        let mut call = self.inner.call();
44        let mut out_cancelled: bool = Default::default();
45        call.status(|handle, out_diagnostic| unsafe {
46            sys::mln_resource_request_is_cancelled(handle, &mut out_cancelled, out_diagnostic)
47        })?;
48        Ok(out_cancelled)
49    }
50
51    /// Hands a resource request back to the library to load as usual.
52    ///
53    /// A failed call fails the request with `ResourceErrorReason::Other`, as
54    /// `ResourceRequestHandle::release()` does.
55    ///
56    /// See `mln_resource_request_pass_through` in the
57    /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/runtime_8h.html).
58    ///
59    /// # Errors
60    ///
61    /// - `Status::InvalidState` when the library cancelled the request.
62    pub fn pass_through(self) -> Result<()> {
63        self.consume_always(|handle| {
64            let mut call = Call::new(handle);
65            call.status(|handle, out_diagnostic| unsafe {
66                sys::mln_resource_request_pass_through(handle, out_diagnostic)
67            })
68        })
69    }
70
71    /// Releases a resource request.
72    ///
73    /// Releasing a request without an answer fails it with
74    /// `ResourceErrorReason::Other`.
75    ///
76    /// See `mln_resource_request_release` in the
77    /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/runtime_8h.html).
78    pub fn release(self) -> std::result::Result<(), ReleaseError<Self>> {
79        self.consume(|handle| {
80            let mut call = Call::new(handle);
81            call.run(|handle| unsafe { sys::mln_resource_request_release(handle) });
82            Ok(())
83        })
84    }
85
86    /// Calls a callback when the library cancels a resource request.
87    ///
88    /// The callback never runs after the request is answered. A request takes
89    /// one cancel callback. When the library has already cancelled the request,
90    /// the call reports that instead and the callback never runs.
91    ///
92    /// See `mln_resource_request_set_cancel_callback` in the
93    /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/runtime_8h.html).
94    pub fn set_cancel_callback(&self, handler: ResourceRequestCancelHandler) -> Result<bool> {
95        let mut call = self.inner.call();
96        let mut out_cancelled: bool = Default::default();
97        let handler = call.reference(&handler)?;
98        call.status_registered(|handle, out_diagnostic| {
99            let status = unsafe {
100                sys::mln_resource_request_set_cancel_callback(
101                    handle,
102                    handler,
103                    &mut out_cancelled,
104                    out_diagnostic,
105                )
106            };
107            (status, !out_cancelled)
108        })?;
109        Ok(out_cancelled)
110    }
111}