pub trait FromMappings: Sized {
// Required method
fn from_mappings<I>(mappings: I, size: usize) -> Result<Self, String>
where I: IntoIterator<Item = (usize, usize)>;
}Required Methods§
fn from_mappings<I>(mappings: I, size: usize) -> Result<Self, String>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl FromMappings for Permutation
impl FromMappings for Permutation
Source§fn from_mappings<I>(mappings: I, size: usize) -> Result<Self, String>
fn from_mappings<I>(mappings: I, size: usize) -> Result<Self, String>
Creates a permutation from a set of mapping pairs, minimizing changes to other elements.
Takes a collection of (from, to) pairs and constructs a valid permutation that satisfies these mappings while keeping other elements as close to their identity positions as possible.
§Arguments
mappings- An iterator of (from, to) pairs where each pair representsfrom -> tosize- The size of the permutation to create
§Returns
A Result containing the permutation if successful, or an error string if the mappings
are inconsistent or invalid.
§Examples
// Create a permutation where 5->0 and 0->1, others stay in place where possible
let mappings = vec![(5, 0), (0, 1)];
let p = Permutation::from_mappings(mappings.iter().copied(), 6).unwrap();
assert_eq!(p.map(), &[1, 5, 2, 3, 4, 0]);
// Verify the specific mappings work
assert_eq!(p[5], 0); // 5 -> 0
assert_eq!(p[0], 1); // 0 -> 1