cidre/ns/coder.rs
1use crate::{arc, define_obj_type, ns, objc};
2
3/// Describes the action an ns::Coder should take when it encounters decode failures (e.g. corrupt data)
4/// for non-TopLevel decodes.
5#[doc(alias = "NSDecodingFailurePolicy")]
6#[derive(Debug, Eq, PartialEq, Copy, Clone)]
7#[repr(isize)]
8pub enum DecodingFailurePolicy {
9 /// On decode failure, the [`ns::Coder`] will raise an exception internally
10 /// to propagate failure messages (and unwind the stack). This exception can be transformed
11 /// into an ns::Error via any of the TopLevel decode APIs.
12 RaiseException,
13
14 /// On decode failure, the [`ns::Coder`] will capture the failure as an [`ns::Error`],
15 /// and prevent further decodes (by returning 0 / None equivalent as appropriate).
16 /// Clients should consider using this policy if they know that all encoded objects behave correctly
17 /// in the presence of decode failures (e.g. they use fail_with_error to communicate decode failures
18 /// and don't raise exceptions for error propagation)
19 SetErrorAndReturn,
20}
21
22define_obj_type!(
23 #[doc(alias = "NSCoder")]
24 pub Coder(ns::Id), NS_CODER
25);
26
27impl Coder {}
28
29unsafe extern "C" {
30 static NS_CODER: &'static objc::Class<Coder>;
31}
32
33#[cfg(test)]
34mod tests {
35 use crate::ns;
36
37 #[test]
38 fn basics() {
39 let coder = ns::Coder::new();
40 println!("{coder:?}");
41 }
42}