Trait easy_cast::ConvFloat

source ·
pub trait ConvFloat<T>: Sized {
    fn try_conv_trunc(x: T) -> Result<Self>;
    fn try_conv_nearest(x: T) -> Result<Self>;
    fn try_conv_floor(x: T) -> Result<Self>;
    fn try_conv_ceil(x: T) -> Result<Self>;

    fn conv_trunc(x: T) -> Self { ... }
    fn conv_nearest(x: T) -> Self { ... }
    fn conv_floor(x: T) -> Self { ... }
    fn conv_ceil(x: T) -> Self { ... }
}
Expand description

Nearest / floor / ceiling conversions from floating point types

This trait is explicitly for conversions from floating-point values to integers, supporting four rounding modes.

As with Conv, the try_conv_* methods must be implemented and must fail if conversion to the expected value is not possible. If the source is non- finite (inf or NaN), then Error::Range should be returned.

The conv_* methods each have a default implementation over the try_.. variant which panics on failure. Implementations handle errors as follows:

  • In debug builds, the methods must panic
  • Otherwise, the method may panic or may return a different value; all results must be well-defined and safe.
  • Implementations provided by this library will also panic if the always_assert or assert_float feature flag is used.

The sister-trait CastFloat supports “into” style usage.

Required Methods§

Try converting to integer with truncation

Rounds towards zero (same as as).

Try converting to the nearest integer

Half-way cases are rounded away from 0.

Try converting the floor to an integer

Returns the largest integer less than or equal to x.

Try convert the ceiling to an integer

Returns the smallest integer greater than or equal to x.

Provided Methods§

Convert to integer with truncatation

Rounds towards zero (same as as).

Examples found in repository?
src/traits.rs (line 324)
323
324
325
    fn cast_trunc(self) -> T {
        T::conv_trunc(self)
    }
More examples
Hide additional examples
src/impl_float.rs (line 243)
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
    fn conv_floor(x: f32) -> u128 {
        ConvFloat::conv_trunc(x)
    }
    #[inline]
    fn conv_ceil(x: f32) -> u128 {
        if cfg!(any(debug_assertions, feature = "assert_float")) {
            Self::try_conv_ceil(x)
                .unwrap_or_else(|_| panic!("cast x: f32 to u128 (ceil): range error for x = {}", x))
        } else {
            x.ceil() as u128
        }
    }

    #[inline]
    fn try_conv_trunc(x: f32) -> Result<Self> {
        // Note: f32::MAX < u128::MAX
        if x >= 0.0 && x.is_finite() {
            Ok(x as u128)
        } else {
            Err(Error::Range)
        }
    }
    #[inline]
    fn try_conv_nearest(x: f32) -> Result<Self> {
        let x = x.round();
        if x >= 0.0 && x.is_finite() {
            Ok(x as u128)
        } else {
            Err(Error::Range)
        }
    }
    #[inline]
    fn try_conv_floor(x: f32) -> Result<Self> {
        Self::try_conv_trunc(x)
    }
    #[inline]
    fn try_conv_ceil(x: f32) -> Result<Self> {
        let x = x.ceil();
        if x >= 0.0 && x.is_finite() {
            Ok(x as u128)
        } else {
            Err(Error::Range)
        }
    }
}

#[cfg(any(feature = "std", feature = "libm"))]
impl ConvApprox<f32> for u128 {
    #[inline]
    fn try_conv_approx(x: f32) -> Result<Self> {
        ConvFloat::<f32>::try_conv_trunc(x)
    }
    #[inline]
    fn conv_approx(x: f32) -> Self {
        ConvFloat::<f32>::conv_trunc(x)
    }
src/impl_basic.rs (line 100)
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
    fn conv_trunc(ss: [S; N]) -> Self {
        let mut tt = [T::default(); N];
        for (s, t) in IntoIterator::into_iter(ss).zip(tt.iter_mut()) {
            *t = T::conv_trunc(s);
        }
        tt
    }
    #[inline]
    fn conv_nearest(ss: [S; N]) -> Self {
        let mut tt = [T::default(); N];
        for (s, t) in IntoIterator::into_iter(ss).zip(tt.iter_mut()) {
            *t = T::conv_nearest(s);
        }
        tt
    }
    #[inline]
    fn conv_floor(ss: [S; N]) -> Self {
        let mut tt = [T::default(); N];
        for (s, t) in IntoIterator::into_iter(ss).zip(tt.iter_mut()) {
            *t = T::conv_floor(s);
        }
        tt
    }
    #[inline]
    fn conv_ceil(ss: [S; N]) -> Self {
        let mut tt = [T::default(); N];
        for (s, t) in IntoIterator::into_iter(ss).zip(tt.iter_mut()) {
            *t = T::conv_ceil(s);
        }
        tt
    }
}

impl Conv<()> for () {
    #[inline]
    fn try_conv(_: ()) -> Result<Self> {
        Ok(())
    }
    #[inline]
    fn conv(_: ()) -> Self {
        ()
    }
}
impl<S0, T0: Conv<S0>> Conv<(S0,)> for (T0,) {
    #[inline]
    fn try_conv(ss: (S0,)) -> Result<Self> {
        Ok((ss.0.try_cast()?,))
    }
    #[inline]
    fn conv(ss: (S0,)) -> Self {
        (ss.0.cast(),)
    }
}
impl<S0, S1, T0: Conv<S0>, T1: Conv<S1>> Conv<(S0, S1)> for (T0, T1) {
    #[inline]
    fn try_conv(ss: (S0, S1)) -> Result<Self> {
        Ok((ss.0.try_cast()?, ss.1.try_cast()?))
    }
    #[inline]
    fn conv(ss: (S0, S1)) -> Self {
        (ss.0.cast(), ss.1.cast())
    }
}
impl<S0, S1, S2, T0: Conv<S0>, T1: Conv<S1>, T2: Conv<S2>> Conv<(S0, S1, S2)> for (T0, T1, T2) {
    #[inline]
    fn try_conv(ss: (S0, S1, S2)) -> Result<Self> {
        Ok((ss.0.try_cast()?, ss.1.try_cast()?, ss.2.try_cast()?))
    }
    #[inline]
    fn conv(ss: (S0, S1, S2)) -> Self {
        (ss.0.cast(), ss.1.cast(), ss.2.cast())
    }
}
impl<S0, S1, S2, S3, T0: Conv<S0>, T1: Conv<S1>, T2: Conv<S2>, T3: Conv<S3>> Conv<(S0, S1, S2, S3)>
    for (T0, T1, T2, T3)
{
    #[inline]
    fn try_conv(ss: (S0, S1, S2, S3)) -> Result<Self> {
        Ok((
            ss.0.try_cast()?,
            ss.1.try_cast()?,
            ss.2.try_cast()?,
            ss.3.try_cast()?,
        ))
    }
    #[inline]
    fn conv(ss: (S0, S1, S2, S3)) -> Self {
        (ss.0.cast(), ss.1.cast(), ss.2.cast(), ss.3.cast())
    }
}
impl<S0, S1, S2, S3, S4, T0: Conv<S0>, T1: Conv<S1>, T2: Conv<S2>, T3: Conv<S3>, T4: Conv<S4>>
    Conv<(S0, S1, S2, S3, S4)> for (T0, T1, T2, T3, T4)
{
    #[inline]
    fn try_conv(ss: (S0, S1, S2, S3, S4)) -> Result<Self> {
        Ok((
            ss.0.try_cast()?,
            ss.1.try_cast()?,
            ss.2.try_cast()?,
            ss.3.try_cast()?,
            ss.4.try_cast()?,
        ))
    }
    #[inline]
    fn conv(ss: (S0, S1, S2, S3, S4)) -> Self {
        (
            ss.0.cast(),
            ss.1.cast(),
            ss.2.cast(),
            ss.3.cast(),
            ss.4.cast(),
        )
    }
}
impl<S0, S1, S2, S3, S4, S5, T0, T1, T2, T3, T4, T5> Conv<(S0, S1, S2, S3, S4, S5)>
    for (T0, T1, T2, T3, T4, T5)
where
    T0: Conv<S0>,
    T1: Conv<S1>,
    T2: Conv<S2>,
    T3: Conv<S3>,
    T4: Conv<S4>,
    T5: Conv<S5>,
{
    #[inline]
    fn try_conv(ss: (S0, S1, S2, S3, S4, S5)) -> Result<Self> {
        Ok((
            ss.0.try_cast()?,
            ss.1.try_cast()?,
            ss.2.try_cast()?,
            ss.3.try_cast()?,
            ss.4.try_cast()?,
            ss.5.try_cast()?,
        ))
    }
    #[inline]
    fn conv(ss: (S0, S1, S2, S3, S4, S5)) -> Self {
        (
            ss.0.cast(),
            ss.1.cast(),
            ss.2.cast(),
            ss.3.cast(),
            ss.4.cast(),
            ss.5.cast(),
        )
    }
}

#[cfg(any(feature = "std", feature = "libm"))]
impl<S0, S1, T0: ConvFloat<S0>, T1: ConvFloat<S1>> ConvFloat<(S0, S1)> for (T0, T1) {
    #[inline]
    fn try_conv_trunc(ss: (S0, S1)) -> Result<Self> {
        Ok((T0::try_conv_trunc(ss.0)?, T1::try_conv_trunc(ss.1)?))
    }
    #[inline]
    fn try_conv_nearest(ss: (S0, S1)) -> Result<Self> {
        Ok((T0::try_conv_nearest(ss.0)?, T1::try_conv_nearest(ss.1)?))
    }
    #[inline]
    fn try_conv_floor(ss: (S0, S1)) -> Result<Self> {
        Ok((T0::try_conv_floor(ss.0)?, T1::try_conv_floor(ss.1)?))
    }
    #[inline]
    fn try_conv_ceil(ss: (S0, S1)) -> Result<Self> {
        Ok((T0::try_conv_ceil(ss.0)?, T1::try_conv_ceil(ss.1)?))
    }

    #[inline]
    fn conv_trunc(ss: (S0, S1)) -> Self {
        (T0::conv_trunc(ss.0), T1::conv_trunc(ss.1))
    }

Convert to the nearest integer

Half-way cases are rounded away from 0.

Examples found in repository?
src/traits.rs (line 328)
327
328
329
    fn cast_nearest(self) -> T {
        T::conv_nearest(self)
    }
More examples
Hide additional examples
src/impl_basic.rs (line 108)
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
    fn conv_nearest(ss: [S; N]) -> Self {
        let mut tt = [T::default(); N];
        for (s, t) in IntoIterator::into_iter(ss).zip(tt.iter_mut()) {
            *t = T::conv_nearest(s);
        }
        tt
    }
    #[inline]
    fn conv_floor(ss: [S; N]) -> Self {
        let mut tt = [T::default(); N];
        for (s, t) in IntoIterator::into_iter(ss).zip(tt.iter_mut()) {
            *t = T::conv_floor(s);
        }
        tt
    }
    #[inline]
    fn conv_ceil(ss: [S; N]) -> Self {
        let mut tt = [T::default(); N];
        for (s, t) in IntoIterator::into_iter(ss).zip(tt.iter_mut()) {
            *t = T::conv_ceil(s);
        }
        tt
    }
}

impl Conv<()> for () {
    #[inline]
    fn try_conv(_: ()) -> Result<Self> {
        Ok(())
    }
    #[inline]
    fn conv(_: ()) -> Self {
        ()
    }
}
impl<S0, T0: Conv<S0>> Conv<(S0,)> for (T0,) {
    #[inline]
    fn try_conv(ss: (S0,)) -> Result<Self> {
        Ok((ss.0.try_cast()?,))
    }
    #[inline]
    fn conv(ss: (S0,)) -> Self {
        (ss.0.cast(),)
    }
}
impl<S0, S1, T0: Conv<S0>, T1: Conv<S1>> Conv<(S0, S1)> for (T0, T1) {
    #[inline]
    fn try_conv(ss: (S0, S1)) -> Result<Self> {
        Ok((ss.0.try_cast()?, ss.1.try_cast()?))
    }
    #[inline]
    fn conv(ss: (S0, S1)) -> Self {
        (ss.0.cast(), ss.1.cast())
    }
}
impl<S0, S1, S2, T0: Conv<S0>, T1: Conv<S1>, T2: Conv<S2>> Conv<(S0, S1, S2)> for (T0, T1, T2) {
    #[inline]
    fn try_conv(ss: (S0, S1, S2)) -> Result<Self> {
        Ok((ss.0.try_cast()?, ss.1.try_cast()?, ss.2.try_cast()?))
    }
    #[inline]
    fn conv(ss: (S0, S1, S2)) -> Self {
        (ss.0.cast(), ss.1.cast(), ss.2.cast())
    }
}
impl<S0, S1, S2, S3, T0: Conv<S0>, T1: Conv<S1>, T2: Conv<S2>, T3: Conv<S3>> Conv<(S0, S1, S2, S3)>
    for (T0, T1, T2, T3)
{
    #[inline]
    fn try_conv(ss: (S0, S1, S2, S3)) -> Result<Self> {
        Ok((
            ss.0.try_cast()?,
            ss.1.try_cast()?,
            ss.2.try_cast()?,
            ss.3.try_cast()?,
        ))
    }
    #[inline]
    fn conv(ss: (S0, S1, S2, S3)) -> Self {
        (ss.0.cast(), ss.1.cast(), ss.2.cast(), ss.3.cast())
    }
}
impl<S0, S1, S2, S3, S4, T0: Conv<S0>, T1: Conv<S1>, T2: Conv<S2>, T3: Conv<S3>, T4: Conv<S4>>
    Conv<(S0, S1, S2, S3, S4)> for (T0, T1, T2, T3, T4)
{
    #[inline]
    fn try_conv(ss: (S0, S1, S2, S3, S4)) -> Result<Self> {
        Ok((
            ss.0.try_cast()?,
            ss.1.try_cast()?,
            ss.2.try_cast()?,
            ss.3.try_cast()?,
            ss.4.try_cast()?,
        ))
    }
    #[inline]
    fn conv(ss: (S0, S1, S2, S3, S4)) -> Self {
        (
            ss.0.cast(),
            ss.1.cast(),
            ss.2.cast(),
            ss.3.cast(),
            ss.4.cast(),
        )
    }
}
impl<S0, S1, S2, S3, S4, S5, T0, T1, T2, T3, T4, T5> Conv<(S0, S1, S2, S3, S4, S5)>
    for (T0, T1, T2, T3, T4, T5)
where
    T0: Conv<S0>,
    T1: Conv<S1>,
    T2: Conv<S2>,
    T3: Conv<S3>,
    T4: Conv<S4>,
    T5: Conv<S5>,
{
    #[inline]
    fn try_conv(ss: (S0, S1, S2, S3, S4, S5)) -> Result<Self> {
        Ok((
            ss.0.try_cast()?,
            ss.1.try_cast()?,
            ss.2.try_cast()?,
            ss.3.try_cast()?,
            ss.4.try_cast()?,
            ss.5.try_cast()?,
        ))
    }
    #[inline]
    fn conv(ss: (S0, S1, S2, S3, S4, S5)) -> Self {
        (
            ss.0.cast(),
            ss.1.cast(),
            ss.2.cast(),
            ss.3.cast(),
            ss.4.cast(),
            ss.5.cast(),
        )
    }
}

#[cfg(any(feature = "std", feature = "libm"))]
impl<S0, S1, T0: ConvFloat<S0>, T1: ConvFloat<S1>> ConvFloat<(S0, S1)> for (T0, T1) {
    #[inline]
    fn try_conv_trunc(ss: (S0, S1)) -> Result<Self> {
        Ok((T0::try_conv_trunc(ss.0)?, T1::try_conv_trunc(ss.1)?))
    }
    #[inline]
    fn try_conv_nearest(ss: (S0, S1)) -> Result<Self> {
        Ok((T0::try_conv_nearest(ss.0)?, T1::try_conv_nearest(ss.1)?))
    }
    #[inline]
    fn try_conv_floor(ss: (S0, S1)) -> Result<Self> {
        Ok((T0::try_conv_floor(ss.0)?, T1::try_conv_floor(ss.1)?))
    }
    #[inline]
    fn try_conv_ceil(ss: (S0, S1)) -> Result<Self> {
        Ok((T0::try_conv_ceil(ss.0)?, T1::try_conv_ceil(ss.1)?))
    }

    #[inline]
    fn conv_trunc(ss: (S0, S1)) -> Self {
        (T0::conv_trunc(ss.0), T1::conv_trunc(ss.1))
    }
    #[inline]
    fn conv_nearest(ss: (S0, S1)) -> Self {
        (T0::conv_nearest(ss.0), T1::conv_nearest(ss.1))
    }

Convert the floor to an integer

Returns the largest integer less than or equal to x.

Examples found in repository?
src/traits.rs (line 332)
331
332
333
    fn cast_floor(self) -> T {
        T::conv_floor(self)
    }
More examples
Hide additional examples
src/impl_basic.rs (line 116)
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
    fn conv_floor(ss: [S; N]) -> Self {
        let mut tt = [T::default(); N];
        for (s, t) in IntoIterator::into_iter(ss).zip(tt.iter_mut()) {
            *t = T::conv_floor(s);
        }
        tt
    }
    #[inline]
    fn conv_ceil(ss: [S; N]) -> Self {
        let mut tt = [T::default(); N];
        for (s, t) in IntoIterator::into_iter(ss).zip(tt.iter_mut()) {
            *t = T::conv_ceil(s);
        }
        tt
    }
}

impl Conv<()> for () {
    #[inline]
    fn try_conv(_: ()) -> Result<Self> {
        Ok(())
    }
    #[inline]
    fn conv(_: ()) -> Self {
        ()
    }
}
impl<S0, T0: Conv<S0>> Conv<(S0,)> for (T0,) {
    #[inline]
    fn try_conv(ss: (S0,)) -> Result<Self> {
        Ok((ss.0.try_cast()?,))
    }
    #[inline]
    fn conv(ss: (S0,)) -> Self {
        (ss.0.cast(),)
    }
}
impl<S0, S1, T0: Conv<S0>, T1: Conv<S1>> Conv<(S0, S1)> for (T0, T1) {
    #[inline]
    fn try_conv(ss: (S0, S1)) -> Result<Self> {
        Ok((ss.0.try_cast()?, ss.1.try_cast()?))
    }
    #[inline]
    fn conv(ss: (S0, S1)) -> Self {
        (ss.0.cast(), ss.1.cast())
    }
}
impl<S0, S1, S2, T0: Conv<S0>, T1: Conv<S1>, T2: Conv<S2>> Conv<(S0, S1, S2)> for (T0, T1, T2) {
    #[inline]
    fn try_conv(ss: (S0, S1, S2)) -> Result<Self> {
        Ok((ss.0.try_cast()?, ss.1.try_cast()?, ss.2.try_cast()?))
    }
    #[inline]
    fn conv(ss: (S0, S1, S2)) -> Self {
        (ss.0.cast(), ss.1.cast(), ss.2.cast())
    }
}
impl<S0, S1, S2, S3, T0: Conv<S0>, T1: Conv<S1>, T2: Conv<S2>, T3: Conv<S3>> Conv<(S0, S1, S2, S3)>
    for (T0, T1, T2, T3)
{
    #[inline]
    fn try_conv(ss: (S0, S1, S2, S3)) -> Result<Self> {
        Ok((
            ss.0.try_cast()?,
            ss.1.try_cast()?,
            ss.2.try_cast()?,
            ss.3.try_cast()?,
        ))
    }
    #[inline]
    fn conv(ss: (S0, S1, S2, S3)) -> Self {
        (ss.0.cast(), ss.1.cast(), ss.2.cast(), ss.3.cast())
    }
}
impl<S0, S1, S2, S3, S4, T0: Conv<S0>, T1: Conv<S1>, T2: Conv<S2>, T3: Conv<S3>, T4: Conv<S4>>
    Conv<(S0, S1, S2, S3, S4)> for (T0, T1, T2, T3, T4)
{
    #[inline]
    fn try_conv(ss: (S0, S1, S2, S3, S4)) -> Result<Self> {
        Ok((
            ss.0.try_cast()?,
            ss.1.try_cast()?,
            ss.2.try_cast()?,
            ss.3.try_cast()?,
            ss.4.try_cast()?,
        ))
    }
    #[inline]
    fn conv(ss: (S0, S1, S2, S3, S4)) -> Self {
        (
            ss.0.cast(),
            ss.1.cast(),
            ss.2.cast(),
            ss.3.cast(),
            ss.4.cast(),
        )
    }
}
impl<S0, S1, S2, S3, S4, S5, T0, T1, T2, T3, T4, T5> Conv<(S0, S1, S2, S3, S4, S5)>
    for (T0, T1, T2, T3, T4, T5)
where
    T0: Conv<S0>,
    T1: Conv<S1>,
    T2: Conv<S2>,
    T3: Conv<S3>,
    T4: Conv<S4>,
    T5: Conv<S5>,
{
    #[inline]
    fn try_conv(ss: (S0, S1, S2, S3, S4, S5)) -> Result<Self> {
        Ok((
            ss.0.try_cast()?,
            ss.1.try_cast()?,
            ss.2.try_cast()?,
            ss.3.try_cast()?,
            ss.4.try_cast()?,
            ss.5.try_cast()?,
        ))
    }
    #[inline]
    fn conv(ss: (S0, S1, S2, S3, S4, S5)) -> Self {
        (
            ss.0.cast(),
            ss.1.cast(),
            ss.2.cast(),
            ss.3.cast(),
            ss.4.cast(),
            ss.5.cast(),
        )
    }
}

#[cfg(any(feature = "std", feature = "libm"))]
impl<S0, S1, T0: ConvFloat<S0>, T1: ConvFloat<S1>> ConvFloat<(S0, S1)> for (T0, T1) {
    #[inline]
    fn try_conv_trunc(ss: (S0, S1)) -> Result<Self> {
        Ok((T0::try_conv_trunc(ss.0)?, T1::try_conv_trunc(ss.1)?))
    }
    #[inline]
    fn try_conv_nearest(ss: (S0, S1)) -> Result<Self> {
        Ok((T0::try_conv_nearest(ss.0)?, T1::try_conv_nearest(ss.1)?))
    }
    #[inline]
    fn try_conv_floor(ss: (S0, S1)) -> Result<Self> {
        Ok((T0::try_conv_floor(ss.0)?, T1::try_conv_floor(ss.1)?))
    }
    #[inline]
    fn try_conv_ceil(ss: (S0, S1)) -> Result<Self> {
        Ok((T0::try_conv_ceil(ss.0)?, T1::try_conv_ceil(ss.1)?))
    }

    #[inline]
    fn conv_trunc(ss: (S0, S1)) -> Self {
        (T0::conv_trunc(ss.0), T1::conv_trunc(ss.1))
    }
    #[inline]
    fn conv_nearest(ss: (S0, S1)) -> Self {
        (T0::conv_nearest(ss.0), T1::conv_nearest(ss.1))
    }
    #[inline]
    fn conv_floor(ss: (S0, S1)) -> Self {
        (T0::conv_floor(ss.0), T1::conv_floor(ss.1))
    }

Convert the ceiling to an integer

Returns the smallest integer greater than or equal to x.

Examples found in repository?
src/traits.rs (line 336)
335
336
337
    fn cast_ceil(self) -> T {
        T::conv_ceil(self)
    }
More examples
Hide additional examples
src/impl_basic.rs (line 124)
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
    fn conv_ceil(ss: [S; N]) -> Self {
        let mut tt = [T::default(); N];
        for (s, t) in IntoIterator::into_iter(ss).zip(tt.iter_mut()) {
            *t = T::conv_ceil(s);
        }
        tt
    }
}

impl Conv<()> for () {
    #[inline]
    fn try_conv(_: ()) -> Result<Self> {
        Ok(())
    }
    #[inline]
    fn conv(_: ()) -> Self {
        ()
    }
}
impl<S0, T0: Conv<S0>> Conv<(S0,)> for (T0,) {
    #[inline]
    fn try_conv(ss: (S0,)) -> Result<Self> {
        Ok((ss.0.try_cast()?,))
    }
    #[inline]
    fn conv(ss: (S0,)) -> Self {
        (ss.0.cast(),)
    }
}
impl<S0, S1, T0: Conv<S0>, T1: Conv<S1>> Conv<(S0, S1)> for (T0, T1) {
    #[inline]
    fn try_conv(ss: (S0, S1)) -> Result<Self> {
        Ok((ss.0.try_cast()?, ss.1.try_cast()?))
    }
    #[inline]
    fn conv(ss: (S0, S1)) -> Self {
        (ss.0.cast(), ss.1.cast())
    }
}
impl<S0, S1, S2, T0: Conv<S0>, T1: Conv<S1>, T2: Conv<S2>> Conv<(S0, S1, S2)> for (T0, T1, T2) {
    #[inline]
    fn try_conv(ss: (S0, S1, S2)) -> Result<Self> {
        Ok((ss.0.try_cast()?, ss.1.try_cast()?, ss.2.try_cast()?))
    }
    #[inline]
    fn conv(ss: (S0, S1, S2)) -> Self {
        (ss.0.cast(), ss.1.cast(), ss.2.cast())
    }
}
impl<S0, S1, S2, S3, T0: Conv<S0>, T1: Conv<S1>, T2: Conv<S2>, T3: Conv<S3>> Conv<(S0, S1, S2, S3)>
    for (T0, T1, T2, T3)
{
    #[inline]
    fn try_conv(ss: (S0, S1, S2, S3)) -> Result<Self> {
        Ok((
            ss.0.try_cast()?,
            ss.1.try_cast()?,
            ss.2.try_cast()?,
            ss.3.try_cast()?,
        ))
    }
    #[inline]
    fn conv(ss: (S0, S1, S2, S3)) -> Self {
        (ss.0.cast(), ss.1.cast(), ss.2.cast(), ss.3.cast())
    }
}
impl<S0, S1, S2, S3, S4, T0: Conv<S0>, T1: Conv<S1>, T2: Conv<S2>, T3: Conv<S3>, T4: Conv<S4>>
    Conv<(S0, S1, S2, S3, S4)> for (T0, T1, T2, T3, T4)
{
    #[inline]
    fn try_conv(ss: (S0, S1, S2, S3, S4)) -> Result<Self> {
        Ok((
            ss.0.try_cast()?,
            ss.1.try_cast()?,
            ss.2.try_cast()?,
            ss.3.try_cast()?,
            ss.4.try_cast()?,
        ))
    }
    #[inline]
    fn conv(ss: (S0, S1, S2, S3, S4)) -> Self {
        (
            ss.0.cast(),
            ss.1.cast(),
            ss.2.cast(),
            ss.3.cast(),
            ss.4.cast(),
        )
    }
}
impl<S0, S1, S2, S3, S4, S5, T0, T1, T2, T3, T4, T5> Conv<(S0, S1, S2, S3, S4, S5)>
    for (T0, T1, T2, T3, T4, T5)
where
    T0: Conv<S0>,
    T1: Conv<S1>,
    T2: Conv<S2>,
    T3: Conv<S3>,
    T4: Conv<S4>,
    T5: Conv<S5>,
{
    #[inline]
    fn try_conv(ss: (S0, S1, S2, S3, S4, S5)) -> Result<Self> {
        Ok((
            ss.0.try_cast()?,
            ss.1.try_cast()?,
            ss.2.try_cast()?,
            ss.3.try_cast()?,
            ss.4.try_cast()?,
            ss.5.try_cast()?,
        ))
    }
    #[inline]
    fn conv(ss: (S0, S1, S2, S3, S4, S5)) -> Self {
        (
            ss.0.cast(),
            ss.1.cast(),
            ss.2.cast(),
            ss.3.cast(),
            ss.4.cast(),
            ss.5.cast(),
        )
    }
}

#[cfg(any(feature = "std", feature = "libm"))]
impl<S0, S1, T0: ConvFloat<S0>, T1: ConvFloat<S1>> ConvFloat<(S0, S1)> for (T0, T1) {
    #[inline]
    fn try_conv_trunc(ss: (S0, S1)) -> Result<Self> {
        Ok((T0::try_conv_trunc(ss.0)?, T1::try_conv_trunc(ss.1)?))
    }
    #[inline]
    fn try_conv_nearest(ss: (S0, S1)) -> Result<Self> {
        Ok((T0::try_conv_nearest(ss.0)?, T1::try_conv_nearest(ss.1)?))
    }
    #[inline]
    fn try_conv_floor(ss: (S0, S1)) -> Result<Self> {
        Ok((T0::try_conv_floor(ss.0)?, T1::try_conv_floor(ss.1)?))
    }
    #[inline]
    fn try_conv_ceil(ss: (S0, S1)) -> Result<Self> {
        Ok((T0::try_conv_ceil(ss.0)?, T1::try_conv_ceil(ss.1)?))
    }

    #[inline]
    fn conv_trunc(ss: (S0, S1)) -> Self {
        (T0::conv_trunc(ss.0), T1::conv_trunc(ss.1))
    }
    #[inline]
    fn conv_nearest(ss: (S0, S1)) -> Self {
        (T0::conv_nearest(ss.0), T1::conv_nearest(ss.1))
    }
    #[inline]
    fn conv_floor(ss: (S0, S1)) -> Self {
        (T0::conv_floor(ss.0), T1::conv_floor(ss.1))
    }
    #[inline]
    fn conv_ceil(ss: (S0, S1)) -> Self {
        (T0::conv_ceil(ss.0), T1::conv_ceil(ss.1))
    }

Implementations on Foreign Types§

Implementors§