conv/lib.rs
1/*!
2This crate provides a number of conversion traits with more specific semantics than those provided by `as` or `From`/`Into`.
3
4The goal with the traits provided here is to be more specific about what generic code can rely on, as well as provide reasonably self-describing alternatives to the standard `From`/`Into` traits. For example, the although `T: From<U>` might be satisfied, it imposes no restrictions on the *kind* of conversion being implemented. As such, the traits in this crate try to be very specific about what conversions are allowed. This makes them less generally applicable, but more useful where they *do* apply.
5
6In addition, `From`/`Into` requires all conversions to succeed or panic. All conversion traits in this crate define an associated error type, allowing code to react to failed conversions as appropriate.
7
8<style type="text/css">
9.link-block { font-family: "Fira Sans"; }
10.link-block > p { display: inline-block; }
11.link-block > p > strong { font-weight: 500; margin-right: 1em; }
12.link-block > ul { display: inline-block; padding: 0; list-style: none; }
13.link-block > ul > li {
14 font-size: 0.8em;
15 background-color: #eee;
16 border: 1px solid #ccc;
17 padding: 0.3em;
18 display: inline-block;
19}
20</style>
21<span></span><div class="link-block">
22
23**Links**
24
25* [Latest Release](https://crates.io/crates/scan-rules/)
26* [Latest Docs](https://danielkeep.github.io/rust-scan-rules/doc/scan_rules/index.html)
27* [Repository](https://github.com/DanielKeep/rust-scan-rules)
28
29<span></span></div>
30
31## Compatibility
32
33`conv` is compatible with Rust 1.2 and higher.
34
35## Change Log
36
37### v0.3.2
38
39- Added integer ↔ `char` conversions.
40- Added missing `isize`/`usize` → `f32`/`f64` conversions.
41- Fixed the error type of `i64` → `usize` for 64-bit targets.
42
43### v0.3.1
44
45- Change to `unwrap_ok` for better codegen (thanks bluss).
46- Fix for Rust breaking change (code in question was dodgy anyway; thanks m4rw3r).
47
48### v0.3.0
49
50- Added an `Error` constraint to all `Err` associated types. This will break any user-defined conversions where the `Err` type does not implement `Error`.
51- Renamed the `Overflow` and `Underflow` errors to `PosOverflow` and `NegOverflow` respectively. In the context of floating point conversions, "underflow" usually means the value was too close to zero to correctly represent.
52
53### v0.2.1
54
55- Added `ConvUtil::into_as<Dst>` as a shortcut for `Into::<Dst>::into`.
56- Added `#[inline]` attributes.
57- Added `Saturate::saturate`, which can saturate `Result`s arising from over/underflow.
58
59### v0.2.0
60
61- Changed all error types to include the original input as payload. This breaks pretty much *everything*. Sorry about that. On the bright side, there's now no downside to using the conversion traits for non-`Copy` types.
62- Added the normal rounding modes for float → int approximations: `RoundToNearest`, `RoundToNegInf`, `RoundToPosInf`, and `RoundToZero`.
63- `ApproxWith` is now subsumed by a pair of extension traits (`ConvUtil` and `ConvAsUtil`), that also have shortcuts for `TryInto` and `ValueInto` so that you can specify the destination type on the method.
64
65# Overview
66
67The following traits are used to define various conversion semantics:
68
69- [`ApproxFrom`](./trait.ApproxFrom.html)/[`ApproxInto`](./trait.ApproxInto.html) - approximate conversions, with selectable approximation scheme (see [`ApproxScheme`](./trait.ApproxScheme.html)).
70- [`TryFrom`](./trait.TryFrom.html)/[`TryInto`](./trait.TryInto.html) - general, potentially failing value conversions.
71- [`ValueFrom`](./trait.ValueFrom.html)/[`ValueInto`](./trait.ValueInto.html) - exact, value-preserving conversions.
72
73When *defining* a conversion, try to implement the `*From` trait variant where possible. When *using* a conversion, try to depend on the `*Into` trait variant where possible. This is because the `*Into` traits automatically use `*From` implementations, but not the reverse. Implementing `*From` and using `*Into` ensures conversions work in as many contexts as possible.
74
75These extension methods are provided to help with some common cases:
76
77- [`ConvUtil::approx_as<Dst>`](./trait.ConvUtil.html#method.approx_as) - approximates to `Dst` with the `DefaultApprox` scheme.
78- [`ConvUtil::approx_as_by<Dst, S>`](./trait.ConvUtil.html#method.approx_as_by) - approximates to `Dst` with the scheme `S`.
79- [`ConvUtil::into_as<Dst>`](./trait.ConvUtil.html#method.into_as) - converts to `Dst` using `Into::into`.
80- [`ConvUtil::try_as<Dst>`](./trait.ConvUtil.html#method.try_as) - converts to `Dst` using `TryInto::try_into`.
81- [`ConvUtil::value_as<Dst>`](./trait.ConvUtil.html#method.value_as) - converts to `Dst` using `ValueInto::value_into`.
82- [`ConvAsUtil::approx`](./trait.ConvAsUtil.html#method.approx) - approximates to an inferred destination type with the `DefaultApprox` scheme.
83- [`ConvAsUtil::approx_by<S>`](./trait.ConvAsUtil.html#method.approx_by) - approximates to an inferred destination type with the scheme `S`.
84- [`Saturate::saturate`](./errors/trait.Saturate.html#tymethod.saturate) - saturates on overflow.
85- [`UnwrapOk::unwrap_ok`](./errors/trait.UnwrapOk.html#tymethod.unwrap_ok) - unwraps results from conversions that cannot fail.
86- [`UnwrapOrInf::unwrap_or_inf`](./errors/trait.UnwrapOrInf.html#tymethod.unwrap_or_inf) - saturates to ±∞ on failure.
87- [`UnwrapOrInvalid::unwrap_or_invalid`](./errors/trait.UnwrapOrInvalid.html#tymethod.unwrap_or_invalid) - substitutes the target type's "invalid" sentinel value on failure.
88- [`UnwrapOrSaturate::unwrap_or_saturate`](./errors/trait.UnwrapOrSaturate.html#tymethod.unwrap_or_saturate) - saturates to the maximum or minimum value of the target type on failure.
89
90A macro is provided to assist in implementing conversions:
91
92- [`TryFrom!`](./macros/index.html#tryfrom!) - derives an implementation of [`TryFrom`](./trait.TryFrom.html).
93
94If you are implementing your own types, you may also be interested in the traits contained in the [`misc`](./misc/index.html) module.
95
96## Provided Implementations
97
98The crate provides several blanket implementations:
99
100- `*From<A> for A` (all types can be converted from and into themselves).
101- `*Into<Dst> for Src where Dst: *From<Src>` (`*From` implementations imply a matching `*Into` implementation).
102
103Conversions for the builtin numeric (integer and floating point) types are provided. In general, `ValueFrom` conversions exist for all pairs except for float → integer (since such a conversion is generally unlikely to *exactly* succeed) and `f64 → f32` (for the same reason). `ApproxFrom` conversions with the `DefaultApprox` scheme exist between all pairs. `ApproxFrom` with the `Wrapping` scheme exist between integers.
104
105## Errors
106
107A number of error types are defined in the [`errors`](./errors/index.html) module. Generally, conversions use whichever error type most *narrowly* defines the kinds of failures that can occur. For example:
108
109- `ValueFrom<u8> for u16` cannot possibly fail, and as such it uses `NoError`.
110- `ValueFrom<i8> for u16` can *only* fail with a negative overflow, thus it uses the `NegOverflow` type.
111- `ValueFrom<i32> for u16` can overflow in either direction, hence it uses `RangeError`.
112- Finally, `ApproxFrom<f32> for u16` can overflow (positive or negative), or attempt to convert NaN; `FloatError` covers those three cases.
113
114Because there are *numerous* error types, the `GeneralError` enum is provided. `From<E, T> for GeneralError<T>` exists for each error type `E<T>` defined by this crate (even for `NoError`!), allowing errors to be translated automatically by `try!`. In fact, all errors can be "expanded" to *all* more general forms (*e.g.* `NoError` → `NegOverflow`, `PosOverflow` → `RangeError` → `FloatError`).
115
116Aside from `NoError`, the various error types wrap the input value that you attempted to convert. This is so that non-`Copy` types do not need to be pre-emptively cloned prior to conversion, just in case the conversion fails. A downside is that this means there are many, *many* incompatible error types.
117
118To help alleviate this, there is also `GeneralErrorKind`, which is simply `GeneralError<T>` without the payload, and all errors can be converted into it directly.
119
120The reason for not just using `GeneralErrorKind` in the first place is to statically reduce the number of potential error cases you need to deal with. It also allows the `Unwrap*` extension traits to be defined *without* the possibility for runtime failure (*e.g.* you cannot use `unwrap_or_saturate` with a `FloatError`, because what do you do if the error is `NotANumber`; saturate to max or to min? Or panic?).
121
122# Examples
123
124```
125# extern crate conv;
126# use conv::*;
127# fn main() {
128// This *cannot* fail, so we can use `unwrap_ok` to discard the `Result`.
129assert_eq!(u8::value_from(0u8).unwrap_ok(), 0u8);
130
131// This *can* fail. Specifically, it can overflow toward negative infinity.
132assert_eq!(u8::value_from(0i8), Ok(0u8));
133assert_eq!(u8::value_from(-1i8), Err(NegOverflow(-1)));
134
135// This can overflow in *either* direction; hence the change to `RangeError`.
136assert_eq!(u8::value_from(-1i16), Err(RangeError::NegOverflow(-1)));
137assert_eq!(u8::value_from(0i16), Ok(0u8));
138assert_eq!(u8::value_from(256i16), Err(RangeError::PosOverflow(256)));
139
140// We can use the extension traits to simplify this a little.
141assert_eq!(u8::value_from(-1i16).unwrap_or_saturate(), 0u8);
142assert_eq!(u8::value_from(0i16).unwrap_or_saturate(), 0u8);
143assert_eq!(u8::value_from(256i16).unwrap_or_saturate(), 255u8);
144
145// Obviously, all integers can be "approximated" using the default scheme (it
146// doesn't *do* anything), but they can *also* be approximated with the
147// `Wrapping` scheme.
148assert_eq!(
149 <u8 as ApproxFrom<_, DefaultApprox>>::approx_from(400u16),
150 Err(PosOverflow(400)));
151assert_eq!(
152 <u8 as ApproxFrom<_, Wrapping>>::approx_from(400u16),
153 Ok(144u8));
154
155// This is rather inconvenient; as such, there are a number of convenience
156// extension methods available via `ConvUtil` and `ConvAsUtil`.
157assert_eq!(400u16.approx(), Err::<u8, _>(PosOverflow(400)));
158assert_eq!(400u16.approx_by::<Wrapping>(), Ok::<u8, _>(144u8));
159assert_eq!(400u16.approx_as::<u8>(), Err(PosOverflow(400)));
160assert_eq!(400u16.approx_as_by::<u8, Wrapping>(), Ok(144));
161
162// Integer -> float conversions *can* fail due to limited precision.
163// Once the continuous range of exactly representable integers is exceeded, the
164// provided implementations fail with overflow errors.
165assert_eq!(f32::value_from(16_777_216i32), Ok(16_777_216.0f32));
166assert_eq!(f32::value_from(16_777_217i32), Err(RangeError::PosOverflow(16_777_217)));
167
168// Float -> integer conversions have to be done using approximations. Although
169// exact conversions are *possible*, "advertising" this with an implementation
170// is misleading.
171//
172// Note that `DefaultApprox` for float -> integer uses whatever rounding
173// mode is currently active (*i.e.* whatever `as` would do).
174assert_eq!(41.0f32.approx(), Ok(41u8));
175assert_eq!(41.3f32.approx(), Ok(41u8));
176assert_eq!(41.5f32.approx(), Ok(41u8));
177assert_eq!(41.8f32.approx(), Ok(41u8));
178assert_eq!(42.0f32.approx(), Ok(42u8));
179
180assert_eq!(255.0f32.approx(), Ok(255u8));
181assert_eq!(256.0f32.approx(), Err::<u8, _>(FloatError::PosOverflow(256.0)));
182
183// Sometimes, it can be useful to saturate the conversion from float to
184// integer directly, then account for NaN as input separately. The `Saturate`
185// extension trait exists for this reason.
186assert_eq!((-23.0f32).approx_as::<u8>().saturate(), Ok(0));
187assert_eq!(302.0f32.approx_as::<u8>().saturate(), Ok(255u8));
188assert!(std::f32::NAN.approx_as::<u8>().saturate().is_err());
189
190// If you really don't care about the specific kind of error, you can just rely
191// on automatic conversion to `GeneralErrorKind`.
192fn too_many_errors() -> Result<(), GeneralErrorKind> {
193 assert_eq!({let r: u8 = try!(0u8.value_into()); r}, 0u8);
194 assert_eq!({let r: u8 = try!(0i8.value_into()); r}, 0u8);
195 assert_eq!({let r: u8 = try!(0i16.value_into()); r}, 0u8);
196 assert_eq!({let r: u8 = try!(0.0f32.approx()); r}, 0u8);
197 Ok(())
198}
199# let _ = too_many_errors();
200# }
201```
202
203*/
204
205#![deny(missing_docs)]
206
207#[macro_use] extern crate custom_derive;
208
209// Exported macros.
210pub mod macros;
211
212pub use errors::{
213 NoError, GeneralError, GeneralErrorKind, Unrepresentable,
214 NegOverflow, PosOverflow,
215 FloatError, RangeError, RangeErrorKind,
216 Saturate,
217 UnwrapOk, UnwrapOrInf, UnwrapOrInvalid, UnwrapOrSaturate,
218};
219
220use std::error::Error;
221
222/**
223Publicly re-exports the most generally useful set of items.
224
225Usage of the prelude should be considered **unstable**. Although items will likely *not* be removed without bumping the major version, new items *may* be added, which could potentially cause name conflicts in user code.
226*/
227pub mod prelude {
228 pub use super::{
229 ApproxFrom, ApproxInto,
230 ValueFrom, ValueInto,
231 GeneralError, GeneralErrorKind,
232 Saturate,
233 UnwrapOk, UnwrapOrInf, UnwrapOrInvalid, UnwrapOrSaturate,
234 ConvUtil, ConvAsUtil,
235 RoundToNearest, RoundToZero, Wrapping,
236 };
237}
238
239macro_rules! as_item {
240 ($($i:item)*) => {$($i)*};
241}
242
243macro_rules! item_for_each {
244 (
245 $( ($($arg:tt)*) ),* $(,)* => { $($exp:tt)* }
246 ) => {
247 macro_rules! body {
248 $($exp)*
249 }
250
251 $(
252 body! { $($arg)* }
253 )*
254 };
255}
256
257pub mod errors;
258pub mod misc;
259
260mod impls;
261
262/**
263This trait is used to perform a conversion that is permitted to approximate the result, but *not* to wrap or saturate the result to fit into the destination type's representable range.
264
265Where possible, prefer *implementing* this trait over `ApproxInto`, but prefer *using* `ApproxInto` for generic constraints.
266
267# Details
268
269All implementations of this trait must provide a conversion that can be separated into two logical steps: an approximation transform, and a representation transform.
270
271The "approximation transform" step involves transforming the input value into an approximately equivalent value which is supported by the target type *without* taking the target type's representable range into account. For example, this might involve rounding or truncating a floating point value to an integer, or reducing the accuracy of a floating point value.
272
273The "representation transform" step *exactly* rewrites the value from the source type's binary representation into the destination type's binary representation. This step *may not* transform the value in any way. If the result of the approximation is not representable, the conversion *must* fail.
274
275The major reason for this formulation is to exactly define what happens when converting between floating point and integer types. Often, it is unclear what happens to floating point values beyond the range of the target integer type. Do they saturate, wrap, or cause a failure?
276
277With this formulation, it is well-defined: if a floating point value is outside the representable range, the conversion fails. This allows users to distinguish between approximation and range violation, and act accordingly.
278*/
279pub trait ApproxFrom<Src, Scheme=DefaultApprox>: Sized where Scheme: ApproxScheme {
280 /// The error type produced by a failed conversion.
281 type Err: Error;
282
283 /// Convert the given value into an approximately equivalent representation.
284 fn approx_from(src: Src) -> Result<Self, Self::Err>;
285}
286
287impl<Src, Scheme> ApproxFrom<Src, Scheme> for Src where Scheme: ApproxScheme {
288 type Err = NoError;
289 fn approx_from(src: Src) -> Result<Self, Self::Err> {
290 Ok(src)
291 }
292}
293
294/**
295This is the dual of `ApproxFrom`; see that trait for information.
296
297Where possible, prefer *using* this trait over `ApproxFrom` for generic constraints, but prefer *implementing* `ApproxFrom`.
298*/
299pub trait ApproxInto<Dst, Scheme=DefaultApprox> where Scheme: ApproxScheme {
300 /// The error type produced by a failed conversion.
301 type Err: Error;
302
303 /// Convert the subject into an approximately equivalent representation.
304 fn approx_into(self) -> Result<Dst, Self::Err>;
305}
306
307impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Src
308where
309 Dst: ApproxFrom<Src, Scheme>,
310 Scheme: ApproxScheme,
311{
312 type Err = Dst::Err;
313 fn approx_into(self) -> Result<Dst, Self::Err> {
314 ApproxFrom::approx_from(self)
315 }
316}
317
318/**
319This trait is used to mark approximation scheme types.
320*/
321pub trait ApproxScheme {}
322
323/**
324The "default" approximation scheme. This scheme does whatever would generally be expected of a lossy conversion, assuming no additional context or instruction is given.
325
326This is a double-edged sword: it has the loosest semantics, but is far more likely to exist than more complicated approximation schemes.
327*/
328pub enum DefaultApprox {}
329impl ApproxScheme for DefaultApprox {}
330
331/**
332This scheme is used to convert a value by "wrapping" it into a narrower range.
333
334In abstract, this can be viewed as the opposite of rounding: rather than preserving the most significant bits of a value, it preserves the *least* significant bits of a value.
335*/
336pub enum Wrapping {}
337impl ApproxScheme for Wrapping {}
338
339/**
340This scheme is used to convert a value by rounding it to the nearest representable value, with ties rounding away from zero.
341*/
342pub enum RoundToNearest {}
343impl ApproxScheme for RoundToNearest {}
344
345/**
346This scheme is used to convert a value by rounding it toward negative infinity to the nearest representable value.
347*/
348pub enum RoundToNegInf {}
349impl ApproxScheme for RoundToNegInf {}
350
351/**
352This scheme is used to convert a value by rounding it toward positive infinity to the nearest representable value.
353*/
354pub enum RoundToPosInf {}
355impl ApproxScheme for RoundToPosInf {}
356
357/**
358This scheme is used to convert a value by rounding it toward zero to the nearest representable value.
359*/
360pub enum RoundToZero {}
361impl ApproxScheme for RoundToZero {}
362
363/**
364This trait is used to perform a conversion between different semantic types which might fail.
365
366Where possible, prefer *implementing* this trait over `TryInto`, but prefer *using* `TryInto` for generic constraints.
367
368# Details
369
370Typically, this should be used in cases where you are converting between values whose ranges and/or representations only partially overlap. That the conversion may fail should be a reasonably expected outcome. A standard example of this is converting from integers to enums of unitary variants.
371*/
372pub trait TryFrom<Src>: Sized {
373 /// The error type produced by a failed conversion.
374 type Err: Error;
375
376 /// Convert the given value into the subject type.
377 fn try_from(src: Src) -> Result<Self, Self::Err>;
378}
379
380impl<Src> TryFrom<Src> for Src {
381 type Err = NoError;
382 fn try_from(src: Src) -> Result<Self, Self::Err> {
383 Ok(src)
384 }
385}
386
387/**
388This is the dual of `TryFrom`; see that trait for information.
389
390Where possible, prefer *using* this trait over `TryFrom` for generic constraints, but prefer *implementing* `TryFrom`.
391*/
392pub trait TryInto<Dst> {
393 /// The error type produced by a failed conversion.
394 type Err: Error;
395
396 /// Convert the subject into the destination type.
397 fn try_into(self) -> Result<Dst, Self::Err>;
398}
399
400impl<Src, Dst> TryInto<Dst> for Src where Dst: TryFrom<Src> {
401 type Err = Dst::Err;
402 fn try_into(self) -> Result<Dst, Self::Err> {
403 TryFrom::try_from(self)
404 }
405}
406
407/**
408This trait is used to perform an exact, value-preserving conversion.
409
410Where possible, prefer *implementing* this trait over `ValueInto`, but prefer *using* `ValueInto` for generic constraints.
411
412# Details
413
414Implementations of this trait should be reflexive, associative and commutative (in the absence of conversion errors). That is, all possible cycles of `ValueFrom` conversions (for which each "step" has a defined implementation) should produce the same result, with a given value either being "round-tripped" exactly, or an error being produced.
415*/
416pub trait ValueFrom<Src>: Sized {
417 /// The error type produced by a failed conversion.
418 type Err: Error;
419
420 /// Convert the given value into an exactly equivalent representation.
421 fn value_from(src: Src) -> Result<Self, Self::Err>;
422}
423
424impl<Src> ValueFrom<Src> for Src {
425 type Err = NoError;
426 fn value_from(src: Src) -> Result<Self, Self::Err> {
427 Ok(src)
428 }
429}
430
431/**
432This is the dual of `ValueFrom`; see that trait for information.
433
434Where possible, prefer *using* this trait over `ValueFrom` for generic constraints, but prefer *implementing* `ValueFrom`.
435*/
436pub trait ValueInto<Dst> {
437 /// The error type produced by a failed conversion.
438 type Err: Error;
439
440 /// Convert the subject into an exactly equivalent representation.
441 fn value_into(self) -> Result<Dst, Self::Err>;
442}
443
444impl<Src, Dst> ValueInto<Dst> for Src where Dst: ValueFrom<Src> {
445 type Err = Dst::Err;
446 fn value_into(self) -> Result<Dst, Self::Err> {
447 ValueFrom::value_from(self)
448 }
449}
450
451/**
452This extension trait exists to simplify using various conversions.
453
454If there is more than one implementation for a given type/trait pair, a simple call to `*_into` may not be uniquely resolvable. Due to the position of the type parameter (on the trait itself), it is cumbersome to specify the destination type. A similar problem exists for approximation schemes.
455
456See also the [`ConvAsUtil`](./trait.ConvAsUtil.html) trait.
457
458> **Note**: There appears to be a bug in `rustdoc`'s output. This trait is implemented *for all* types, though the methods are only available for types where the appropriate conversions are defined.
459*/
460pub trait ConvUtil {
461 /// Approximate the subject to a given type with the default scheme.
462 fn approx_as<Dst>(self) -> Result<Dst, Self::Err>
463 where Self: Sized + ApproxInto<Dst> {
464 self.approx_into()
465 }
466
467 /// Approximate the subject to a given type with a specific scheme.
468 fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
469 where
470 Self: Sized + ApproxInto<Dst, Scheme>,
471 Scheme: ApproxScheme,
472 {
473 self.approx_into()
474 }
475
476 /// Convert the subject to a given type.
477 fn into_as<Dst>(self) -> Dst
478 where Self: Sized + Into<Dst> {
479 self.into()
480 }
481
482 /// Attempt to convert the subject to a given type.
483 fn try_as<Dst>(self) -> Result<Dst, Self::Err>
484 where Self: Sized + TryInto<Dst> {
485 self.try_into()
486 }
487
488 /// Attempt a value conversion of the subject to a given type.
489 fn value_as<Dst>(self) -> Result<Dst, Self::Err>
490 where Self: Sized + ValueInto<Dst> {
491 self.value_into()
492 }
493}
494
495impl<T> ConvUtil for T {}
496
497/**
498This extension trait exists to simplify using various conversions.
499
500If there is more than one `ApproxFrom` implementation for a given type, a simple call to `approx_into` may not be uniquely resolvable. Due to the position of the scheme parameter (on the trait itself), it is cumbersome to specify which scheme you wanted.
501
502The destination type is inferred from context.
503
504See also the [`ConvUtil`](./trait.ConvUtil.html) trait.
505
506> **Note**: There appears to be a bug in `rustdoc`'s output. This trait is implemented *for all* types, though the methods are only available for types where the appropriate conversions are defined.
507*/
508pub trait ConvAsUtil<Dst> {
509 /// Approximate the subject with the default scheme.
510 fn approx(self) -> Result<Dst, Self::Err>
511 where Self: Sized + ApproxInto<Dst> {
512 self.approx_into()
513 }
514
515 /// Approximate the subject with a specific scheme.
516 fn approx_by<Scheme>(self) -> Result<Dst, Self::Err>
517 where
518 Self: Sized + ApproxInto<Dst, Scheme>,
519 Scheme: ApproxScheme,
520 {
521 self.approx_into()
522 }
523}
524
525impl<T, Dst> ConvAsUtil<Dst> for T {}