Skip to content

Commit 1e619ee

Browse files
author
Guillermo Bescos
committed
Switch from vector to slice to allow adding traits to multiple structs
1 parent 1d385ee commit 1e619ee

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

program/rust/build.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
mod build_utils;
22
use bindgen::Builder;
33
use std::collections::HashMap;
4-
use std::vec::Vec;
54

65

76
fn main() {
87
println!("cargo:rustc-link-search=../c/target");
98

10-
let borsh_derives: Vec<String> = vec!["BorshSerialize".to_string(), "BorshDeserialize".to_string()];
9+
let borsh_derives: &[&str] = &["BorshSerialize", "BorshDeserialize"];
1110

1211
let parser = build_utils::DeriveAdderParserCallback{types_to_traits: HashMap::from([
13-
("cmd_hdr", borsh_derives)
12+
("cmd_hdr", borsh_derives), ("cmd_upd_price", borsh_derives)
1413
//map more struct names to traits here, be sure that the definitions of your traites
1514
//are included in c_oracle_header.rs
1615
])};

program/rust/build_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::collections::HashMap;
88
///is provided as a ParseCallback for bindgen
99
#[derive(Debug)]
1010
pub struct DeriveAdderParserCallback<'a>{
11-
pub types_to_traits: HashMap<&'a str, Vec<String>> ,
11+
pub types_to_traits: HashMap<&'a str, &'a[&'a str]> ,
1212
}
1313

1414
//this is required to implement the callback trait
@@ -18,7 +18,7 @@ impl ParseCallbacks for DeriveAdderParserCallback<'_>{
1818
fn add_derives(&self, _name: &str) -> Vec<String>{
1919
let traits = self.types_to_traits.get(_name);
2020
match traits{
21-
Some(trait_names)=>trait_names.to_vec(),
21+
Some(trait_names)=>trait_names.to_vec().iter().map(|s| s.to_string()).collect(),
2222
None => vec![],
2323
}
2424
}

0 commit comments

Comments
 (0)