I had written some code for my library, arkley_algebra
, around 3 weeks ago. It built successfully, ran without issues, and passed the tests. However, now it's not compiling, and I'm getting an error message that says: "the trait bound
Number: Clone is not satisfied
." This is surprising because the trait bound for Clone
is implemented using the derive
attribute, and it had worked perfectly before without any changes to the code or modifications to the Rust tools version.
The specific error message is as follows:
error[E0277]: the trait bound `Number: Clone` is not satisfied
> arkley_algebra\src\term.rs:21:5

18  #[derive(Debug,PartialEq,Clone)]
  in this derive macro
expansion
...
21  coefficient: Number,
 ^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `Number`

= note: this error originates in the derive macro `Clone` (in Nightly builds, run with Z macrobacktrace for more info)
error[E0277]: the trait bound `Number: Clone` is not satisfied
> arkley_algebra\src\term.rs:24:5

18  #[derive(Debug,PartialEq,Clone)]
  in this derive macro
expansion
...
24  variables: Variables,
 ^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `Number`

= note: required for `BTreeMap<char, Number>` to implement `Clone`
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with Z macrobacktrace for more info)
Here is the relevant code:
/// Represents a collection of variables, each associated with a numerical value.
/// The `Variables` type is an alias for `BTreeMap<char, Number>`.
pub type Variables = BTreeMap<char,Number>;
/// A struct representing a mathematical term.
///
/// A `Term` is a basic unit in a mathematical expression. It consists of a coefficient
/// (which can be any type that implements the `Numeric` trait) and variables represented
/// as `BTreeMap<char,Number>` .
#[derive(Debug,PartialEq,Clone)]
pub struct Term {
/// The coefficient of the term.
coefficient: Number,
/// The variables and their exponents in the term.
variables: Variables,
}
Where Number
is defined as:
/// Represents a numeric value that can be decimal (aka f64) or Fraction or Standardform number
///
/// `Note` : add fractions variant to is as well
#[derive(Debug, PartialEq, Clone)]
pub enum Number {
/// Represents a floatingpoint decimal number.
Decimal(f64),
/// Represents a number in the StandardForm notation.
StandardForm(StandardForm),
}
/// Represents a number in standard form.
///
/// The `Standardform` struct holds the significand (mantissa) of the number
/// and an exponent that determines the power of 10 by which the significand should be multiplied.
#[derive(Debug,PartialEq,Clone)]
pub struct StandardForm {
mantissa : f64,
exponent : i8
}
I have even tried manually implementing the Clone
trait for Number
, like this:
impl Clone for Number {
fn clone(&self) > Self {
match self {
Number::Decimal(d) => Number::Decimal(*d),
Number::StandardForm(sf) => Number::StandardForm(sf.clone()),
}
}
}
Despite this effort, I'm still encountering the same error. I'm puzzled because I don't have any other errors that might be interfering with the implementation of the Clone
trait, such as macros.
Is there a specific reason for this issue, or is there a way to address and resolve it? I'm unsure of what could be causing this unexpected behavior.