Struct Linearized Copy item path
Summary Source pub struct Linearized<L>{ }
Expand description Pre-computed output of Linearize::linearize .
StaticMap and StaticCopyMap can be index directly with a Linearize type.
That operation computes the output of linearize ad-hoc. While the linearize function
is zero cost for many types, you might be using types for which the cost is non-zero
or unknown.
In such situations, the Linearized
type allows you to cache the output of
linearize .
It is guaranteed that the value cached by this type is the output of the linearize
function. In particular, the value is less than LENGTH .
§ Example
fn add_one<L: Linearize>(map: &mut StaticMap<L, u8>, key: L) {
let key = key.linearized();
let v = map[key];
map[key] = v + 1 ;
}
§ Trait Implementations
This type implements traits such as Debug , Hash , etc. These implementations
operate on the pre-computed usize
. In particular, the Debug implementation does
not print the name of the original value used to create this object.
Pre-computes the linearized value.
This function pre-computes the output of linearize .
The LinearizeExt extension trait provides the
linearized function which does the same.
§ Example
fn get_value<L: Linearize>(map: & StaticMap<L, u8>, key: L) -> u8 {
map[Linearized::new(& key)]
}
Wraps an already computed values.
§ Safety
The index must be less than L::LENGTH
.
Returns the linearized value.
This function returns the output of linearize that was
computed when this object was created.
§ Example
fn get<L: Linearize>(key: L) {
assert_eq! (key.linearized().get(), key.linearize());
}
Returns the value that was used to create this object.
This function returns the output of
from_linear_unchecked . This value is required
to be the same that was used to create this object.
§ Example
fn get<L: Linearize + Eq + Debug>(key: L) {
assert_eq! (key.linearized().delinearize(), key);
}
Performs copy-assignment from
source
.
Read more Formats the value using the given formatter.
Read more The returned type after indexing.
Performs the indexing (
container[index]
) operation.
Read more The returned type after indexing.
Performs the indexing (
container[index]
) operation.
Read more Performs the mutable indexing (
container[index]
) operation.
Read more Performs the mutable indexing (
container[index]
) operation.
Read more Compares and returns the maximum of two values.
Read more Compares and returns the minimum of two values.
Read more Restrict a value to a certain interval.
Read more Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
This method returns an ordering between
self
and
other
values if one exists.
Read more Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self
and
other
) and is used by
the
>=
operator.
Read more This method returns an ordering between
self
and
other
values if one exists.
Read more Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self
and
other
) and is used by
the
>=
operator.
Read more Immutably borrows from an owned value.
Read more Mutably borrows from an owned value.
Read more 🔬 This is a nightly-only experimental API. (clone_to_uninit
)
Performs copy-assignment from
self
to
dest
.
Read more Returns the argument unchanged.
Calls U::from(self)
.
That is, this conversion is whatever the implementation of
From <T> for U
chooses to do.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning.
Read more Uses borrowed data to replace owned data, usually by cloning.
Read more The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.