Skip to content

Commit bab71af

Browse files
committed
update
1 parent 212f77e commit bab71af

File tree

9 files changed

+28
-49
lines changed

9 files changed

+28
-49
lines changed

num-format-windows/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ maintenance = { status = "actively-developed" }
2121
travis-ci = { repository = "bcmyers/num-format", branch = "master" }
2222

2323
[build-dependencies]
24-
cfg-if = "0.1"
2524
bindgen = "0.47"

num-format-windows/build.rs

+6-19
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
#[macro_use]
2-
extern crate cfg_if;
3-
4-
cfg_if! {
5-
if #[cfg(windows)] {
1+
#[cfg(windows)]
62
fn main() {
73
use std::env;
84
use std::path::Path;
95

106
use bindgen::{Builder, RustTarget};
117

128
let root = env::var("CARGO_MANIFEST_DIR").unwrap();
13-
let headers_path = Path::new(&root).join("win.h");
9+
let headers_path = Path::new(&root).join("wrapper.h");
1410
let headers = headers_path.to_str().unwrap();
1511

1612
let bindings = Builder::default()
@@ -30,20 +26,11 @@ fn main() {
3026
.generate()
3127
.expect("unable to generate bindings for windows.h");
3228

33-
let out_path = Path::new(&env::var("OUT_DIR").unwrap()).join("windows.rs");
29+
let out_path = Path::new(&env::var("OUT_DIR").unwrap()).join("bindings.rs");
3430
bindings
3531
.write_to_file(&out_path)
3632
.expect("unable to write bindings for windows.h");
37-
38-
let development_dir = Path::new(&root).parent().unwrap().join("tmp");
39-
if development_dir.exists() {
40-
let out_path = development_dir.join("windows.rs");
41-
bindings
42-
.write_to_file(&out_path)
43-
.expect("unable to write bindings for windows.h");
44-
}
45-
}
46-
} else {
47-
fn main() {}
48-
}
4933
}
34+
35+
#[cfg(not(windows))]
36+
fn main() {}

num-format-windows/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
#![allow(non_camel_case_types)]
44
#![allow(non_snake_case)]
55
#![allow(non_upper_case_globals)]
6-
include!(concat!(env!("OUT_DIR"), "\\windows.rs"));
6+
include!(concat!(env!("OUT_DIR"), "\\bindings.rs"));
File renamed without changes.

num-format/src/buffer.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use core::ops::Deref;
55
use core::str;
66

77
use crate::constants::MAX_BUF_LEN;
8-
use crate::{Format, ToFormattedStr};
8+
use crate::format::Format;
9+
use crate::to_formatted_str::ToFormattedStr;
910

1011
/// <b><u>A key type</u></b>. Represents a stack-allocated buffer you can use to get a
1112
/// formatted `&str` without heap allocation.
@@ -84,6 +85,20 @@ impl Buffer {
8485
pub(crate) fn as_mut_ptr(&mut self) -> *mut u8 {
8586
self.inner.as_mut_ptr()
8687
}
88+
89+
#[inline(always)]
90+
pub(crate) fn write_with_itoa<N: itoa::Integer>(&mut self, n: N) -> usize {
91+
let mut itoa_buf = itoa::Buffer::new();
92+
let s = itoa_buf.format(n);
93+
let bytes = s.as_bytes();
94+
let len = s.len();
95+
for i in 0..len {
96+
self.inner[i] = bytes[i];
97+
}
98+
self.pos = 0;
99+
self.end = len;
100+
len
101+
}
87102
}
88103

89104
impl AsRef<str> for Buffer {

num-format/src/error.rs

-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ impl Error {
9494
where
9595
S: AsRef<str>,
9696
{
97-
eprintln!("{}", msg.as_ref());
9897
unimplemented!()
9998
}
10099
}

num-format/src/impls/int.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use core::mem;
22
use core::ptr;
33

4-
use itoa;
5-
64
use crate::constants::{MAX_BUF_LEN, TABLE};
75
use crate::helpers::{self, Separator};
86
use crate::sealed::Sealed;
@@ -28,10 +26,7 @@ macro_rules! impl_signed {
2826
// Bail out early if we can just use itoa
2927
// (i.e. if we don't have a separator and a minus sign doesn't cause us problems)
3028
if sep.is_none() && ((is_negative && min == "-") || !is_negative) {
31-
let c = itoa::write(&mut buf.inner[..], *self).unwrap();
32-
buf.pos = 0;
33-
buf.end = c;
34-
return c;
29+
return buf.write_with_itoa(*self);
3530
}
3631

3732
// Reset our position to the end of the buffer

num-format/src/impls/non_zero_uint.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use core::mem;
22
use core::num::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize};
33

4-
use itoa;
5-
64
use crate::constants::{MAX_BUF_LEN, TABLE};
75
use crate::helpers::{self, Separator};
86
use crate::sealed::Sealed;
@@ -15,10 +13,7 @@ impl ToFormattedStr for NonZeroU8 {
1513
where
1614
F: Format,
1715
{
18-
let c = itoa::write(&mut buf.inner[..], self.get()).unwrap();
19-
buf.pos = 0;
20-
buf.end = c;
21-
c
16+
buf.write_with_itoa(self.get())
2217
}
2318
}
2419

@@ -40,10 +35,7 @@ macro_rules! impl_non_zero {
4035
// Bail out early if we can just use itoa
4136
// (i.e. if we don't have a separator)
4237
if sep.is_none() {
43-
let c = itoa::write(&mut buf.inner[..], self.get()).unwrap();
44-
buf.pos = 0;
45-
buf.end = c;
46-
return c;
38+
return buf.write_with_itoa(self.get());
4739
}
4840

4941
// Reset our position to the end of the buffer

num-format/src/impls/uint.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use core::mem;
22

3-
use itoa;
4-
53
use crate::constants::{MAX_BUF_LEN, TABLE};
64
use crate::helpers::{self, Separator};
75
use crate::sealed::Sealed;
@@ -14,10 +12,7 @@ impl ToFormattedStr for u8 {
1412
where
1513
F: Format,
1614
{
17-
let c = itoa::write(&mut buf.inner[..], *self).unwrap();
18-
buf.pos = 0;
19-
buf.end = c;
20-
c
15+
buf.write_with_itoa(*self)
2116
}
2217
}
2318

@@ -39,10 +34,7 @@ macro_rules! impl_unsigned {
3934
// Bail out early if we can just use itoa
4035
// (i.e. if we don't have a separator)
4136
if sep.is_none() {
42-
let c = itoa::write(&mut buf.inner[..], *self).unwrap();
43-
buf.pos = 0;
44-
buf.end = c;
45-
return c;
37+
return buf.write_with_itoa(*self);
4638
}
4739

4840
// Reset our position to the end of the buffer

0 commit comments

Comments
 (0)