16
16
17
17
If all code is glued together, our glue is the safest on the market.
18
18
19
- ## FFI-safe trait generation, helper structures, and more!
19
+ ## The most complete dynamic trait object implementation, period.
20
20
21
21
<!-- toc -->
22
22
- [ Overview] ( #overview )
@@ -41,31 +41,35 @@ If all code is glued together, our glue is the safest on the market.
41
41
42
42
## Overview
43
43
44
- CGlue bridges Rust traits between C and other languages. It aims to be seamless to integrate -
45
- just add a few annotations around your traits, and they should be good to go!
44
+ CGlue exposes ` dyn Trait ` in FFI-safe manner. It bridges Rust traits between C and other
45
+ languages. It aims to be seamless to integrate - just add a few annotations around your traits,
46
+ and they should be good to go!
46
47
47
48
``` rust
48
49
use cglue :: * ;
49
50
50
51
// One annotation for the trait.
51
52
#[cglue_trait]
52
53
pub trait InfoPrinter {
53
- fn print_info (& self );
54
+ type Mark ;
55
+ fn print_info (& self , mark : Self :: Mark );
54
56
}
55
57
56
58
struct Info {
57
59
value : usize
58
60
}
59
61
60
62
impl InfoPrinter for Info {
61
- fn print_info (& self ) {
62
- println! (" Info struct: {}" , self . value);
63
+ type Mark = u8 ;
64
+
65
+ fn print_info (& self , mark : Self :: Mark ) {
66
+ println! (" {} - info struct: {}" , mark , self . value);
63
67
}
64
68
}
65
69
66
- fn use_info_printer (printer : & impl InfoPrinter ) {
70
+ fn use_info_printer < T : InfoPrinter > (printer : & T , mark : T :: Mark ) {
67
71
println! (" Printing info:" );
68
- printer . print_info ();
72
+ printer . print_info (mark );
69
73
}
70
74
71
75
fn main () -> () {
@@ -76,7 +80,7 @@ fn main() -> () {
76
80
// Here, the object is fully opaque, and is FFI and ABI safe.
77
81
let obj = trait_obj! (& mut info as InfoPrinter );
78
82
79
- use_info_printer (& obj );
83
+ use_info_printer (& obj , 42 );
80
84
}
81
85
```
82
86
@@ -331,7 +335,8 @@ impl<
331
335
> GenGroupVtableFiller <'cglue_a , CGlueInst , CGlueCtx , T > for GA <T >
332
336
where
333
337
Self : TA ,
334
- & 'cglue_a TAVtbl <'cglue_a , GenGroupContainer <CGlueInst , CGlueCtx , T >>:
338
+ & 'cglue_a TAVtbl <'cglue_a , GenGroupContainer <CGlueInst , CGlueCtx , T >,
339
+ >:
335
340
'cglue_a + Default ,
336
341
T : cglue :: trait_group :: GenericTypeBounds ,
337
342
{
@@ -739,5 +744,3 @@ If you want your project to be added to the list, please open an issue report :)
739
744
740
745
It is available in [ CHANGELOG.md] ( https://github.com/h33p/cglue/blob/main/CHANGELOG.md ) file.
741
746
742
-
743
- License: MIT
0 commit comments