@@ -864,19 +864,36 @@ pub struct Function {
864864 pub arg_names : Vec < SmolStr > ,
865865}
866866
867- #[ derive( Debug , Clone , PartialEq ) ]
867+ #[ derive( Debug , Clone ) ]
868868pub enum StructName {
869869 None ,
870870 /// When declared in .slint as `struct Foo { }`, then the name is "Foo"
871- User ( SmolStr ) ,
871+ User {
872+ name : SmolStr ,
873+ /// When declared in .slint, this is the node of the declaration.
874+ node : syntax_nodes:: ObjectType ,
875+ } ,
872876 Native ( NativeType ) ,
873877}
874878
879+ impl PartialEq for StructName {
880+ fn eq ( & self , other : & Self ) -> bool {
881+ match ( self , other) {
882+ (
883+ Self :: User { name : l_user_name, node : _ } ,
884+ Self :: User { name : r_user_name, node : _ } ,
885+ ) => l_user_name == r_user_name,
886+ ( Self :: Native ( l0) , Self :: Native ( r0) ) => l0 == r0,
887+ _ => core:: mem:: discriminant ( self ) == core:: mem:: discriminant ( other) ,
888+ }
889+ }
890+ }
891+
875892impl StructName {
876893 pub fn slint_name ( & self ) -> Option < SmolStr > {
877894 match self {
878895 StructName :: None => None ,
879- StructName :: User ( name) => Some ( name. clone ( ) ) ,
896+ StructName :: User { name, .. } => Some ( name. clone ( ) ) ,
880897 StructName :: Native ( native_type) => native_type. slint_name ( ) ,
881898 }
882899 }
@@ -913,12 +930,19 @@ impl From<NativePublicType> for StructName {
913930pub struct Struct {
914931 pub fields : BTreeMap < SmolStr , Type > ,
915932 pub name : StructName ,
916- /// When declared in .slint, this is the node of the declaration.
917- pub node : Option < syntax_nodes:: ObjectType > ,
918933 /// derived
919934 pub rust_attributes : Option < Vec < SmolStr > > ,
920935}
921936
937+ impl Struct {
938+ pub fn node ( & self ) -> Option < & syntax_nodes:: ObjectType > {
939+ match & self . name {
940+ StructName :: User { node, .. } => Some ( node) ,
941+ _ => None ,
942+ }
943+ }
944+ }
945+
922946impl Display for Struct {
923947 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
924948 if let Some ( name) = & self . name . slint_name ( ) {
0 commit comments