相关疑难解决方法(0)

从特性到特性以及将usize转换为f64

我一直试图以一种非常通用的方式编写一些Rust代码,而没有明确指定类型。但是,我到达了需要将a转换usize为a的位置f64,但这不起作用。大概f64没有足够的精度来保存任意usize值。在夜间频道上进行编译时,出现错误消息:error: the trait `core::convert::From<usize>` is not implemented for the type `f64` [E0277]

那么,如果我想编写尽可能通用的代码,那有什么选择呢?显然,我应该使用可能会失败的特征(与Into或不同From)。已经有那样的东西了吗?是否有通过实施转换的特征as

这是下面的代码。

#![feature(zero_one)]
use std::num::{Zero, One};
use std::ops::{Add, Mul, Div, Neg};
use std::convert::{From, Into};

/// Computes the reciprocal of a polynomial or of a truncation of a
/// series.
///
/// If the input is of length `n`, then this performs `n^2`
/// multiplications.  Therefore the complexity is `n^2` when the type …
Run Code Online (Sandbox Code Playgroud)

type-conversion rust

3
推荐指数
2
解决办法
1736
查看次数

标签 统计

rust ×1

type-conversion ×1