rust_macios/foundation/
ns_uuid.rs1use std::ffi::c_uchar;
2
3use crate::{
4 object,
5 objective_c_runtime::{
6 macros::interface_impl,
7 msg_send, sel, sel_impl,
8 traits::{FromId, PNSObject},
9 },
10};
11
12use super::{NSComparisonResult, NSString};
13
14object! {
15 unsafe pub struct NSUUID;
17}
18
19#[interface_impl(NSObject)]
20impl NSUUID {
21 #[method]
26 pub fn uuid() -> Self
27 where
28 Self: Sized + FromId,
29 {
30 unsafe { Self::from_id(msg_send![Self::m_class(), UUID]) }
31 }
32
33 #[method]
35 pub fn init(&mut self) -> Self
36 where
37 Self: Sized + FromId,
38 {
39 unsafe { Self::from_id(msg_send![self.m_self(), init]) }
40 }
41
42 #[method]
44 pub fn init_with_uuid_string(&mut self, string: NSString) -> Self
45 where
46 Self: Sized + FromId,
47 {
48 unsafe { Self::from_id(msg_send![self.m_self(), initWithUUIDString: string]) }
49 }
50
51 #[method]
61 pub fn init_with_uuid_bytes(&mut self, bytes: *const c_uchar) -> Self
62 where
63 Self: Sized + FromId,
64 {
65 unsafe { Self::from_id(msg_send![self.m_self(), initWithUUIDBytes: bytes]) }
66 }
67
68 #[method]
77 pub fn get_uuid_bytes(&self, uuid: *mut c_uchar) {
78 unsafe { msg_send![self.m_self(), getUUIDBytes: uuid] }
79 }
80
81 #[property]
83 pub fn uuid_string(&self) -> NSString {
84 unsafe { NSString::from_id(msg_send![self.m_self(), UUIDString]) }
85 }
86
87 #[method]
89 pub fn compare(&self, other_uuid: NSUUID) -> NSComparisonResult {
90 unsafe { msg_send![self.m_self(), compare: other_uuid] }
91 }
92}