File tree Expand file tree Collapse file tree 2 files changed +15
-21
lines changed Expand file tree Collapse file tree 2 files changed +15
-21
lines changed Original file line number Diff line number Diff line change @@ -280,7 +280,7 @@ fn convert_tokens<C: TokenConvertor>(conv: &mut C) -> tt::Subtree {
280
280
parent. subtree . token_trees . extend ( entry. subtree . token_trees ) ;
281
281
}
282
282
283
- let subtree = stack. into_first ( ) . subtree ;
283
+ let subtree = stack. into_last ( ) . subtree ;
284
284
if let [ tt:: TokenTree :: Subtree ( first) ] = & * subtree. token_trees {
285
285
first. clone ( )
286
286
} else {
Original file line number Diff line number Diff line change 1
- //! A [`Vec`] that is guaranteed to at least contain one element .
1
+ //! See [`NonEmptyVec`] .
2
2
3
- pub struct NonEmptyVec < T > ( Vec < T > ) ;
3
+ /// A [`Vec`] that is guaranteed to at least contain one element.
4
+ pub struct NonEmptyVec < T > {
5
+ first : T ,
6
+ rest : Vec < T > ,
7
+ }
4
8
5
9
impl < T > NonEmptyVec < T > {
6
10
#[ inline]
7
- pub fn new ( initial : T ) -> Self {
8
- NonEmptyVec ( vec ! [ initial ] )
11
+ pub fn new ( first : T ) -> Self {
12
+ NonEmptyVec { first , rest : Vec :: new ( ) }
9
13
}
10
14
11
15
#[ inline]
12
16
pub fn last_mut ( & mut self ) -> & mut T {
13
- match self . 0 . last_mut ( ) {
14
- Some ( it) => it,
15
- None => unreachable ! ( ) ,
16
- }
17
+ self . rest . last_mut ( ) . unwrap_or ( & mut self . first )
17
18
}
18
19
19
20
#[ inline]
20
21
pub fn pop ( & mut self ) -> Option < T > {
21
- if self . 0 . len ( ) <= 1 {
22
- None
23
- } else {
24
- self . 0 . pop ( )
25
- }
22
+ self . rest . pop ( )
26
23
}
27
24
28
25
#[ inline]
29
26
pub fn push ( & mut self , value : T ) {
30
- self . 0 . push ( value)
27
+ self . rest . push ( value)
31
28
}
32
29
33
30
#[ inline]
34
31
pub fn len ( & self ) -> usize {
35
- self . 0 . len ( )
32
+ 1 + self . rest . len ( )
36
33
}
37
34
38
35
#[ inline]
39
- pub fn into_first ( mut self ) -> T {
40
- match self . 0 . pop ( ) {
41
- Some ( it) => it,
42
- None => unreachable ! ( ) ,
43
- }
36
+ pub fn into_last ( mut self ) -> T {
37
+ self . rest . pop ( ) . unwrap_or ( self . first )
44
38
}
45
39
}
You can’t perform that action at this time.
0 commit comments