Skip to content

Commit 3e8e147

Browse files
committed
Update README
1 parent 6c1662a commit 3e8e147

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

README.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
If all code is glued together, our glue is the safest on the market.
1818

19-
## FFI-safe trait generation, helper structures, and more!
19+
## The most complete dynamic trait object implementation, period.
2020

2121
<!-- toc -->
2222
- [Overview](#overview)
@@ -41,31 +41,35 @@ If all code is glued together, our glue is the safest on the market.
4141

4242
## Overview
4343

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!
4647

4748
```rust
4849
use cglue::*;
4950

5051
// One annotation for the trait.
5152
#[cglue_trait]
5253
pub trait InfoPrinter {
53-
fn print_info(&self);
54+
type Mark;
55+
fn print_info(&self, mark: Self::Mark);
5456
}
5557

5658
struct Info {
5759
value: usize
5860
}
5961

6062
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);
6367
}
6468
}
6569

66-
fn use_info_printer(printer: &impl InfoPrinter) {
70+
fn use_info_printer<T: InfoPrinter>(printer: &T, mark: T::Mark) {
6771
println!("Printing info:");
68-
printer.print_info();
72+
printer.print_info(mark);
6973
}
7074

7175
fn main() -> () {
@@ -76,7 +80,7 @@ fn main() -> () {
7680
// Here, the object is fully opaque, and is FFI and ABI safe.
7781
let obj = trait_obj!(&mut info as InfoPrinter);
7882

79-
use_info_printer(&obj);
83+
use_info_printer(&obj, 42);
8084
}
8185
```
8286

@@ -331,7 +335,8 @@ impl<
331335
> GenGroupVtableFiller<'cglue_a, CGlueInst, CGlueCtx, T> for GA<T>
332336
where
333337
Self: TA,
334-
&'cglue_a TAVtbl<'cglue_a, GenGroupContainer<CGlueInst, CGlueCtx, T>>:
338+
&'cglue_a TAVtbl<'cglue_a, GenGroupContainer<CGlueInst, CGlueCtx, T>,
339+
>:
335340
'cglue_a + Default,
336341
T: cglue::trait_group::GenericTypeBounds,
337342
{
@@ -739,5 +744,3 @@ If you want your project to be added to the list, please open an issue report :)
739744

740745
It is available in [CHANGELOG.md](https://github.com/h33p/cglue/blob/main/CHANGELOG.md) file.
741746

742-
743-
License: MIT

cglue/src/lib.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
//!
1717
//! If all code is glued together, our glue is the safest on the market.
1818
//!
19-
//! ## FFI-safe trait generation, helper structures, and more!
19+
//! ## The most complete dynamic trait object implementation, period.
2020
//!
2121
//! <!-- toc -->
2222
//! - [Overview](#overview)
@@ -41,31 +41,35 @@
4141
//!
4242
//! ## Overview
4343
//!
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!
4647
//!
4748
//! ```rust
4849
//! use cglue::*;
4950
//!
5051
//! // One annotation for the trait.
5152
//! #[cglue_trait]
5253
//! pub trait InfoPrinter {
53-
//! fn print_info(&self);
54+
//! type Mark;
55+
//! fn print_info(&self, mark: Self::Mark);
5456
//! }
5557
//!
5658
//! struct Info {
5759
//! value: usize
5860
//! }
5961
//!
6062
//! 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);
6367
//! }
6468
//! }
6569
//!
66-
//! fn use_info_printer(printer: &impl InfoPrinter) {
70+
//! fn use_info_printer<T: InfoPrinter>(printer: &T, mark: T::Mark) {
6771
//! println!("Printing info:");
68-
//! printer.print_info();
72+
//! printer.print_info(mark);
6973
//! }
7074
//!
7175
//! fn main() -> () {
@@ -76,7 +80,7 @@
7680
//! // Here, the object is fully opaque, and is FFI and ABI safe.
7781
//! let obj = trait_obj!(&mut info as InfoPrinter);
7882
//!
79-
//! use_info_printer(&obj);
83+
//! use_info_printer(&obj, 42);
8084
//! }
8185
//! ```
8286
//!

0 commit comments

Comments
 (0)