Skip to content

Commit

Permalink
Add Rust lang support for the new 1.0 verion of the uuid crate. (#1562)
Browse files Browse the repository at this point in the history
  • Loading branch information
VegetarianOrc authored May 3, 2022
1 parent eb74b45 commit dc21165
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions docs/content/rust/reference/polar/classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,20 @@ dependency. In `Cargo.toml`, an Oso dependency that supports UUIDs looks as
follows:

```toml
oso = { version = "X.Y.Z", features = ["uuid-07"] }
oso = { version = "X.Y.Z", features = ["uuid-10"] }
```

**Note that the numbers in the feature flags do not refer to [the UUID
version][wiki] but to the version of the `uuid` crate.** Most people will want
the `uuid-07` feature flag, as it supports recent versions of the `uuid` crate.
the `uuid-10` feature flag, as it supports recent versions of the `uuid` crate.

[wiki]: https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions

| `uuid` Crate Version | Feature Flag |
|----------------------|--------------|
| `0.6.5` - `0.6.x` | `uuid-06` |
| `0.7.0` - `0.8.x` | `uuid-07` |
| `1.0.0` - `2.0.0` | `uuid-10` |

### Rust → Polar Types Summary

Expand Down
1 change: 1 addition & 0 deletions languages/rust/oso/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ rustyline-derive = { version = "0.5.0", optional = true }

uuid-06 = { package = "uuid", version = "0.6.5", optional = true }
uuid-07 = { package = "uuid", version = ">=0.7.0, <0.9.0", optional = true }
uuid-10 = { package = "uuid", version = ">=1.0.0, <2.0.0", optional = true }

[dev-dependencies]
anyhow = "1.0.44"
Expand Down
9 changes: 9 additions & 0 deletions languages/rust/oso/src/extras.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@ impl crate::PolarClass for uuid_07::Uuid {
.with_equality_check()
}
}

#[cfg(feature = "uuid-10")]
impl crate::PolarClass for uuid_10::Uuid {
fn get_polar_class_builder() -> crate::host::ClassBuilder<uuid_10::Uuid> {
crate::host::Class::builder()
.name("Uuid")
.with_equality_check()
}
}
12 changes: 12 additions & 0 deletions languages/rust/oso/tests/test_polar_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,3 +776,15 @@ fn test_uuid_07() -> Result<(), Box<dyn std::error::Error>> {
test.oso.query_rule("f", (x, y))?.next().unwrap()?;
Ok(())
}

#[cfg(feature = "uuid-10")]
#[test]
fn test_uuid_10() -> Result<(), Box<dyn std::error::Error>> {
use uuid_10::Uuid;
let mut test = OsoTest::new();
test.oso.register_class(Uuid::get_polar_class())?;
test.load_str("f(x: Uuid, y: Uuid) if x = y;");
let (x, y) = (Uuid::nil(), Uuid::nil());
test.oso.query_rule("f", (x, y))?.next().unwrap()?;
Ok(())
}

1 comment on commit dc21165

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust Benchmark

Benchmark suite Current: dc21165 Previous: eb74b45 Ratio
rust_get_attribute 45240 ns/iter (± 1934) 56141 ns/iter (± 6133) 0.81
n_plus_one/100 2221116 ns/iter (± 3116) 2540209 ns/iter (± 201816) 0.87
n_plus_one/500 10714187 ns/iter (± 105314) 13231565 ns/iter (± 870373) 0.81
n_plus_one/1000 21291231 ns/iter (± 268623) 27667984 ns/iter (± 1655230) 0.77
unify_once 973 ns/iter (± 58) 1247 ns/iter (± 133) 0.78
unify_twice 2541 ns/iter (± 55) 3218 ns/iter (± 612) 0.79
many_rules 62979 ns/iter (± 1565) 80652 ns/iter (± 9735) 0.78
fib/5 527429 ns/iter (± 8646) 630082 ns/iter (± 48400) 0.84
prime/3 17737 ns/iter (± 784) 21809 ns/iter (± 3149) 0.81
prime/23 17741 ns/iter (± 682) 21718 ns/iter (± 2185) 0.82
prime/43 17763 ns/iter (± 709) 21259 ns/iter (± 2672) 0.84
prime/83 17726 ns/iter (± 1287) 22778 ns/iter (± 2848) 0.78
prime/255 16374 ns/iter (± 592) 20842 ns/iter (± 2408) 0.79
indexed/100 6033 ns/iter (± 632) 7386 ns/iter (± 1683) 0.82
indexed/500 7796 ns/iter (± 1738) 9584 ns/iter (± 2955) 0.81
indexed/1000 9308 ns/iter (± 396) 11453 ns/iter (± 1779) 0.81
indexed/10000 25751 ns/iter (± 2306) 27900 ns/iter (± 12631) 0.92
not 5958 ns/iter (± 103) 7665 ns/iter (± 1241) 0.78
double_not 12411 ns/iter (± 278) 14217 ns/iter (± 1552) 0.87
De_Morgan_not 7952 ns/iter (± 189) 9115 ns/iter (± 819) 0.87
load_policy 892830 ns/iter (± 4416) 1178263 ns/iter (± 79243) 0.76
partial_and/1 31438 ns/iter (± 1490) 39560 ns/iter (± 10373) 0.79
partial_and/5 110480 ns/iter (± 3078) 143047 ns/iter (± 9304) 0.77
partial_and/10 210287 ns/iter (± 3994) 275382 ns/iter (± 27704) 0.76
partial_and/20 428103 ns/iter (± 5997) 528699 ns/iter (± 40472) 0.81
partial_and/40 907485 ns/iter (± 11926) 1119977 ns/iter (± 85192) 0.81
partial_and/80 2042072 ns/iter (± 3620) 2758580 ns/iter (± 182228) 0.74
partial_and/100 2704355 ns/iter (± 16473) 3429950 ns/iter (± 210561) 0.79
partial_rule_depth/1 102082 ns/iter (± 4203) 118135 ns/iter (± 10517) 0.86
partial_rule_depth/5 334119 ns/iter (± 5200) 420451 ns/iter (± 27245) 0.79
partial_rule_depth/10 729627 ns/iter (± 11527) 853491 ns/iter (± 79672) 0.85
partial_rule_depth/20 2045456 ns/iter (± 5573) 2456727 ns/iter (± 185220) 0.83
partial_rule_depth/40 7485127 ns/iter (± 58243) 9690792 ns/iter (± 741383) 0.77
partial_rule_depth/80 43211500 ns/iter (± 231067) 64874303 ns/iter (± 7202978) 0.67
partial_rule_depth/100 79528105 ns/iter (± 381463) 114232090 ns/iter (± 6398904) 0.70

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.