@@ -9,7 +9,7 @@ use std::sync::Arc;
99use tracing:: trace;
1010
1111use crate :: core:: compiler:: { CompileKind , CompileTarget } ;
12- use crate :: core:: { PackageId , SourceId , Summary } ;
12+ use crate :: core:: { CliUnstable , PackageId , SourceId , Summary } ;
1313use crate :: util:: errors:: CargoResult ;
1414use crate :: util:: interning:: InternedString ;
1515use crate :: util:: OptVersionReq ;
@@ -52,50 +52,32 @@ struct Inner {
5252}
5353
5454#[ derive( Serialize ) ]
55- struct SerializedDependency < ' a > {
56- name : & ' a str ,
55+ pub struct SerializedDependency {
56+ name : InternedString ,
5757 source : SourceId ,
5858 req : String ,
5959 kind : DepKind ,
60- rename : Option < & ' a str > ,
60+ rename : Option < InternedString > ,
6161
6262 optional : bool ,
6363 uses_default_features : bool ,
64- features : & ' a [ InternedString ] ,
64+ features : Vec < InternedString > ,
6565 #[ serde( skip_serializing_if = "Option::is_none" ) ]
66- artifact : Option < & ' a Artifact > ,
67- target : Option < & ' a Platform > ,
66+ artifact : Option < Artifact > ,
67+ target : Option < Platform > ,
6868 /// The registry URL this dependency is from.
6969 /// If None, then it comes from the default registry (crates.io).
70- registry : Option < & ' a str > ,
70+ registry : Option < String > ,
7171
7272 /// The file system path for a local path dependency.
7373 #[ serde( skip_serializing_if = "Option::is_none" ) ]
7474 path : Option < PathBuf > ,
75- }
7675
77- impl ser:: Serialize for Dependency {
78- fn serialize < S > ( & self , s : S ) -> Result < S :: Ok , S :: Error >
79- where
80- S : ser:: Serializer ,
81- {
82- let registry_id = self . registry_id ( ) ;
83- SerializedDependency {
84- name : & * self . package_name ( ) ,
85- source : self . source_id ( ) ,
86- req : self . version_req ( ) . to_string ( ) ,
87- kind : self . kind ( ) ,
88- optional : self . is_optional ( ) ,
89- uses_default_features : self . uses_default_features ( ) ,
90- features : self . features ( ) ,
91- target : self . platform ( ) ,
92- rename : self . explicit_name_in_toml ( ) . map ( |s| s. as_str ( ) ) ,
93- registry : registry_id. as_ref ( ) . map ( |sid| sid. url ( ) . as_str ( ) ) ,
94- path : self . source_id ( ) . local_path ( ) ,
95- artifact : self . artifact ( ) ,
96- }
97- . serialize ( s)
98- }
76+ /// `public` flag is unset if `-Zpublic-dependency` is not enabled
77+ ///
78+ /// Once that feature is stabilized, `public` will not need to be `Option`
79+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
80+ public : Option < bool > ,
9981}
10082
10183#[ derive( PartialEq , Eq , Hash , Ord , PartialOrd , Clone , Debug , Copy ) ]
@@ -182,6 +164,26 @@ impl Dependency {
182164 }
183165 }
184166
167+ pub fn serialized ( & self , unstable_flags : & CliUnstable ) -> SerializedDependency {
168+ SerializedDependency {
169+ name : self . package_name ( ) ,
170+ source : self . source_id ( ) ,
171+ req : self . version_req ( ) . to_string ( ) ,
172+ kind : self . kind ( ) ,
173+ optional : self . is_optional ( ) ,
174+ uses_default_features : self . uses_default_features ( ) ,
175+ features : self . features ( ) . to_vec ( ) ,
176+ target : self . inner . platform . clone ( ) ,
177+ rename : self . explicit_name_in_toml ( ) ,
178+ registry : self . registry_id ( ) . as_ref ( ) . map ( |sid| sid. url ( ) . to_string ( ) ) ,
179+ path : self . source_id ( ) . local_path ( ) ,
180+ artifact : self . inner . artifact . clone ( ) ,
181+ public : unstable_flags
182+ . public_dependency
183+ . then_some ( self . inner . public ) ,
184+ }
185+ }
186+
185187 pub fn version_req ( & self ) -> & OptVersionReq {
186188 & self . inner . req
187189 }
0 commit comments