core::ops
本页内容
- Traits
Add1Modulo1Sub1Mul1Div1Rem1Pow1Neg1Not1BitNot1BitAnd1BitOr1BitXor1Shl1Shr1PartialOrd5LogicalAnd1LogicalOr1Call1AddAssign1SubAssign1MulAssign1PowAssign1DivAssign1RemAssign1ModuloAssign1BitAndAssign1BitOrAssign1BitXorAssign1ShlAssign1ShrAssign1DotAdd1DotSub1DotMul1DotPow1DotDiv1DotRem1DotModulo1DotEq1DotNe1DotLt1DotGt1DotLe1DotGe1DotLogicalAnd1DotLogicalOr1DotBitAnd1DotBitOr1DotBitXor1DotShl1DotShr1Broadcastable1BroadcastScalar1Materialize1Cross1Dot1Compose1Sqrt1Contains2Subset2Union1Intersect1
API 参考只有英文版,由标准库源代码中的英文文档注释生成。
Operator traits: the source of every operator token.
nabic binds each token to the trait method carrying its #[infix] /
#[prefix] / #[postfix]; precedence and associativity are fixed by
the language. #[lang(...)] binds each trait to a
compiler slot.
Traits
AddSource
pub trait Add<Rhs = Self>+: addition.
self + rhs.
ModuloSource
pub trait Modulo<Rhs = Self>%%: floored modulo - the result takes the divisor's sign, so
a positive divisor gives [0, rhs) (Python's %). No lang slot.
self %% rhs.
SubSource
pub trait Sub<Rhs = Self>-: subtraction.
self - rhs.
MulSource
pub trait Mul<Rhs = Self>*: multiplication.
self * rhs.
DivSource
pub trait Div<Rhs = Self>/: division.
self / rhs.
RemSource
pub trait Rem<Rhs = Self>%: truncated remainder - the result takes the dividend's sign.
self % rhs.
PowSource
pub trait Pow<Rhs = Self>**: power. Binds tighter than prefix - and to the right:
-x**2 is -(x**2), 2**3**2 is 2**(3**2). An integer base
takes a u32 exponent (overflow is the arithmetic's); a float base
a float (pow) or an i32 (powi).
self ** rhs.
NegSource
pub trait NegPrefix -: negation.
-self.
NotSource
pub trait NotPrefix !: logical not.
!self.
BitNotSource
pub trait BitNotPrefix ~: bitwise not.
~self.
BitAndSource
pub trait BitAnd<Rhs = Self>&: bitwise and.
self & rhs.
BitOrSource
pub trait BitOr<Rhs = Self>|: bitwise or.
self | rhs.
BitXorSource
pub trait BitXor<Rhs = Self>^: bitwise xor.
self ^ rhs.
ShlSource
pub trait Shl<Rhs = Self><<: shift left.
self << rhs.
ShrSource
pub trait Shr<Rhs = Self>>>: shift right.
self >> rhs.
PartialEqSource
pub trait PartialEq<Rhs = Self>== / !=: equality that may be partial (NaN is unequal to itself).
Whether
selfequalsrhs.!=:!self.eq(rhs).
PartialOrdSource
pub trait PartialOrd<Rhs = Self>: PartialEq<Rhs><, >, <=, >=: an order that may be partial (NaN).
Whether
selfis less thanrhs.Whether
selfis greater thanrhs.Whether
selfis less than or equal torhs.Whether
selfis greater than or equal torhs.The order, or
nonewhen the two are incomparable (NaN).
LogicalAndSource
pub trait LogicalAnd<Rhs = Self>&& on a non-bool type; both sides are evaluated.
self && rhs.
LogicalOrSource
pub trait LogicalOr<Rhs = Self>|| on a non-bool type; both sides are evaluated.
self || rhs.
CallSource
pub trait Call<Args>A call v(a) on a value whose type is not a function: call(a).
Args is the one argument's type, a tuple for several (v(a, b) is
v.call((a, b))) and () for none. fn values and closures are
called directly and need no impl.
self(args).
AddAssignSource
pub trait AddAssign<Rhs = Self>+=
Adds
rhstoselfin place.
SubAssignSource
pub trait SubAssign<Rhs = Self>-=
Subtracts
rhsfromselfin place.
MulAssignSource
pub trait MulAssign<Rhs = Self>*=
Multiplies
selfbyrhsin place.
PowAssignSource
pub trait PowAssign<Rhs = Self>**=
Raises
selftorhsin place.
DivAssignSource
pub trait DivAssign<Rhs = Self>/=
Divides
selfbyrhsin place.
RemAssignSource
pub trait RemAssign<Rhs = Self>%=
Sets
selftoself % rhs.
ModuloAssignSource
pub trait ModuloAssign<Rhs = Self>%%=
Sets
selftoself %% rhs.
BitAndAssignSource
pub trait BitAndAssign<Rhs = Self>&=
Sets
selftoself & rhs.
BitOrAssignSource
pub trait BitOrAssign<Rhs = Self>|=
Sets
selftoself | rhs.
BitXorAssignSource
pub trait BitXorAssign<Rhs = Self>^=
Sets
selftoself ^ rhs.
ShlAssignSource
pub trait ShlAssign<Rhs = Self><<=
Shifts
selfleft byrhsin place.
ShrAssignSource
pub trait ShrAssign<Rhs = Self>>>=
Shifts
selfright byrhsin place.
DotAddSource
pub trait DotAdd<Rhs = Self>.+: element-wise addition.
self .+ rhs.
DotSubSource
pub trait DotSub<Rhs = Self>.-: element-wise subtraction.
self .- rhs.
DotMulSource
pub trait DotMul<Rhs = Self>.*: element-wise multiplication.
self .* rhs.
DotPowSource
pub trait DotPow<Rhs = Self>.**: element-wise power.
self .** rhs.
DotDivSource
pub trait DotDiv<Rhs = Self>./: element-wise division.
self ./ rhs.
DotRemSource
pub trait DotRem<Rhs = Self>.%: element-wise truncated remainder.
self .% rhs.
DotModuloSource
pub trait DotModulo<Rhs = Self>.%%: element-wise floored modulo.
self .%% rhs.
DotEqSource
pub trait DotEq<Rhs = Self>.==: element-wise equality.
self .== rhs.
DotNeSource
pub trait DotNe<Rhs = Self>.!=: element-wise inequality.
self .!= rhs.
DotLtSource
pub trait DotLt<Rhs = Self>.<: element-wise less-than.
self .< rhs.
DotGtSource
pub trait DotGt<Rhs = Self>.>: element-wise greater-than.
self .> rhs.
DotLeSource
pub trait DotLe<Rhs = Self>.<=: element-wise less-or-equal.
self .<= rhs.
DotGeSource
pub trait DotGe<Rhs = Self>.>=: element-wise greater-or-equal.
self .>= rhs.
DotLogicalAndSource
pub trait DotLogicalAnd<Rhs = Self>.&& / .||: element-wise, both sides always evaluated.
self .&& rhs.
DotLogicalOrSource
pub trait DotLogicalOr<Rhs = Self>.||: element-wise or, both sides always evaluated.
self .|| rhs.
DotBitAndSource
pub trait DotBitAnd<Rhs = Self>.&: element-wise bitwise and.
self .& rhs.
DotBitOrSource
pub trait DotBitOr<Rhs = Self>.|: element-wise bitwise or.
self .| rhs.
DotBitXorSource
pub trait DotBitXor<Rhs = Self>.^: element-wise bitwise xor.
self .^ rhs.
DotShlSource
pub trait DotShl<Rhs = Self>.<<: element-wise shift left.
self .<< rhs.
DotShrSource
pub trait DotShr<Rhs = Self>.>>: element-wise shift right.
self .>> rhs.
BroadcastableSource
pub trait Broadcastable<const N: usize>An operand of a fused dot expression: its elements seen as an
N-axis array, with no copy. A dot expression whose containers are
all Broadcastable (and whose other operands are primitives, an
element type or BroadcastScalar) runs as one loop with no
intermediate arrays, and .= / .+= .. write into one in place.
Array implements it; a type of your own that keeps its elements in
an Array returns that. Implementing it promises that the type's dot
operators act on the viewed elements as on plain values.
The elements as an array: a view sharing the storage.
BroadcastScalarSource
pub trait BroadcastScalarA scalar operand of a fused dot expression that wraps a number (a
quantity with a unit): the loop applies broadcast_scalar to every
element, as the type's dot operators would.
The plain value.
MaterializeSource
pub trait Materialize<U, const N: usize>The container a fused dot expression returns: out holds the
result's elements, U, in a fresh row-major array. A tree over
arrays takes it from its leading operand (the first of the highest
rank); a tree over types of your own from the type its dot operators
give.
The result built around
out.
CrossSource
pub trait Cross<Rhs = Self>×: cross product.
self × rhs.
DotSource
pub trait Dot<Rhs = Self>⋅: dot product.
self ⋅ rhs.
ComposeSource
pub trait Compose<Rhs>∘: function composition.
self ∘ rhs.
SqrtSource
pub trait SqrtPrefix √: square root.
√self.
ContainsSource
pub trait Contains<Item>∈ / ∉: a ∈ s is s.contains(a) (swap).
Whether
selfholdsitem.∉:!self.contains(item).
SubsetSource
pub trait Subset<Rhs = Self>⊂ / ⊆: subset tests.
Whether every item of
selfis inrhsandrhshas more.Whether every item of
selfis inrhs.
UnionSource
pub trait Union<Rhs = Self>∪: union.
self ∪ rhs.
IntersectSource
pub trait Intersect<Rhs = Self>∩: intersection.
self ∩ rhs.