Skip to content

Commit

Permalink
refactor: fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
olichwiruk committed Jan 10, 2025
1 parent 50c5dfb commit c85d87e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 32 deletions.
22 changes: 8 additions & 14 deletions oca/src/facade/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ impl Facade {
let mut input: Vec<u8> = vec![];
match &step.parent_said {
Some(said) => {
input.push(said.to_string().as_bytes().len().try_into().unwrap());
input.push(said.to_string().len().try_into().unwrap());
input.extend(said.to_string().as_bytes());
}
None => {
Expand Down Expand Up @@ -358,7 +358,7 @@ impl Facade {
let mut input: Vec<u8> = vec![];
match &capture_base_model.parent {
Some(said) => {
input.push(said.to_string().as_bytes().len().try_into().unwrap());
input.push(said.to_string().len().try_into().unwrap());
input.extend(said.to_string().as_bytes());
}
None => {
Expand All @@ -369,9 +369,7 @@ impl Facade {
input.push(
capture_base_model
.command_digest
.to_string()
.as_bytes()
.len()
.to_string().len()
.try_into()
.unwrap(),
);
Expand All @@ -390,7 +388,7 @@ impl Facade {
let mut input: Vec<u8> = vec![];
match &overlay_model.parent {
Some(said) => {
input.push(said.to_string().as_bytes().len().try_into().unwrap());
input.push(said.to_string().len().try_into().unwrap());
input.extend(said.to_string().as_bytes());
}
None => {
Expand All @@ -401,9 +399,7 @@ impl Facade {
input.push(
overlay_model
.command_digest
.to_string()
.as_bytes()
.len()
.to_string().len()
.try_into()
.unwrap(),
);
Expand All @@ -422,7 +418,7 @@ impl Facade {
let mut input: Vec<u8> = vec![];
match &oca_bundle_model.parent {
Some(said) => {
input.push(said.to_string().as_bytes().len().try_into().unwrap());
input.push(said.to_string().len().try_into().unwrap());
input.extend(said.to_string().as_bytes());
}
None => {
Expand All @@ -433,16 +429,14 @@ impl Facade {
input.push(
oca_bundle_model
.capture_base_said
.to_string()
.as_bytes()
.len()
.to_string().len()
.try_into()
.unwrap(),
);
input.extend(oca_bundle_model.capture_base_said.to_string().as_bytes());

for said in &oca_bundle_model.overlays_said {
input.push(said.to_string().as_bytes().len().try_into().unwrap());
input.push(said.to_string().len().try_into().unwrap());
input.extend(said.to_string().as_bytes());
}

Expand Down
4 changes: 2 additions & 2 deletions semantics/oca-bundle/src/state/oca.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,9 +716,9 @@ impl From<OCABundle> for OCABox {
.iter()
.filter_map(|x| x.as_any().downcast_ref::<overlay::Conditional>())
.collect::<Vec<_>>();
for overlay in conditional_overlays {
let re = regex::Regex::new(r"\$\{(\d+)\}").unwrap();

let re = regex::Regex::new(r"\$\{(\d+)\}").unwrap();
for overlay in conditional_overlays {
for (attr_name, condition) in overlay.attribute_conditions.iter() {
let condition_dependencies = overlay.attribute_dependencies.get(attr_name).unwrap(); // todo
let cond = re
Expand Down
20 changes: 8 additions & 12 deletions semantics/oca-bundle/src/state/oca/overlay/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,32 +237,28 @@ mod tests {

assert!(overlay
.category_labels
.get(&"_cat-1_".to_string())
.is_some());
if let Some(cat1) = overlay.category_labels.get(&"_cat-1_".to_string()) {
.contains_key("_cat-1_"));
if let Some(cat1) = overlay.category_labels.get("_cat-1_") {
assert_eq!(*cat1, "Cat 1".to_string());
}
assert!(overlay
.category_labels
.get(&"_cat-2_".to_string())
.is_some());
if let Some(cat2) = overlay.category_labels.get(&"_cat-2_".to_string()) {
.contains_key("_cat-2_"));
if let Some(cat2) = overlay.category_labels.get("_cat-2_") {
assert_eq!(*cat2, "Cat 2".to_string());
}

assert!(overlay
._category_attributes
.get(&"_cat-1_".to_string())
.is_some());
if let Some(cat1_attrs) = overlay._category_attributes.get(&"_cat-1_".to_string()) {
.contains_key("_cat-1_"));
if let Some(cat1_attrs) = overlay._category_attributes.get("_cat-1_") {
assert_eq!(cat1_attrs.len(), 1);
assert!(cat1_attrs.contains(&"attr1".to_string()));
}
assert!(overlay
._category_attributes
.get(&"_cat-2_".to_string())
.is_some());
if let Some(cat2_attrs) = overlay._category_attributes.get(&"_cat-2_".to_string()) {
.contains_key("_cat-2_"));
if let Some(cat2_attrs) = overlay._category_attributes.get("_cat-2_") {
assert_eq!(cat2_attrs.len(), 1);
assert!(cat2_attrs.contains(&"attr2".to_string()));
}
Expand Down
4 changes: 2 additions & 2 deletions semantics/oca-dag/src/versioning/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ impl From<OCABundleDTO> for Vec<u8> {
fn from(val: OCABundleDTO) -> Self {
let mut digests: Vec<u8> = Vec::new();
if let Some(ref said) = val.bundle.capture_base.said {
digests.push(said.to_string().as_bytes().len().try_into().unwrap());
digests.push(said.to_string().len().try_into().unwrap());
digests.extend(said.to_string().as_bytes());
}

val.bundle.overlays.iter().for_each(|overlay| {
if let Some(ref said) = overlay.said() {
digests.push(said.to_string().as_bytes().len().try_into().unwrap());
digests.push(said.to_string().len().try_into().unwrap());
// digests.push(overlay.overlay_type().into());
digests.extend(said.to_string().as_bytes());
}
Expand Down
4 changes: 2 additions & 2 deletions semantics/oca-dag/src/versioning/ocafile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ pub fn build_oca(
match base {
Some(ref mut base) => {
let base_said = base.generate_bundle().said.unwrap().to_string();
input.push(base_said.as_bytes().len().try_into().unwrap());
input.push(base_said.len().try_into().unwrap());
input.extend(base_said.as_bytes());
}
None => {
input.push(0);
}
}
input.push(command_str.as_bytes().len().try_into().unwrap());
input.push(command_str.len().try_into().unwrap());
input.extend(command_str.as_bytes());
db.insert(
&format!("oca.{}.operation", oca_bundle.clone().said.unwrap()),
Expand Down

0 comments on commit c85d87e

Please sign in to comment.