Skip to content

Commit 33d20f8

Browse files
committed
logics-rs: Test fixes and README.md update
1 parent dd655ae commit 33d20f8

File tree

4 files changed

+116
-7
lines changed

4 files changed

+116
-7
lines changed

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
<a href="https://www.npmjs.com/package/logics-js">
1414
<img alt="Badge showing current npm version of logics-js" title="logics-js" src="https://img.shields.io/npm/v/logics-js?label=logics-js">
1515
</a>
16+
<a href="https://crates.io/crates/logics-rs">
17+
<img alt="Badge showing current crates.io version of logics-rs" title="logics-rs", src="https://img.shields.io/crates/v/logics-rs">
18+
</a>
1619
<br>
17-
A multi-platform, sandboxed and extendable expression language with a Python-like syntax.
20+
A sandboxed and extendable expression language with a Python-like syntax, running in Python, JavaScript and Rust* (*soon).
1821
</div>
1922

2023
## About
@@ -41,7 +44,7 @@ Since Logics is used on both the client and server side, the language was made a
4144

4245
- [logics-js](https://www.npmjs.com/package/logics-js) is a pure (vanilla) JavaScript implementation of Logics provided as npm-package.
4346
- [logics-py](https://pypi.org/project/logics-py/) is a pure Python >= 3.10 implementation of Logics provided as PyPI-package.
44-
- [logics-rs](https://crates.io/crates/logics-rs) is a new Rust implementation of Logics provided via crates.io, under development.
47+
- [logics-rs](https://crates.io/crates/logics-rs) is a new Rust implementation of Logics provided via crates.io, **under development**.
4548

4649
Both packages are stand-alone without any further dependencies. They are both under recent development and stable until a specific degree right now. They are maintained in separate version numbers, which is planned to be changed soon, when they become almost feature-complete.
4750

@@ -64,6 +67,19 @@ logics = Logics("a + 2 * 3 + b")
6467
print(logics.run({"a": 1, "b": "-Logics"})) # "7-Logics"
6568
```
6669

70+
Using Logics in Rust (currently supports only Value abstraction):
71+
```rust
72+
// cargo install logics-rs
73+
74+
use logics_rs::Value;
75+
76+
fn main() {
77+
// Currently, only the Value-object abstraction is available.
78+
let v = Value::String("7-Logics".to_string());
79+
println!("{}", v.to_string()); // "7-Logics"
80+
}
81+
```
82+
6783
## Features
6884

6985
- Secure, native, running in a sandboxed environment apart from the host language

logics-rs/Cargo.lock

Lines changed: 92 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

logics-rs/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "logics-rs"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
edition = "2024"
55
description = "Logics is a user-friendly formula language with a subset of Python's expression syntax"
66
authors = [
@@ -16,3 +16,4 @@ categories = [
1616
readme = "../README.md"
1717

1818
[dependencies]
19+
num-parse = "0.1"

logics-rs/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::collections::HashMap;
2+
use num_parse::parse_int;
23

34
#[derive(Debug)]
4-
enum Value {
5+
pub enum Value {
56
None,
67
Bool(bool),
78
Int(i64),
@@ -37,7 +38,7 @@ impl Value {
3738
Self::Int(i) => *i,
3839
Self::Float(f) => *f as i64,
3940
Self::String(s) => {
40-
if let Ok(i) = s.parse::<i64>() {
41+
if let Some(i) = parse_int::<i64>(s) {
4142
i
4243
} else {
4344
0
@@ -224,5 +225,5 @@ fn test_string() {
224225
assert_eq!(s.to_i64(), 3i64);
225226
assert_eq!(s.to_f64(), 3.1415f64);
226227
assert_eq!(s.to_string(), "3.1415");
227-
assert_eq!(s.repr(), "3.1415");
228+
assert_eq!(s.repr(), "\"3.1415\"");
228229
}

0 commit comments

Comments
 (0)