Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 52 additions & 55 deletions .github/workflows/master-push.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

# Based on https://github.com/actions-rs/meta/blob/master/recipes/msrv.md

on: [push, pull_request]

name: Build
Expand All @@ -9,95 +7,94 @@ jobs:
check:
name: Check
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
steps:
- name: Checkout sources
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
uses: dtolnay/rust-toolchain@stable

- name: Run cargo check
uses: actions-rs/cargo@v1
with:
command: check
run: cargo check

test:
name: Test Suite
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
steps:
- name: Checkout sources
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
uses: dtolnay/rust-toolchain@stable

- name: Run cargo test
uses: actions-rs/cargo@v1
with:
command: test
run: cargo test

fmt:
name: Rustfmt
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
steps:
- name: Checkout sources
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install toolchain
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
override: true

- name: Install rustfmt
run: rustup component add rustfmt
components: rustfmt

- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
run: cargo fmt --all -- --check

clippy:
name: Clippy
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
steps:
- name: Checkout sources
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install toolchain
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
override: true

- name: Install clippy
run: rustup component add clippy
components: clippy

- name: Run cargo clippy
uses: actions-rs/cargo@v1
run: cargo clippy --workspace -- -D warnings

coverage:
name: Code Coverage
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Install toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools-preview

- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov

- name: Generate code coverage
run: |
cargo llvm-cov --all-features --workspace --no-report
cargo llvm-cov report --lcov --output-path lcov.info
cargo llvm-cov report --html --output-dir coverage/

- name: Upload HTML coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage/
retention-days: 14

- name: Report coverage on PR
if: github.event_name == 'pull_request'
uses: romeovs/lcov-reporter-action@v0.4.0
with:
command: clippy
args: --workspace -- -D warnings
lcov-file: lcov.info
github-token: ${{ secrets.GITHUB_TOKEN }}
filter-changed-files: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
target
coverage
lcov.info
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libhaystack"
version = "3.1.4"
version = "3.1.5"
description = "Rust implementation of the Haystack 4 data types, defs, filter, units, and encodings"
authors = ["J2 Innovations", "Radu Racariu <radur@j2inn.com>"]
edition = "2024"
Expand Down
8 changes: 2 additions & 6 deletions src/haystack/defs/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ impl Namespace {
reflected.into_iter().collect()
}

pub fn def_of_dict(&self, subject: &Dict) -> Dict {
pub fn def_of_dict(&self, subject: &Dict) -> &Dict {
self.reflect(subject).entity_type
}

Expand Down Expand Up @@ -799,11 +799,7 @@ impl Namespace {
let mut ref_tag = ref_target.as_ref().cloned();
let mut subjects = vec![subject.clone()];

'search: loop {
let Some(mut cur_subject) = subjects.pop() else {
break;
};

'search: while let Some(mut cur_subject) = subjects.pop() {
let id = cur_subject.get_ref("id").cloned();
while let Some((subject_key, subject_val)) = cur_subject.pop_first() {
let subject_def = self.get_by_name(&subject_key);
Expand Down
18 changes: 9 additions & 9 deletions src/haystack/defs/reflection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use std::collections::BTreeMap;

use super::namespace::Namespace;
use crate::defs::namespace::EMPTY_DICT;
use crate::haystack::defs::namespace::DefDict;
use crate::haystack::val::{Dict, HaystackDict, Symbol};

Expand All @@ -17,7 +18,7 @@ pub struct Reflection<'a> {
/// The def namespace used for the reflection
pub ns: &'a Namespace,
/// The entity type of the target dictionary
pub entity_type: Dict,
pub entity_type: &'a Dict,
}

impl<'a> Reflection<'a> {
Expand All @@ -26,7 +27,7 @@ impl<'a> Reflection<'a> {
subject: subject.clone(),
defs,
ns,
entity_type: Dict::default(),
entity_type: &EMPTY_DICT,
};
reflect.compute_entity_type();
reflect
Expand All @@ -52,24 +53,23 @@ impl<'a> Reflection<'a> {
for def in &self.defs {
let inheritance = self.ns.inheritance(def.def_symbol());
if inheritance.contains(&entity) {
types_with_inheritance.insert(def, inheritance.clone());
types_with_inheritance.insert(def, inheritance);
}
}

if types_with_inheritance.len() == 1 {
// Just get the first entity if only one has been found.
types_with_inheritance
.keys()
.copied()
.next()
.map_or(Dict::default(), |def| def.clone())
.map_or(&EMPTY_DICT, |def| def)
} else {
// If multiple entity tags have been found then we need to find which tag is the most specific.
// This can happen if a record has a tag like `ahu` and `equip`. The `ahu` tag extends `equip`.
// Therefore, we need to check all the inheritance to find the first tag that isn't any of the
// other tag's inheritance. This tag should be the most specific entity.

let all_defs = types_with_inheritance.keys().copied();
let all_defs = types_with_inheritance.keys();

all_defs
.into_iter()
Expand All @@ -79,13 +79,13 @@ impl<'a> Reflection<'a> {
!types_with_inheritance
.iter()
.any(|(inner_def, inheritance)| {
inner_def != def && inheritance.contains(def)
inner_def != *def && inheritance.contains(def)
})
})
.map_or(Dict::default(), |def| def.clone())
.map_or(&EMPTY_DICT, |def| def)
}
}
None => Dict::default(),
None => &EMPTY_DICT,
}
}
}
4 changes: 2 additions & 2 deletions src/haystack/units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ pub fn match_units(dim: UnitDimensions, scale: f64) -> Vec<&'static Unit> {
#[cfg(feature = "units-db")]
{
units_generated::UNITS
.iter()
.filter_map(|(_, u)| {
.values()
.filter_map(|u| {
if u.dimensions.as_ref() == Some(&dim) && approx_eq(u.scale, scale) {
Some(*u)
} else {
Expand Down
11 changes: 8 additions & 3 deletions src/haystack/val/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ impl Symbol {
// Make a Haystack `Symbol` from a string value
impl From<&str> for Symbol {
fn from(value: &str) -> Self {
Symbol {
value: String::from(value),
}
Symbol::from(value.to_owned())
}
}

// Make a Haystack `Symbol` from a String value
impl From<String> for Symbol {
fn from(value: String) -> Self {
Symbol { value }
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/haystack/val/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ impl From<String> for Uri {
// Make a Haystack `Uri` from a string value
impl From<&str> for Uri {
fn from(value: &str) -> Self {
Uri {
value: String::from(value),
}
Uri::from(value.to_owned())
}
}

Expand Down
Loading