Skip to main content

p3_field/
dup.rs

1/// Cheap duplication for prime-characteristic ring elements used in hot paths.
2///
3///  - [`Copy`] scalars and packed fields use a trivial copy
4///  - non-[`Copy`] rings (e.g. symbolic expressions) should implement this with [`Clone::clone`]
5///
6/// It defaults to a trivial copy for types that are both [`Copy`] and [`Clone`].
7///
8/// # Usage
9///
10/// It is recommended to rely on the [`Dup`] trait in downstream implementations for any type
11/// that is used in hot paths, such as trace cells in constraint evaluation for instance.
12pub trait Dup: Clone {
13    fn dup(&self) -> Self;
14}
15
16impl<T: Copy + Clone> Dup for T {
17    #[inline(always)]
18    fn dup(&self) -> Self {
19        *self
20    }
21}