Skip to content

Commit

Permalink
Merge pull request #31 from elastic-rs/feat/id-from-num
Browse files Browse the repository at this point in the history
Convert integers to Id
  • Loading branch information
KodrAus authored May 15, 2017
2 parents e7d3275 + 9b135dd commit 999472f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "elastic_requests"
version = "0.4.0"
version = "0.4.2"
authors = ["Ashley Mannix <[email protected]>"]
license = "Apache-2.0"
description = "Code generated request types for the Elasticsearch REST API."
Expand Down
3 changes: 3 additions & 0 deletions codegen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ fn params_mod(tokens: &mut Tokens, derives: Tokens, params_to_emit: BTreeMap<Str
tokens.append(uses.to_string());
tokens.append("\n\n");

tokens.append(r#"include!("genned.params.rs");"#);
tokens.append("\n\n");

let params_to_emit = params_to_emit.iter()
.filter(|&(_, is_emitted)| *is_emitted);

Expand Down
Empty file added src/genned.
Empty file.
16 changes: 16 additions & 0 deletions src/genned.params.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
macro_rules! impl_from_num_for_id {
($num:ty) => (
impl<'a> From<$num> for Id<'a> {
fn from(value: $num) -> Id<'a> {
Id::from(value.to_string())
}
}
)
}

impl_from_num_for_id!(u32);
impl_from_num_for_id!(u64);
impl_from_num_for_id!(usize);
impl_from_num_for_id!(i32);
impl_from_num_for_id!(i64);
impl_from_num_for_id!(isize);
2 changes: 2 additions & 0 deletions src/genned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5889,6 +5889,8 @@ pub mod http {
pub mod params {
use std::borrow::Cow;

include!("genned.params.rs");

# [ derive ( Debug , PartialEq , Clone ) ]
pub struct Alias<'a>(pub Cow<'a, str>);
pub fn alias<'a, I>(value: I) -> Alias<'a>
Expand Down
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,13 @@ mod tests {

do_something_with_static_request(req).join().unwrap();
}

#[test]
fn id_from_number() {
let ids = vec![Id::from(1i32), Id::from(1u32), Id::from(1i64), Id::from(1u64), Id::from(1isize), Id::from(1usize)];

for id in ids {
assert_eq!("1", &*id);
}
}
}

0 comments on commit 999472f

Please sign in to comment.