File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11[package ]
22name = " value-box"
3- version = " 2.2.0 "
3+ version = " 2.2.1 "
44authors = [
" feenk gmbh <[email protected] >" ]
55edition = " 2021"
66repository = " https://github.com/feenkcom/boxes-rs/tree/main/value-box"
Original file line number Diff line number Diff line change @@ -29,19 +29,28 @@ pub fn library_object_create() -> *mut ValueBox<MyObject> {
2929#[no_mangle]
3030pub 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]
3847pub 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]
4352pub 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]
5362pub 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```
You can’t perform that action at this time.
0 commit comments