@@ -3,7 +3,7 @@ use std::{
33 ops:: { DerefMut , Index } ,
44} ;
55
6- use serde:: de ;
6+ use serde:: { de , Deserialize } ;
77
88use crate :: { de:: PathDeserializer , Resource , ResourcePath } ;
99
@@ -24,8 +24,13 @@ impl Default for PathItem {
2424/// If resource path contains variable patterns, `Path` stores them.
2525#[ derive( Debug , Clone , Default ) ]
2626pub struct Path < T > {
27+ /// Full path representation.
2728 path : T ,
29+
30+ /// Number of characters in `path` that have been processed into `segments`.
2831 pub ( crate ) skip : u16 ,
32+
33+ /// List of processed dynamic segments; name->value pairs.
2934 pub ( crate ) segments : Vec < ( Cow < ' static , str > , PathItem ) > ,
3035}
3136
@@ -83,8 +88,8 @@ impl<T: ResourcePath> Path<T> {
8388 /// Set new path.
8489 #[ inline]
8590 pub fn set ( & mut self , path : T ) {
86- self . skip = 0 ;
8791 self . path = path;
92+ self . skip = 0 ;
8893 self . segments . clear ( ) ;
8994 }
9095
@@ -103,7 +108,7 @@ impl<T: ResourcePath> Path<T> {
103108
104109 pub ( crate ) fn add ( & mut self , name : impl Into < Cow < ' static , str > > , value : PathItem ) {
105110 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 ) ) ) ,
107112 PathItem :: Segment ( begin, end) => self . segments . push ( (
108113 name. into ( ) ,
109114 PathItem :: Segment ( self . skip + begin, self . skip + end) ,
@@ -168,9 +173,13 @@ impl<T: ResourcePath> Path<T> {
168173 }
169174 }
170175
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 ) )
174183 }
175184}
176185
0 commit comments