1 //! Fast lexical conversion routines for a no_std environment.
2 //!
3 //! lexical-core is a low-level API for number-to-string and
4 //! string-to-number conversions, without requiring a system
5 //! allocator. If you would like to use a convenient, high-level
6 //! API, please look at [lexical](https://crates.io/crates/lexical)
7 //! instead.
8 //!
9 //! # Getting Started
10 //!
11 //! ```rust
12 //! extern crate lexical_core;
13 //!
14 //! // String to number using Rust slices.
15 //! // The argument is the byte string parsed.
16 //! let f: f32 = lexical_core::parse(b"3.5").unwrap();   // 3.5
17 //! let i: i32 = lexical_core::parse(b"15").unwrap();    // 15
18 //!
19 //! // All lexical_core parsers are checked, they validate the
20 //! // input data is entirely correct, and stop parsing when invalid data
21 //! // is found, or upon numerical overflow.
22 //! let r = lexical_core::parse::<u8>(b"256"); // Err(ErrorCode::Overflow.into())
23 //! let r = lexical_core::parse::<u8>(b"1a5"); // Err(ErrorCode::InvalidDigit.into())
24 //!
25 //! // In order to extract and parse a number from a substring of the input
26 //! // data, use `parse_partial`. These functions return the parsed value and
27 //! // the number of processed digits, allowing you to extract and parse the
28 //! // number in a single pass.
29 //! let r = lexical_core::parse_partial::<i8>(b"3a5"); // Ok((3, 1))
30 //!
31 //! // If an insufficiently long buffer is passed, the serializer will panic.
32 //! // PANICS
33 //! let mut buf = [b'0'; 1];
34 //! //let slc = lexical_core::write::<i64>(15, &mut buf);
35 //!
36 //! // In order to guarantee the buffer is long enough, always ensure there
37 //! // are at least `T::FORMATTED_SIZE` bytes, which requires the
38 //! // `lexical_core::Number` trait to be in scope.
39 //! use lexical_core::Number;
40 //! let mut buf = [b'0'; f64::FORMATTED_SIZE];
41 //! let slc = lexical_core::write::<f64>(15.1, &mut buf);
42 //! assert_eq!(slc, b"15.1");
43 //!
44 //! // When the `radix` feature is enabled, for decimal floats, using
45 //! // `T::FORMATTED_SIZE` may significantly overestimate the space
46 //! // required to format the number. Therefore, the
47 //! // `T::FORMATTED_SIZE_DECIMAL` constants allow you to get a much
48 //! // tighter bound on the space required.
49 //! let mut buf = [b'0'; f64::FORMATTED_SIZE_DECIMAL];
50 //! let slc = lexical_core::write::<f64>(15.1, &mut buf);
51 //! assert_eq!(slc, b"15.1");
52 //! ```
53 //!
54 //! # Conversion API
55 //!
56 //! **To String**
57 //! - [`write`]
58 #![cfg_attr(feature = "radix", doc = " - [`write_radix`]")]
59 //!
60 //! **From String**
61 //! - [`parse`]
62 #![cfg_attr(feature = "radix", doc = " - [`parse_radix`]")]
63 #![cfg_attr(feature = "format", doc = " - [`parse_format`]")]
64 #![cfg_attr(all(feature = "format", feature = "radix"), doc = " - [`parse_format_radix`]")]
65 //! - [`parse_partial`]
66 #![cfg_attr(feature = "radix", doc = " - [`parse_partial_radix`]")]
67 #![cfg_attr(feature = "format", doc = " - [`parse_partial_format`]")]
68 #![cfg_attr(all(feature = "format", feature = "radix"), doc = " - [`parse_partial_format_radix`]")]
69 //! - [`parse_lossy`]
70 #![cfg_attr(feature = "radix", doc = " - [`parse_lossy_radix`]")]
71 #![cfg_attr(feature = "format", doc = " - [`parse_lossy_format`]")]
72 #![cfg_attr(all(feature = "format", feature = "radix"), doc = " - [`parse_lossy_format_radix`]")]
73 //! - [`parse_partial_lossy`]
74 #![cfg_attr(feature = "radix", doc = " - [`parse_partial_lossy_radix`]")]
75 #![cfg_attr(feature = "format", doc = " - [`parse_partial_lossy_format`]")]
76 #![cfg_attr(all(feature = "format", feature = "radix"), doc = " - [`parse_partial_lossy_format_radix`]")]
77 //!
78 //! # Configuration Settings
79 //!
80 //! **Get Configuration**
81 //! - [`get_exponent_default_char`]
82 #![cfg_attr(feature = "radix", doc = " - [`get_exponent_backup_char`]")]
83 #![cfg_attr(all(feature = "correct", feature = "rounding"), doc = " - [`get_float_rounding`]")]
84 //! - [`get_nan_string`]
85 //! - [`get_inf_string`]
86 //! - [`get_infinity_string`]
87 //!
88 //! **Set Configuration**
89 //! - [`set_exponent_default_char`]
90 #![cfg_attr(feature = "radix", doc = " - [`set_exponent_backup_char`]")]
91 #![cfg_attr(all(feature = "correct", feature = "rounding"), doc = " - [`set_float_rounding`]")]
92 //! - [`set_nan_string`]
93 //! - [`set_inf_string`]
94 //! - [`set_infinity_string`]
95 //!
96 //! [`write`]: fn.write.html
97 #![cfg_attr(feature = "radix", doc = " [`write_radix`]: fn.write_radix.html")]
98 //! [`parse`]: fn.parse.html
99 #![cfg_attr(feature = "radix", doc = " [`parse_radix`]: fn.parse_radix.html")]
100 #![cfg_attr(feature = "format", doc = " [`parse_format`]: fn.parse_format.html")]
101 #![cfg_attr(all(feature = "format", feature = "radix"), doc = " [`parse_format_radix`]: fn.parse_format_radix.html")]
102 //! [`parse_partial`]: fn.parse_partial.html
103 #![cfg_attr(feature = "radix", doc = " [`parse_partial_radix`]: fn.parse_partial_radix.html")]
104 #![cfg_attr(feature = "format", doc = " [`parse_partial_format`]: fn.parse_partial_format.html")]
105 #![cfg_attr(all(feature = "format", feature = "radix"), doc = " [`parse_partial_format_radix`]: fn.parse_partial_format_radix.html")]
106 //! [`parse_lossy`]: fn.parse_lossy.html
107 #![cfg_attr(feature = "radix", doc = " [`parse_lossy_radix`]: fn.parse_lossy_radix.html")]
108 #![cfg_attr(feature = "format", doc = " [`parse_lossy_format`]: fn.parse_lossy_format.html")]
109 #![cfg_attr(all(feature = "format", feature = "radix"), doc = " [`parse_lossy_format_radix`]: fn.parse_lossy_format_radix.html")]
110 //! [`parse_partial_lossy`]: fn.parse_partial_lossy.html
111 #![cfg_attr(feature = "radix", doc = " [`parse_partial_lossy_radix`]: fn.parse_partial_lossy_radix.html")]
112 #![cfg_attr(feature = "format", doc = " [`parse_partial_lossy_format`]: fn.parse_partial_lossy_format.html")]
113 #![cfg_attr(all(feature = "format", feature = "radix"), doc = " [`parse_partial_lossy_format_radix`]: fn.parse_partial_lossy_format_radix.html")]
114 //!
115 //! [`get_exponent_default_char`]: fn.get_exponent_default_char.html
116 #![cfg_attr(feature = "radix", doc = " [`get_exponent_backup_char`]: fn.get_exponent_backup_char.html")]
117 #![cfg_attr(all(feature = "correct", feature = "rounding"), doc = " [`get_float_rounding`]: fn.get_float_rounding.html")]
118 //! [`get_nan_string`]: fn.get_nan_string.html
119 //! [`get_inf_string`]: fn.get_inf_string.html
120 //! [`get_infinity_string`]: fn.get_infinity_string.html
121 //!
122 //! [`set_exponent_default_char`]: fn.set_exponent_default_char.html
123 #![cfg_attr(feature = "radix", doc = " [`set_exponent_backup_char`]: fn.set_exponent_backup_char.html")]
124 #![cfg_attr(all(feature = "correct", feature = "rounding"), doc = " [`set_float_rounding`]: fn.set_float_rounding.html")]
125 //! [`set_nan_string`]: fn.set_nan_string.html
126 //! [`set_inf_string`]: fn.set_inf_string.html
127 //! [`set_infinity_string`]: fn.set_infinity_string.html
128 
129 // silence warnings for unused doc comments
130 #![allow(unused_doc_comments)]
131 
132 // FEATURES
133 
134 // Require intrinsics in a no_std context.
135 #![cfg_attr(not(feature = "std"), no_std)]
136 #![cfg_attr(all(not(feature = "std"), not(feature = "libm")), feature(core_intrinsics))]
137 
138 // DEPENDENCIES
139 
140 #[macro_use]
141 extern crate cfg_if;
142 
143 // Use vec if there is a system allocator, which we require only if
144 // we're using the correct and radix features.
145 #[cfg(all(not(feature = "std"), feature = "correct", feature = "radix"))]
146 #[cfg_attr(test, macro_use)]
147 extern crate alloc;
148 
149 // Use arrayvec for atof.
150 #[cfg(feature = "correct")]
151 extern crate arrayvec;
152 
153 // Ensure only one back-end is enabled.
154 #[cfg(all(feature = "grisu3", feature = "ryu"))]
155 compile_error!("Lexical only accepts one of the following backends: `grisu3` or `ryu`.");
156 
157 // Import the back-end, if applicable.
158 cfg_if! {
159     if #[cfg(feature = "grisu3")] {
160         extern crate dtoa;
161     } else if #[cfg(feature = "ryu")] {
162         extern crate ryu;
163     }
164 }  // cfg_if
165 
166 /// Facade around the core features for name mangling.
167 pub(crate) mod lib {
168     #[cfg(feature = "std")]
169     pub(crate) use std::*;
170 
171     #[cfg(not(feature = "std"))]
172     pub(crate) use core::*;
173 
174     cfg_if! {
175         if #[cfg(all(feature = "correct", feature = "radix"))] {
176             #[cfg(feature = "std")]
177             pub(crate) use std::vec::Vec;
178 
179             #[cfg(not(feature = "std"))]
180             pub(crate) use ::alloc::vec::Vec;
181         }
182     }  // cfg_if
183 }   // lib
184 
185 // API
186 
187 // Hide implementation details
188 #[macro_use]
189 mod util;
190 
191 mod atof;
192 mod atoi;
193 mod float;
194 mod ftoa;
195 mod itoa;
196 
197 // Re-export configuration and utilities globally.
198 pub use util::*;
199 
200 /// Write number to string.
201 ///
202 /// Returns a subslice of the input buffer containing the written bytes,
203 /// starting from the same address in memory as the input slice.
204 ///
205 /// * `value`   - Number to serialize.
206 /// * `bytes`   - Slice containing a numeric string.
207 ///
208 /// # Panics
209 ///
210 /// Panics if the buffer may not be large enough to hold the serialized
211 /// number. In order to ensure the function will not panic, provide a
212 /// buffer with at least `{integer}::FORMATTED_SIZE_DECIMAL` elements.
213 ///
214 /// # Example
215 ///
216 /// ```
217 /// // import `Number` trait to get the `FORMATTED_SIZE_DECIMAL` of the number.
218 /// use lexical_core::Number;
219 ///
220 /// let mut buffer = [0u8; f32::FORMATTED_SIZE_DECIMAL];
221 /// let float = 3.14159265359_f32;
222 ///
223 /// lexical_core::write(float, &mut buffer);
224 ///
225 /// assert_eq!(&buffer[0..9], b"3.1415927");
226 /// ```
227 ///
228 /// This will panic, because the buffer is not large enough:
229 ///
230 /// ```should_panic
231 /// // note: the buffer is only one byte large
232 /// let mut buffer = [0u8; 1];
233 /// let float = 3.14159265359_f32;
234 ///
235 /// lexical_core::write(float, &mut buffer);
236 /// ```
237 #[inline]
write<'a, N: ToLexical>(n: N, bytes: &'a mut [u8]) -> &'a mut [u8]238 pub fn write<'a, N: ToLexical>(n: N, bytes: &'a mut [u8])
239     -> &'a mut [u8]
240 {
241     n.to_lexical(bytes)
242 }
243 
244 /// Write number to string with a custom radix.
245 ///
246 /// Returns a subslice of the input buffer containing the written bytes,
247 /// starting from the same address in memory as the input slice.
248 ///
249 /// * `value`   - Number to serialize.
250 /// * `radix`   - Radix for number encoding.
251 /// * `bytes`   - Slice containing a numeric string.
252 ///
253 /// # Panics
254 ///
255 /// Panics if the radix is not in the range `[2, 36]`.
256 ///
257 /// Also panics if the buffer may not be large enough to hold the
258 /// serialized number. In order to ensure the function will not panic,
259 /// provide a buffer with at least [`FORMATTED_SIZE`] elements.
260 ///
261 /// [`FORMATTED_SIZE`]: trait.Number.html#associatedconstant.FORMATTED_SIZE
262 #[inline]
263 #[cfg(feature = "radix")]
write_radix<'a, N: ToLexical>(n: N, radix: u8, bytes: &'a mut [u8]) -> &'a mut [u8]264 pub fn write_radix<'a, N: ToLexical>(n: N, radix: u8, bytes: &'a mut [u8])
265     -> &'a mut [u8]
266 {
267     n.to_lexical_radix(radix, bytes)
268 }
269 
270 /// Parse number from string.
271 ///
272 /// This method parses the entire string, returning an error if
273 /// any invalid digits are found during parsing.
274 ///
275 /// * `bytes`   - Byte slice containing a numeric string.
276 #[inline]
parse<N: FromLexical>(bytes: &[u8]) -> Result<N>277 pub fn parse<N: FromLexical>(bytes: &[u8])
278     -> Result<N>
279 {
280     N::from_lexical(bytes)
281 }
282 
283 /// Parse number from string.
284 ///
285 /// This method parses until an invalid digit is found (or the end
286 /// of the string), returning the number of processed digits
287 /// and the parsed value until that point.
288 ///
289 /// * `bytes`   - Byte slice containing a numeric string.
290 #[inline]
parse_partial<N: FromLexical>(bytes: &[u8]) -> Result<(N, usize)>291 pub fn parse_partial<N: FromLexical>(bytes: &[u8])
292     -> Result<(N, usize)>
293 {
294     N::from_lexical_partial(bytes)
295 }
296 
297 /// Lossily parse number from string.
298 ///
299 /// This method parses the entire string, returning an error if
300 /// any invalid digits are found during parsing. This parser is
301 /// lossy, so numerical rounding may occur during parsing.
302 ///
303 /// * `bytes`   - Byte slice containing a numeric string.
304 #[inline]
parse_lossy<N: FromLexicalLossy>(bytes: &[u8]) -> Result<N>305 pub fn parse_lossy<N: FromLexicalLossy>(bytes: &[u8])
306     -> Result<N>
307 {
308     N::from_lexical_lossy(bytes)
309 }
310 
311 /// Lossily parse number from string.
312 ///
313 /// This method parses until an invalid digit is found (or the end
314 /// of the string), returning the number of processed digits
315 /// and the parsed value until that point. This parser is
316 /// lossy, so numerical rounding may occur during parsing.
317 ///
318 /// * `bytes`   - Byte slice containing a numeric string.
319 #[inline]
parse_partial_lossy<N: FromLexicalLossy>(bytes: &[u8]) -> Result<(N, usize)>320 pub fn parse_partial_lossy<N: FromLexicalLossy>(bytes: &[u8])
321     -> Result<(N, usize)>
322 {
323     N::from_lexical_partial_lossy(bytes)
324 }
325 
326 /// Parse number from string with a custom radix.
327 ///
328 /// This method parses the entire string, returning an error if
329 /// any invalid digits are found during parsing.
330 ///
331 /// * `radix`   - Radix for number decoding.
332 /// * `bytes`   - Byte slice containing a numeric string.
333 ///
334 /// # Panics
335 ///
336 /// Panics if the radix is not in the range `[2, 36]`.
337 #[inline]
338 #[cfg(feature = "radix")]
parse_radix<N: FromLexical>(bytes: &[u8], radix: u8) -> Result<N>339 pub fn parse_radix<N: FromLexical>(bytes: &[u8], radix: u8)
340     -> Result<N>
341 {
342     N::from_lexical_radix(bytes, radix)
343 }
344 
345 /// Parse number from string with a custom radix.
346 ///
347 /// This method parses until an invalid digit is found (or the end
348 /// of the string), returning the number of processed digits
349 /// and the parsed value until that point.
350 ///
351 /// * `radix`   - Radix for number decoding.
352 /// * `bytes`   - Byte slice containing a numeric string.
353 ///
354 /// # Panics
355 ///
356 /// Panics if the radix is not in the range `[2, 36]`.
357 #[inline]
358 #[cfg(feature = "radix")]
parse_partial_radix<N: FromLexical>(bytes: &[u8], radix: u8) -> Result<(N, usize)>359 pub fn parse_partial_radix<N: FromLexical>(bytes: &[u8], radix: u8)
360     -> Result<(N, usize)>
361 {
362     N::from_lexical_partial_radix(bytes, radix)
363 }
364 
365 /// Lossily parse number from string with a custom radix.
366 ///
367 /// This method parses the entire string, returning an error if
368 /// any invalid digits are found during parsing. This parser is
369 /// lossy, so numerical rounding may occur during parsing.
370 ///
371 /// * `radix`   - Radix for number decoding.
372 /// * `bytes`   - Byte slice containing a numeric string.
373 ///
374 /// # Panics
375 ///
376 /// Panics if the radix is not in the range `[2, 36]`.
377 #[inline]
378 #[cfg(feature = "radix")]
parse_lossy_radix<N: FromLexicalLossy>(bytes: &[u8], radix: u8) -> Result<N>379 pub fn parse_lossy_radix<N: FromLexicalLossy>(bytes: &[u8], radix: u8)
380     -> Result<N>
381 {
382     N::from_lexical_lossy_radix(bytes, radix)
383 }
384 
385 /// Lossily parse number from string with a custom radix.
386 ///
387 /// This method parses until an invalid digit is found (or the end
388 /// of the string), returning the number of processed digits
389 /// and the parsed value until that point. This parser is
390 /// lossy, so numerical rounding may occur during parsing.
391 ///
392 /// * `bytes`   - Byte slice containing a numeric string.
393 /// * `radix`   - Radix for number decoding.
394 ///
395 /// # Panics
396 ///
397 /// Panics if the radix is not in the range `[2, 36]`.
398 #[inline]
399 #[cfg(feature = "radix")]
parse_partial_lossy_radix<N: FromLexicalLossy>(bytes: &[u8], radix: u8) -> Result<(N, usize)>400 pub fn parse_partial_lossy_radix<N: FromLexicalLossy>(bytes: &[u8], radix: u8)
401     -> Result<(N, usize)>
402 {
403     N::from_lexical_partial_lossy_radix(bytes, radix)
404 }
405 
406 /// Parse number from string with a custom numerical format.
407 ///
408 /// This method parses the entire string, returning an error if
409 /// any invalid digits are found during parsing. The numerical format
410 /// is specified by the format bitflags, which customize the required
411 /// components, digit separators, and other parameters of the number.
412 ///
413 /// * `bytes`   - Byte slice containing a numeric string.
414 /// * `format`  - Numerical format.
415 #[inline]
416 #[cfg(feature = "format")]
parse_format<N: FromLexicalFormat>(bytes: &[u8], format: NumberFormat) -> Result<N>417 pub fn parse_format<N: FromLexicalFormat>(bytes: &[u8], format: NumberFormat)
418     -> Result<N>
419 {
420     N::from_lexical_format(bytes, format)
421 }
422 
423 /// Parse number from string with a custom numerical format.
424 ///
425 /// This method parses until an invalid digit is found (or the end
426 /// of the string), returning the number of processed digits
427 /// and the parsed value until that point. The numerical format
428 /// is specified by the format bitflags, which customize the required
429 /// components, digit separators, and other parameters of the number.
430 ///
431 /// * `bytes`   - Byte slice containing a numeric string.
432 /// * `format`  - Numerical format.
433 #[inline]
434 #[cfg(feature = "format")]
parse_partial_format<N: FromLexicalFormat>(bytes: &[u8], format: NumberFormat) -> Result<(N, usize)>435 pub fn parse_partial_format<N: FromLexicalFormat>(bytes: &[u8], format: NumberFormat)
436     -> Result<(N, usize)>
437 {
438     N::from_lexical_partial_format(bytes, format)
439 }
440 
441 /// Lossily parse number from string with a custom numerical format.
442 ///
443 /// This method parses the entire string, returning an error if
444 /// any invalid digits are found during parsing. This parser is
445 /// lossy, so numerical rounding may occur during parsing. The
446 /// numerical format is specified by the format bitflags, which
447 /// customize the required components, digit separators, and other
448 /// parameters of the number.
449 ///
450 /// * `bytes`   - Byte slice containing a numeric string.
451 /// * `format`  - Numerical format.
452 #[inline]
453 #[cfg(feature = "format")]
parse_lossy_format<N: FromLexicalLossyFormat>(bytes: &[u8], format: NumberFormat) -> Result<N>454 pub fn parse_lossy_format<N: FromLexicalLossyFormat>(bytes: &[u8], format: NumberFormat)
455     -> Result<N>
456 {
457     N::from_lexical_lossy_format(bytes, format)
458 }
459 
460 /// Lossily parse number from string with a custom numerical format.
461 ///
462 /// This method parses until an invalid digit is found (or the end
463 /// of the string), returning the number of processed digits
464 /// and the parsed value until that point. This parser is
465 /// lossy, so numerical rounding may occur during parsing. The
466 /// numerical format is specified by the format bitflags, which
467 /// customize the required components, digit separators, and other
468 /// parameters of the number.
469 ///
470 /// * `bytes`   - Byte slice containing a numeric string.
471 /// * `format`  - Numerical format.
472 #[inline]
473 #[cfg(feature = "format")]
parse_partial_lossy_format<N: FromLexicalLossyFormat>(bytes: &[u8], format: NumberFormat) -> Result<(N, usize)>474 pub fn parse_partial_lossy_format<N: FromLexicalLossyFormat>(bytes: &[u8], format: NumberFormat)
475     -> Result<(N, usize)>
476 {
477     N::from_lexical_partial_lossy_format(bytes, format)
478 }
479 
480 /// Parse number from string with a custom radix and numerical format.
481 ///
482 /// This method parses the entire string, returning an error if
483 /// any invalid digits are found during parsing. The numerical format
484 /// is specified by the format bitflags, which customize the required
485 /// components, digit separators, and other parameters of the number.
486 ///
487 /// * `bytes`   - Byte slice containing a numeric string.
488 /// * `radix`   - Radix for number decoding.
489 /// * `format`  - Numerical format.
490 ///
491 /// # Panics
492 ///
493 /// Panics if the radix is not in the range `[2, 36]`.
494 #[inline]
495 #[cfg(all(feature = "radix", feature = "format"))]
parse_format_radix<N: FromLexicalFormat>(bytes: &[u8], radix: u8, format: NumberFormat) -> Result<N>496 pub fn parse_format_radix<N: FromLexicalFormat>(bytes: &[u8], radix: u8, format: NumberFormat)
497     -> Result<N>
498 {
499     N::from_lexical_format_radix(bytes, radix, format)
500 }
501 
502 /// Parse number from string with a custom radix and numerical format.
503 ///
504 /// This method parses until an invalid digit is found (or the end
505 /// of the string), returning the number of processed digits
506 /// and the parsed value until that point. The numerical format
507 /// is specified by the format bitflags, which customize the required
508 /// components, digit separators, and other parameters of the number.
509 ///
510 /// * `bytes`   - Byte slice containing a numeric string.
511 /// * `radix`   - Radix for number decoding.
512 /// * `format`  - Numerical format.
513 ///
514 /// # Panics
515 ///
516 /// Panics if the radix is not in the range `[2, 36]`.
517 #[inline]
518 #[cfg(all(feature = "radix", feature = "format"))]
parse_partial_format_radix<N: FromLexicalFormat>(bytes: &[u8], radix: u8, format: NumberFormat) -> Result<(N, usize)>519 pub fn parse_partial_format_radix<N: FromLexicalFormat>(bytes: &[u8], radix: u8, format: NumberFormat)
520     -> Result<(N, usize)>
521 {
522     N::from_lexical_partial_format_radix(bytes, radix, format)
523 }
524 
525 /// Lossily parse number from string with a custom radix and numerical format.
526 ///
527 /// This method parses the entire string, returning an error if
528 /// any invalid digits are found during parsing. This parser is
529 /// lossy, so numerical rounding may occur during parsing. The
530 /// numerical format is specified by the format bitflags, which
531 /// customize the required components, digit separators, and other
532 /// parameters of the number.
533 ///
534 /// * `bytes`   - Byte slice containing a numeric string.
535 /// * `radix`   - Radix for number decoding.
536 /// * `format`  - Numerical format.
537 ///
538 /// # Panics
539 ///
540 /// Panics if the radix is not in the range `[2, 36]`.
541 #[inline]
542 #[cfg(all(feature = "radix", feature = "format"))]
parse_lossy_format_radix<N: FromLexicalLossyFormat>(bytes: &[u8], radix: u8, format: NumberFormat) -> Result<N>543 pub fn parse_lossy_format_radix<N: FromLexicalLossyFormat>(bytes: &[u8], radix: u8, format: NumberFormat)
544     -> Result<N>
545 {
546     N::from_lexical_lossy_format_radix(bytes, radix, format)
547 }
548 
549 /// Lossily parse number from string with a custom radix and numerical format.
550 ///
551 /// This method parses until an invalid digit is found (or the end
552 /// of the string), returning the number of processed digits
553 /// and the parsed value until that point. This parser is
554 /// lossy, so numerical rounding may occur during parsing. The
555 /// numerical format is specified by the format bitflags, which
556 /// customize the required components, digit separators, and other
557 /// parameters of the number.
558 ///
559 /// * `bytes`   - Byte slice containing a numeric string.
560 /// * `radix`   - Radix for number decoding.
561 /// * `format`  - Numerical format.
562 ///
563 /// # Panics
564 ///
565 /// Panics if the radix is not in the range `[2, 36]`.
566 #[inline]
567 #[cfg(all(feature = "radix", feature = "format"))]
parse_partial_lossy_format_radix<N: FromLexicalLossyFormat>(bytes: &[u8], radix: u8, format: NumberFormat) -> Result<(N, usize)>568 pub fn parse_partial_lossy_format_radix<N: FromLexicalLossyFormat>(bytes: &[u8], radix: u8, format: NumberFormat)
569     -> Result<(N, usize)>
570 {
571     N::from_lexical_partial_lossy_format_radix(bytes, radix, format)
572 }
573