Skip to content

Commit

Permalink
Ditch id generator
Browse files Browse the repository at this point in the history
  • Loading branch information
CreepySkeleton committed Dec 29, 2019
1 parent 2d3e10f commit f419c5c
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions structopt-derive/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,17 +312,15 @@ impl Attrs {
https://docs.rs/structopt/0.3.5/structopt/#magical-methods")
};

let static_name = format_ident!("__STRUCTOPT_DEFAULT_VALUE_{}", fresh_id());

quote_spanned!(ident.span()=> {
::structopt::lazy_static::lazy_static! {
static ref #static_name: &'static str = {
static ref DEFAULT_VALUE: &'static str = {
let val = <#ty as ::std::default::Default>::default();
let s = ::std::string::ToString::to_string(&val);
::std::boxed::Box::leak(s.into_boxed_str())
};
}
*#static_name
*DEFAULT_VALUE
})
};

Expand Down Expand Up @@ -642,20 +640,6 @@ impl Attrs {
}
}

fn fresh_id() -> usize {
use std::cell::Cell;

thread_local! {
static NEXT_ID: Cell<usize> = Cell::new(0);
}

NEXT_ID.with(|next_id| {
let id = next_id.get();
next_id.set(id + 1);
id
})
}

/// replace all `:` with `, ` when not inside the `<>`
///
/// `"author1:author2:author3" => "author1, author2, author3"`
Expand Down

0 comments on commit f419c5c

Please sign in to comment.