specialize.rs - source
Description: Source of the Rust file `library/core/src/slice/specialize.rs`.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23

    pub(super) trait SpecFill<T> {
        fn spec_fill(&mut self, value: T);
    }

    impl<T: Clone> SpecFill<T> for [T] {
        default fn spec_fill(&mut self, value: T) {
            if let Some((last, elems)) = self.split_last_mut() {
                for el in elems {
                    el.clone_from(&value);
                }

                *last = value
            }
        }
    }

    impl<T: Copy> SpecFill<T> for [T] {
        fn spec_fill(&mut self, value: T) {
            for item in self.iter_mut() {
                *item = value;
            }
        }
    }