@@ -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 , Feature , Features , 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,34 @@ impl Dependency {
182164 }
183165 }
184166
167+ pub fn serialized (
168+ & self ,
169+ unstable_flags : & CliUnstable ,
170+ features : & Features ,
171+ ) -> SerializedDependency {
172+ SerializedDependency {
173+ name : self . package_name ( ) ,
174+ source : self . source_id ( ) ,
175+ req : self . version_req ( ) . to_string ( ) ,
176+ kind : self . kind ( ) ,
177+ optional : self . is_optional ( ) ,
178+ uses_default_features : self . uses_default_features ( ) ,
179+ features : self . features ( ) . to_vec ( ) ,
180+ target : self . inner . platform . clone ( ) ,
181+ rename : self . explicit_name_in_toml ( ) ,
182+ registry : self . registry_id ( ) . as_ref ( ) . map ( |sid| sid. url ( ) . to_string ( ) ) ,
183+ path : self . source_id ( ) . local_path ( ) ,
184+ artifact : self . inner . artifact . clone ( ) ,
185+ public : if unstable_flags. public_dependency
186+ || features. is_enabled ( Feature :: public_dependency ( ) )
187+ {
188+ Some ( self . inner . public )
189+ } else {
190+ None
191+ } ,
192+ }
193+ }
194+
185195 pub fn version_req ( & self ) -> & OptVersionReq {
186196 & self . inner . req
187197 }
0 commit comments