Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken doctests #35

Merged
merged 2 commits into from
Jan 14, 2025
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
11 changes: 7 additions & 4 deletions examples/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ use a_tree::{ATree, AttributeDefinition};
use std::collections::HashMap;

const FIRST_EXPRESSION: &str = r#"exchange_id = 1 and deal_ids one of ['deal-1', 'deal-2'] and segment_ids one of [1, 2, 3] and country in ['FR', 'GB']"#;
const SECOND_EXPRESSION: &str = r#"exchange_id = 1 and deal_ids one of ['deal-1', 'deal-2'] and segment_ids one of [1, 2, 3] and country = 'CA' and city in ['QC'] or country = 'US' and city in ['AZ']"#;
const THIRD_EXPRESSION: &str = r#"exchange_id = 1 and deal_ids one of ['deal-1', 'deal-2'] and segment_ids one of [1, 2, 3] and country = 'CA' and city in ['QC'] or country = 'US'"#;
const SECOND_EXPRESSION: &str = r#"(exchange_id = 1 and deal_ids one of ['deal-1', 'deal-2']) and segment_ids one of [1, 2, 3] and ((country = 'CA' and city in ['QC']) or (country = 'US' and city in ['AZ']))"#;
const THIRD_EXPRESSION: &str = r#"(exchange_id = 1 and deal_ids one of ['deal-1', 'deal-2']) and segment_ids one of [1, 2, 3] and ((country = 'CA' and city in ['QC']) or (country = 'US'))"#;
const FOURTH_EXPRESSION: &str =
r#"exchange_id = 1 and deal_ids one of ['deal-1', 'deal-2'] and segment_ids one of [1, 2, 3]"#;

fn main() {
// Create the A-Tree
Expand All @@ -21,6 +23,7 @@ fn main() {
(1, FIRST_EXPRESSION),
(2, SECOND_EXPRESSION),
(3, THIRD_EXPRESSION),
(4, FOURTH_EXPRESSION),
];
let mappings: HashMap<u64, &str> = HashMap::from_iter(expressions_by_ids);
for (id, expression) in &expressions_by_ids {
Expand All @@ -29,7 +32,7 @@ fn main() {

// Create the matching event
let mut builder = atree.make_event();
builder.with_integer("exchange_id", 5).unwrap();
builder.with_integer("exchange_id", 1).unwrap();
builder
.with_string_list("deal_ids", &["deal-3", "deal-1"])
.unwrap();
Expand All @@ -41,7 +44,7 @@ fn main() {
let event = builder.build().unwrap();

// Search inside the A-Tree for matching events
let report = atree.search(event).unwrap();
let report = atree.search(&event).unwrap();
report.matches().iter().for_each(|id| {
println!(r#"Found ID: {id}, Expression: "{}""#, mappings[id]);
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
//! let event = builder.build().unwrap();
//!
//! // Search for matching boolean expressions
//! let report = atree.search(event).unwrap();
//! let report = atree.search(&event).unwrap();
//! report.matches().iter().for_each(|id| {
//! println!(r#"Found ID: {id}, Expression: "{}""#, mappings[id]);
//! });
Expand Down