comparison rust/hg-core/src/utils.rs @ 42748:7cae6bc29ff9

rust-parsers: switch to parse/pack_dirstate to mutate-on-loop Both `parse_dirstate` and `pack_dirstate` can operate directly on the data they're passed, which prevents the creation of intermediate data structures, simplifies the function signatures and reduces boilerplate. They are exposed directly to the Python for now, but a later patch will make use of them inside `hg-core`. Differential Revision: https://phab.mercurial-scm.org/D6628
author Raphaël Gomès <rgomes@octobus.net>
date Tue, 09 Jul 2019 11:49:49 +0200
parents 2f760da140ee
children 4b3b27d567d5
comparison
equal deleted inserted replaced
42747:760a7851e9ba 42748:7cae6bc29ff9
1 pub mod files; 1 pub mod files;
2
3 use std::convert::AsMut;
4
5 /// Takes a slice and copies it into an array.
6 ///
7 /// # Panics
8 ///
9 /// Will panic if the slice and target array don't have the same length.
10 pub fn copy_into_array<A, T>(slice: &[T]) -> A
11 where
12 A: Sized + Default + AsMut<[T]>,
13 T: Copy,
14 {
15 let mut a = Default::default();
16 <A as AsMut<[T]>>::as_mut(&mut a).copy_from_slice(slice);
17 a
18 }
2 19
3 /// Replaces the `from` slice with the `to` slice inside the `buf` slice. 20 /// Replaces the `from` slice with the `to` slice inside the `buf` slice.
4 /// 21 ///
5 /// # Examples 22 /// # Examples
6 /// 23 ///