@@ -14,7 +14,7 @@ use crate::parser::Rule;
1414use pest:: Span ;
1515use pest_ast:: FromPest ;
1616use serde:: Serialize ;
17- use std:: { borrow :: Cow , fmt} ;
17+ use std:: fmt;
1818
1919/// Represents a type statement in the AST.
2020#[ derive( Debug , Clone , Serialize , FromPest ) ]
@@ -1142,7 +1142,7 @@ pub struct UseItems<'a> {
11421142 /// The opening brace of the statement.
11431143 pub open : OpenBrace < ' a > ,
11441144 /// The items being used.
1145- pub list : Vec < Ident < ' a > > ,
1145+ pub list : Vec < UseItem < ' a > > ,
11461146 /// The closing brace of the use items.
11471147 pub close : CloseBrace < ' a > ,
11481148}
@@ -1166,6 +1166,51 @@ impl AstDisplay for UseItems<'_> {
11661166
11671167display ! ( UseItems ) ;
11681168
1169+ /// Represents an item being used in a use statement in the AST.
1170+ #[ derive( Debug , Clone , Serialize , FromPest ) ]
1171+ #[ pest_ast( rule( Rule :: UseItem ) ) ]
1172+ #[ serde( rename_all = "camelCase" ) ]
1173+ pub struct UseItem < ' a > {
1174+ /// The identifier of the item.
1175+ pub id : Ident < ' a > ,
1176+ /// The optional as clause of the item.
1177+ pub as_clause : std:: option:: Option < UseAsClause < ' a > > ,
1178+ }
1179+
1180+ impl AstDisplay for UseItem < ' _ > {
1181+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > , indenter : & mut Indenter ) -> fmt:: Result {
1182+ self . id . fmt ( f, indenter) ?;
1183+
1184+ if let Some ( as_clause) = & self . as_clause {
1185+ write ! ( f, " {as_clause}" ) ?;
1186+ }
1187+
1188+ Ok ( ( ) )
1189+ }
1190+ }
1191+
1192+ display ! ( UseItem ) ;
1193+
1194+ /// Represents an as clause in a use statement in the AST.
1195+ #[ derive( Debug , Clone , Serialize , FromPest ) ]
1196+ #[ pest_ast( rule( Rule :: UseAsClause ) ) ]
1197+ #[ serde( rename_all = "camelCase" ) ]
1198+ pub struct UseAsClause < ' a > {
1199+ /// The `as` keyword.
1200+ pub keyword : As < ' a > ,
1201+ /// The identifier of the as clause.
1202+ pub id : Ident < ' a > ,
1203+ }
1204+
1205+ impl AstDisplay for UseAsClause < ' _ > {
1206+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > , indenter : & mut Indenter ) -> fmt:: Result {
1207+ write ! ( f, "{keyword} " , keyword = self . keyword) ?;
1208+ self . id . fmt ( f, indenter)
1209+ }
1210+ }
1211+
1212+ display ! ( UseAsClause ) ;
1213+
11691214/// Represents a use path in the AST.
11701215#[ derive( Debug , Clone , Serialize , FromPest ) ]
11711216#[ pest_ast( rule( Rule :: UsePath ) ) ]
@@ -1524,11 +1569,11 @@ pub enum WorldRef<'a> {
15241569}
15251570
15261571impl < ' a > WorldRef < ' a > {
1527- /// Gets the full name of the world ref .
1528- pub fn name ( & self ) -> Cow < ' a , str > {
1572+ /// Gets the name of the world being referred to .
1573+ pub fn name ( & self ) -> & str {
15291574 match self {
1530- Self :: Ident ( id) => Cow :: Borrowed ( id. as_str ( ) ) ,
1531- Self :: Path ( path) => Cow :: Owned ( path. to_string ( ) ) ,
1575+ Self :: Ident ( id) => id. as_str ( ) ,
1576+ Self :: Path ( path) => path. as_str ( ) ,
15321577 }
15331578 }
15341579
0 commit comments