1
+ use std:: borrow:: Cow ;
1
2
use std:: collections:: HashMap ;
2
3
use std:: fmt:: { Debug , Formatter } ;
3
4
use std:: sync:: Arc ;
@@ -505,36 +506,27 @@ impl From<Pos> for async_graphql::Pos {
505
506
506
507
#[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
507
508
#[ serde( untagged) ]
508
- pub enum PathSegment {
509
+ pub enum PathSegment < ' a > {
509
510
/// A field in an object.
510
- Field ( String ) ,
511
+ Field ( Cow < ' a , String > ) ,
511
512
/// An index in a list.
512
513
Index ( usize ) ,
513
514
}
514
515
515
- impl From < async_graphql:: PathSegment > for PathSegment {
516
+ impl From < async_graphql:: PathSegment > for PathSegment < ' static > {
516
517
fn from ( value : async_graphql:: PathSegment ) -> Self {
517
518
match value {
518
- async_graphql:: PathSegment :: Field ( field) => PathSegment :: Field ( field) ,
519
+ async_graphql:: PathSegment :: Field ( field) => PathSegment :: Field ( Cow :: Owned ( field) ) ,
519
520
async_graphql:: PathSegment :: Index ( index) => PathSegment :: Index ( index) ,
520
521
}
521
522
}
522
523
}
523
524
524
- impl From < PathSegment > for async_graphql:: PathSegment {
525
- fn from ( val : PathSegment ) -> Self {
526
- match val {
527
- PathSegment :: Field ( field) => async_graphql:: PathSegment :: Field ( field) ,
528
- PathSegment :: Index ( index) => async_graphql:: PathSegment :: Index ( index) ,
529
- }
530
- }
531
- }
532
-
533
525
#[ derive( Debug , Serialize , Clone ) ]
534
526
pub struct Positioned < Value > {
535
527
pub value : Value ,
536
528
pub pos : Pos ,
537
- pub path : Vec < PathSegment > ,
529
+ pub path : Vec < PathSegment < ' static > > ,
538
530
}
539
531
540
532
impl < Value > Positioned < Value > {
@@ -547,7 +539,7 @@ impl<Value> Positioned<Value>
547
539
where
548
540
Value : Clone ,
549
541
{
550
- pub fn with_path ( & mut self , path : Vec < PathSegment > ) -> Self {
542
+ pub fn with_path ( & mut self , path : Vec < PathSegment < ' static > > ) -> Self {
551
543
Self { value : self . value . clone ( ) , pos : self . pos , path }
552
544
}
553
545
}
0 commit comments