ring-lang-codegen
Proc macros to generate Ring extensions using Rust - zero configuration needed.
Usage
Add to your Cargo.toml:
[]
= ["cdylib"]
[]
= "0.1"
= "0.1"
Then use ring_extension!:
use ring_extension;
use *;
ring_extension!
That's it! No .rf file needed. Everything is auto-generated including ring_libinit!.
What Gets Generated
| Source | Generated Ring Functions |
|---|---|
pub fn add(a, b) |
mylib_add(a, b) |
pub struct Counter |
mylib_counter_new(), mylib_counter_delete(ptr) |
pub value: i64 field |
mylib_counter_get_value(ptr), mylib_counter_set_value(ptr, v) |
impl Counter { pub fn new() } |
Replaces default _new with custom constructor |
pub fn increment(&mut self) |
mylib_counter_increment(ptr) |
Example: Hash Library
See examples/hash-demo/ for a complete example wrapping base64, sha2, md5 crates:
ring_extension!
Ring usage:
loadlib("libring_hash.so")
? hash_sha256("hello") # Standalone function
? hash_base64_encode("hello")
h = hash_hasher_new("sha256") # Struct with custom constructor
? hash_hasher_hash(h, "hello")
hash_hasher_delete(h)
Examples
| Example | Crate | Description |
|---|---|---|
examples/hash-demo/ |
base64, sha2, md5, hex | Hashing and encoding functions |
examples/json-demo/ |
serde_json | JSON parsing, querying, modification |
examples/uuid-demo/ |
uuid | UUID v4/v7 generation, parsing, validation |
examples/datetime-demo/ |
chrono | Date/time operations, parsing, formatting |
examples/regex-demo/ |
regex | Pattern matching, replacement, extraction |
Comparison
| Feature | parsec.ring | ring_extension! |
|---|---|---|
| Configuration | Manual .rf file |
None - just annotate code |
| Sync with source | Manual | Automatic |
ring_libinit! |
Manual | Auto-generated |
| Type checking | String parsing | Full Rust types |
| IDE support | None | Full autocomplete |
| Build step | Run codegen script | Just cargo build |