ontodev / valve.rs

A lightweight validation engine written in rust.
BSD 3-Clause "New" or "Revised" License
4 stars 0 forks source link

Draft of new API for discussion #68

Closed jamesaoverton closed 10 months ago

jamesaoverton commented 10 months ago

Here is a draft API for discussion. I think it is fairly idiomatic Rust, and would be easy to use in Nanobot.

The code does not compile, but short of that I tried to include as much information as possible. Although I created a separate api.rs file, I would expect this code to be part of lib.rs.

Some points for discussion:

  1. In most languages I avoid "Object Oriented" APIs, but I think what I'm proposing is idiomatic for Rust. The alternative is passing a config struct as the first argument for the functions I'm defining.
  2. VALVE is fundamentally about mutating the database, but I think that the Valve struct that I'm proposing could usually be created as immutable, because the configuration data does not change. The main exception is the connect() method. The Rust Book talks about the interior mutability pattern which could be used in this case, I guess. Or build() could take two arguments: table table path and database connection string.
  3. If the struct is immutable, then I would make the configuration fields public, for reading.
  4. The error types I sketched are probably not complete.
lmcmicu commented 10 months ago

I have added the stubs from this PR in this commit which has been pushed to the branch new-api-forked-from-guess which is being tracked by PR #70.

This PR (#68) can now be closed unless further discussion is required.