Stringly-Typed Rust

Build Status

A crate for updating values using a stringly-typed API.

Typical Use Case

Imagine you're working on a system that uses a lot of runtime configuration to alter the behaviour of the application. For whatever reason it isn't practical to stop the entire system just to update a single configuration key, so you need the ability to update configuration on the fly... How do you do it?

In terms of difficulty the first option is quite nice. You just wrap your config with a RWLock and all your configuration update issues go away, however you now pay the price of serializing/deserializing and network transfer. Plus it can feel awfully wasteful to copy around an entire file just to change one key.

TODO: Mention how serialize-deserialize is expensive

TODO: Mention this is essentially automating the massive switch-case statement

```rust

[macro_use]

extern crate stringlytyped; use stringlytyped::{StringlyTyped, Value};

[derive(StringlyTyped)]

struct Config { motionparameters: MotionParameters, targetbed_temp: f64, version: String, ... }

[derive(StringlyTyped)]

struct MotionParameters { maxtranslationvelocity: f64, maxverticalvelocity: f64, }

// Assume we were told which key and value to update over the network or some // other dynamic source let key = "motionparameters.maxvertical_velocity"; let value = Value::Double(40.0);

cfg.set(key, value)?; asserteq!(cfg.motionparameters.maxverticalvelocity, 40.0); ```

Features

Benchmarks

The main goal of this crate isn't performance, however it performs quite well compared to the "usual" static assignment (i.e. normal Rust with the dot operator), and still beats the serialize-update-deserialize method.

text test static_assign ... bench: 81 ns/iter (+/- 6) test stringly_update ... bench: 167 ns/iter (+/- 12) test serialize_deserialize ... bench: 1,243 ns/iter (+/- 343)

As with any benchmark, we're only comparing three contrived use cases so take these numbers with a grain of salt.