Skip to content

Commit

Permalink
Regenerate README and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
ogoffart committed Sep 14, 2019
1 parent 58bae95 commit ca32aa4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "vptr"
version = "0.2.0"
version = "0.2.1"
authors = ["Olivier Goffart <ogoffart@woboq.com>"]
edition = "2018"
description = "Thin references to trait objects by embedding the virtual table pointer in the struct"
Expand All @@ -16,4 +16,4 @@ default = ["std"]
std = []

[dependencies]
vptr-macros = {path = "./macros", version = "=0.2.0"}
vptr-macros = {path = "./macros", version = "=0.2.1"}
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ This crates allows to easily opt in to thin references to trait for a type, by h
pointers to the virtual table within the object.

```rust
use vptr::vptr;
trait Shape { fn area(&self) -> f32; }
#[vptr(Shape)]
struct Rectangle { w: f32, h : f32 }
Expand All @@ -73,7 +74,7 @@ struct Circle { r: f32 }
impl Shape for Circle { fn area(&self) -> f32 { 3.14 * self.r * self.r } }

// Given an array of Shape, compute the sum of their area
fn total_area(list: &[ThinRef<dyn Shape>]) -> f32 {
fn total_area(list: &[vptr::ThinRef<dyn Shape>]) -> f32 {
list.iter().map(|x| x.area()).fold(0., |a, b| a+b)
}
```
Expand Down Expand Up @@ -134,6 +135,17 @@ impl Shape for Point { fn area(&self) -> f32 { 0. } }
let p = Point(1, 2, VPtr::new());
let pointref = ThinRef::from(&p);
assert_eq!(pointref.area(), 0.);

// The trait can be put in quote if it is too complex for a meta attribute
#[vptr("PartialEq<str>")]
#[derive(Default)]
struct MyString(String);
impl PartialEq<str> for MyString {
fn eq(&self, other: &str) -> bool { self.0 == other }
}
let mystr = MyString("Hi".to_string(), VPtr::new());
let mystring_ref = ThinRef::from(&mystr);
assert!(*mystring_ref == *"Hi");
```

## License
Expand Down
2 changes: 1 addition & 1 deletion macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "vptr-macros"
version = "0.2.0"
version = "0.2.1"
authors = ["Olivier Goffart <ogoffart@woboq.com>"]
description = "Procedural macros for the `vptr` crate"
edition = "2018"
Expand Down

0 comments on commit ca32aa4

Please sign in to comment.