File: define_class_self.rs

package info (click to toggle)
firefox 148.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,719,656 kB
  • sloc: cpp: 7,618,171; javascript: 6,701,506; ansic: 3,781,787; python: 1,418,364; xml: 638,647; asm: 438,962; java: 186,285; sh: 62,885; makefile: 19,010; objc: 13,092; perl: 12,763; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (64 lines) | stat: -rw-r--r-- 1,501 bytes parent folder | download | duplicates (3)
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
//! To remind myself that `Self` needs to work in methods in `define_class!`,
//! and hence whenever we name any of the types involved in this, we need to
//! do it in a context where `Self` works.
use objc2::rc::{Allocated, Retained};
use objc2::runtime::NSObject;
use objc2::{define_class, ClassType};

trait GetSameType {
    type SameType: ?Sized;
}

impl<T: ?Sized> GetSameType for T {
    type SameType = T;
}

trait GetRetained {
    type RetainedType;
}

impl<T> GetRetained for T {
    type RetainedType = Retained<T>;
}

macro_rules! get_self {
    () => {
        Self
    };
}

define_class!(
    #[unsafe(super(NSObject))]
    struct MyTestObject;

    impl MyTestObject {
        #[unsafe(method_id(initWith:))]
        fn init(
            _this: Allocated<<Self as GetSameType>::SameType>,
            _param: <*const Self as GetSameType>::SameType,
        ) -> Retained<<Self as GetSameType>::SameType> {
            unimplemented!()
        }

        #[unsafe(method(isEqual:))]
        fn is_equal(&self, _other: &Self) -> bool {
            unimplemented!()
        }

        #[unsafe(method_id(test4))]
        #[allow(unused_parens)]
        fn test4(_this: &<(Self) as GetSameType>::SameType) -> Retained<get_self!()> {
            unimplemented!()
        }

        #[unsafe(method_id(test5))]
        fn test5(&self) -> <Self as GetRetained>::RetainedType {
            unimplemented!()
        }
    }
);

#[test]
fn create_class() {
    let _ = MyTestObject::class();
}