Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aeac23b

Browse files
committed
update value-box readme
1 parent cb19d4e commit aeac23b

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

value-box/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "value-box"
3-
version = "2.2.0"
3+
version = "2.2.1"
44
authors = ["feenk gmbh <[email protected]>"]
55
edition = "2021"
66
repository = "https://github.com/feenkcom/boxes-rs/tree/main/value-box"

value-box/README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,28 @@ pub fn library_object_create() -> *mut ValueBox<MyObject> {
2929
#[no_mangle]
3030
pub fn library_object_is_something(object: *mut ValueBox<MyObject>) -> bool {
3131
object
32-
.to_ref()
33-
.map(|object| object.is_something())
32+
// with_ref_ok() wraps the returned value into Result:Ok,
33+
// hence the name
34+
.with_ref_ok(|object| object.is_something())
3435
.unwrap_or(false)
3536
}
3637

38+
#[no_mangle]
39+
pub fn library_object_try_something(object: *mut ValueBox<MyObject>) {
40+
object
41+
// with_ref() expects the closure to return a Result
42+
.with_ref(|object| object.try_something())
43+
.log();
44+
}
45+
3746
#[no_mangle]
3847
pub fn library_object_by_ref(object: *mut ValueBox<MyObject>) {
39-
object.to_ref().map(|object| object.by_ref()).log();
48+
object.with_ref_ok(|object| object.by_ref()).log();
4049
}
4150

4251
#[no_mangle]
4352
pub fn library_object_by_mut(object: *mut ValueBox<MyObject>) {
44-
object.to_ref().map(|mut object| object.by_mut()).log();
53+
object.with_mut_ok(|mut object| object.by_mut()).log();
4554
}
4655

4756
#[no_mangle]
@@ -52,8 +61,7 @@ pub fn library_object_by_value(object: *mut ValueBox<MyObject>) {
5261
#[no_mangle]
5362
pub fn library_object_by_value_clone(object: *mut ValueBox<MyObject>) {
5463
object
55-
.to_ref()
56-
.map(|object| object.clone().by_value())
64+
.with_clone_ok(|object| object.by_value())
5765
.log();
5866
}
5967

@@ -75,5 +83,8 @@ impl MyObject {
7583
pub fn is_something(&self) -> bool {
7684
true
7785
}
86+
pub fn try_something(&self) -> Result<()> {
87+
Ok(())
88+
}
7889
}
7990
```

0 commit comments

Comments
 (0)