Ji-Xinyou opened a new pull request, #2329:
URL: https://github.com/apache/incubator-opendal/pull/2329

   Introduce initializing opendal_operator by key-value pairs
   
   # Some explainations
   
   For map construction, I came up with essentially three ideas.
   
   1. Use a `opendal_map` struct, which is essentially a pointer to Rust 
Hashmap. I did **not** use this because this introduce complexity just like we 
construct a `opendal_operator_ptr`, users have to free the heap memory used 
only once.
   ```Rust
   opendal_map m = opendal_map_new(kvs: opendal_kvs);
   opendal_operator_ptr ptr = opendal_operator_from_map(scheme, m);
   
   /* I don't want this since this is not necessary, we are not using this 
anymore */
   opendal_map_free(m);
   
   opendal_operator_ptr_free(ptr);
   ```
   
   
   2. Use a series of keys and values in the `opendal_operator_ptr_from_kvs()`, 
 this api would be like
   ```Rust
   fn opendal_operator_ptr_from_kvs(scheme: *const c_char, keys: *const c_char, 
values: *const c_char) -> ....
   ```
   The pro of this is that we do not need to introduce any new foreign data 
structures into Rust (like we actually do in this PR for `opendal_kv`).
   The con of this is that users have we make sure that the ordering and number 
of the provided keys and values are correct, making this API really bad.
   
   
   3. The approach used in this PR. We introduce a new data structure called 
`opendal_kv`, which is essentially a simple key-value pair. This helps us to 
easier align the keys and values provided by user, and provide a more friendly 
interfaces.
   ```Rust
   opendal_kv kvs[3];
   kvs[0] = opendal_kv {.key = "k1", .value = "v1"};
   kvs[1] = opendal_kv {.key = "k2", .value = "v2"};
   kvs[2] = opendal_kv {.key = "k3", .value = "v3"};
   
   opendal_operator_ptr ptr = opendal_operator_ptr_from_kvs("memory", kvs, 3);
   ...
   ```
   We do not need to explicitly manage heap allocation of hashmap, manage the 
correctness of the ordering of key-values, and we can make use of this kv data 
structure in the future.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to