File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,3 +28,7 @@ rayon = "1.8.1"
2828serde = { version = " 1.0.197" , features = [" derive" ] }
2929serde_json = " 1.0.114"
3030toml = " 0.8.10"
31+
32+ [build-dependencies ]
33+ serde = { version = " 1.0.215" , features = [" derive" ] }
34+ toml = " 0.8.19"
Original file line number Diff line number Diff line change 1- use std:: fs;
1+ #[ derive( Deserialize ) ]
2+ struct Toml {
3+ package : Package ,
4+ }
5+
6+ #[ derive( Deserialize ) ]
7+ struct Package {
8+ version : String ,
9+ }
210
311fn main ( ) {
412 println ! ( "cargo:rerun-if-changed=Cargo.toml" ) ;
513
614 println ! (
715 "cargo:rustc-env=CARGO_PKG_VERSION={}" ,
8- fs:: read_to_string( "Cargo.toml" )
9- . expect( "Failed to read Cargo.toml." )
10- . lines( )
11- . find( |line| line. starts_with( "version" ) )
12- . unwrap( )
13- . split( '=' )
14- . nth( 1 )
15- . expect( "Invalid version line format." )
16- . trim( )
17- . trim_matches( '"' )
16+ toml:: from_str:: <Toml >( & std:: fs:: read_to_string( "Cargo.toml" ) . expect( "Cannot Cargo.toml." ) )
17+ . expect( "Cannot toml." )
18+ . package
19+ . version
1820 ) ;
1921}
22+
23+ use serde:: Deserialize ;
You can’t perform that action at this time.
0 commit comments