@@ -3,7 +3,7 @@ use std::{
3
3
ops:: { DerefMut , Index } ,
4
4
} ;
5
5
6
- use serde:: de ;
6
+ use serde:: { de , Deserialize } ;
7
7
8
8
use crate :: { de:: PathDeserializer , Resource , ResourcePath } ;
9
9
@@ -24,8 +24,13 @@ impl Default for PathItem {
24
24
/// If resource path contains variable patterns, `Path` stores them.
25
25
#[ derive( Debug , Clone , Default ) ]
26
26
pub struct Path < T > {
27
+ /// Full path representation.
27
28
path : T ,
29
+
30
+ /// Number of characters in `path` that have been processed into `segments`.
28
31
pub ( crate ) skip : u16 ,
32
+
33
+ /// List of processed dynamic segments; name->value pairs.
29
34
pub ( crate ) segments : Vec < ( Cow < ' static , str > , PathItem ) > ,
30
35
}
31
36
@@ -83,8 +88,8 @@ impl<T: ResourcePath> Path<T> {
83
88
/// Set new path.
84
89
#[ inline]
85
90
pub fn set ( & mut self , path : T ) {
86
- self . skip = 0 ;
87
91
self . path = path;
92
+ self . skip = 0 ;
88
93
self . segments . clear ( ) ;
89
94
}
90
95
@@ -103,7 +108,7 @@ impl<T: ResourcePath> Path<T> {
103
108
104
109
pub ( crate ) fn add ( & mut self , name : impl Into < Cow < ' static , str > > , value : PathItem ) {
105
110
match value {
106
- PathItem :: Static ( s ) => self . segments . push ( ( name. into ( ) , PathItem :: Static ( s ) ) ) ,
111
+ PathItem :: Static ( seg ) => self . segments . push ( ( name. into ( ) , PathItem :: Static ( seg ) ) ) ,
107
112
PathItem :: Segment ( begin, end) => self . segments . push ( (
108
113
name. into ( ) ,
109
114
PathItem :: Segment ( self . skip + begin, self . skip + end) ,
@@ -168,9 +173,13 @@ impl<T: ResourcePath> Path<T> {
168
173
}
169
174
}
170
175
171
- /// Try to deserialize matching parameters to a specified type `U`
172
- pub fn load < ' de , U : serde:: Deserialize < ' de > > ( & ' de self ) -> Result < U , de:: value:: Error > {
173
- de:: Deserialize :: deserialize ( PathDeserializer :: new ( self ) )
176
+ /// Deserializes matching parameters to a specified type `U`.
177
+ ///
178
+ /// # Errors
179
+ ///
180
+ /// Returns error when dynamic path segments cannot be deserialized into a `U` type.
181
+ pub fn load < ' de , U : Deserialize < ' de > > ( & ' de self ) -> Result < U , de:: value:: Error > {
182
+ Deserialize :: deserialize ( PathDeserializer :: new ( self ) )
174
183
}
175
184
}
176
185
0 commit comments