pub trait HasSubfield<S: Field>: Field + Algebra<S> {
// Required method
fn as_subfield(&self) -> Option<S>;
// Provided method
fn all_in_subfield(values: &[Self]) -> bool { ... }
}Expand description
A field containing a copy of the small field S.
A kernel whose inputs all lie in S can do its arithmetic there and lift only the result.
The Algebra supertrait embeds S and lets its elements act on this field.
This trait answers whether an element lies in that copy of S.
§Contract
For every x: Self, s: S and values: &[Self]:
Self::fromis an injective ring homomorphism: it sendsS::ONEtoSelf::ONE, it commutes with addition and multiplication, and distinct elements ofShave distinct images.x + s,x - sandx * sequalx + Self::from(s),x - Self::from(s)andx * Self::from(s), and so do the assigning forms.x.as_subfield() == Some(s)holds exactly whenx == Self::from(s). So it returnsNoneexactly whenxis the image of no element ofS.Self::all_in_subfield(values)holds exactly when everyv.as_subfield()isSome. In particular it holds on an empty slice.
Callers narrow values into S on the strength of these equalities, so they must hold exactly.
A Some for an element outside the subfield would silently compute with a different value.
Required Methods§
Sourcefn as_subfield(&self) -> Option<S>
fn as_subfield(&self) -> Option<S>
The element of S whose image this is, or None if it lies outside the subfield.
Provided Methods§
Sourcefn all_in_subfield(values: &[Self]) -> bool
fn all_in_subfield(values: &[Self]) -> bool
Whether every element of values lies in the subfield.
Equal to values.iter().all(|v| v.as_subfield().is_some()), which is what the default
computes. Override it where a whole slice can be tested without narrowing each element in
turn.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".