comparison rust/hg-core/src/dirstate/dirstate_map.rs @ 42799:5399532510ae

rust: simply use TryInto to convert slice to array Since our rust module depends on TryInto, there's no point to avoid using it. While rewriting copy_into_array(), I noticed CPython interface doesn't check the length of the p1/p2 values, which is marked as TODO.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 17 Aug 2019 11:37:42 +0900
parents 99dff4264524
children 1a535313ad1b
comparison
equal deleted inserted replaced
42798:99dff4264524 42799:5399532510ae
5 // This software may be used and distributed according to the terms of the 5 // This software may be used and distributed according to the terms of the
6 // GNU General Public License version 2 or any later version. 6 // GNU General Public License version 2 or any later version.
7 7
8 use crate::{ 8 use crate::{
9 dirstate::{parsers::PARENT_SIZE, EntryState}, 9 dirstate::{parsers::PARENT_SIZE, EntryState},
10 pack_dirstate, parse_dirstate, 10 pack_dirstate, parse_dirstate, CopyMap, DirsIterable, DirsMultiset,
11 utils::copy_into_array, 11 DirstateEntry, DirstateError, DirstateMapError, DirstateParents,
12 CopyMap, DirsIterable, DirsMultiset, DirstateEntry, DirstateError, 12 DirstateParseError, StateMap,
13 DirstateMapError, DirstateParents, DirstateParseError, StateMap,
14 }; 13 };
15 use core::borrow::Borrow; 14 use core::borrow::Borrow;
16 use std::collections::{HashMap, HashSet}; 15 use std::collections::{HashMap, HashSet};
16 use std::convert::TryInto;
17 use std::iter::FromIterator; 17 use std::iter::FromIterator;
18 use std::ops::Deref; 18 use std::ops::Deref;
19 use std::time::Duration; 19 use std::time::Duration;
20 20
21 pub type FileFoldMap = HashMap<Vec<u8>, Vec<u8>>; 21 pub type FileFoldMap = HashMap<Vec<u8>, Vec<u8>>;
258 return Ok(parents.clone()); 258 return Ok(parents.clone());
259 } 259 }
260 let parents; 260 let parents;
261 if file_contents.len() == PARENT_SIZE * 2 { 261 if file_contents.len() == PARENT_SIZE * 2 {
262 parents = DirstateParents { 262 parents = DirstateParents {
263 p1: copy_into_array(&file_contents[..PARENT_SIZE]), 263 p1: file_contents[..PARENT_SIZE].try_into().unwrap(),
264 p2: copy_into_array( 264 p2: file_contents[PARENT_SIZE..PARENT_SIZE * 2]
265 &file_contents[PARENT_SIZE..PARENT_SIZE * 2], 265 .try_into()
266 ), 266 .unwrap(),
267 }; 267 };
268 } else if file_contents.is_empty() { 268 } else if file_contents.is_empty() {
269 parents = DirstateParents { 269 parents = DirstateParents {
270 p1: NULL_ID, 270 p1: NULL_ID,
271 p2: NULL_ID, 271 p2: NULL_ID,