@@ -8,12 +8,13 @@ use crate::dist::temp;
8
8
use crate :: errors:: * ;
9
9
use crate :: utils:: utils;
10
10
11
+ use lazy_static:: lazy_static;
12
+ use regex:: Regex ;
13
+
11
14
use std:: env;
12
15
use std:: fmt;
13
16
use std:: path:: Path ;
14
17
15
- use regex:: Regex ;
16
-
17
18
pub const DEFAULT_DIST_SERVER : & str = "https://static.rust-lang.org" ;
18
19
19
20
// Deprecated
@@ -223,15 +224,17 @@ impl PartialTargetTriple {
223
224
// we can count on all triple components being
224
225
// delineated by it.
225
226
let name = format ! ( "-{}" , name) ;
226
- let pattern = format ! (
227
- r"^(?:-({}))?(?:-({}))?(?:-({}))?$" ,
228
- LIST_ARCHS . join( "|" ) ,
229
- LIST_OSES . join( "|" ) ,
230
- LIST_ENVS . join( "|" )
231
- ) ;
232
-
233
- let re = Regex :: new ( & pattern) . unwrap ( ) ;
234
- re. captures ( & name) . map ( |c| {
227
+ lazy_static ! {
228
+ /// This is an example for using doc comment attributes
229
+ static ref PATTERN : String = format!(
230
+ r"^(?:-({}))?(?:-({}))?(?:-({}))?$" ,
231
+ LIST_ARCHS . join( "|" ) ,
232
+ LIST_OSES . join( "|" ) ,
233
+ LIST_ENVS . join( "|" )
234
+ ) ;
235
+ static ref RE : Regex = Regex :: new( & PATTERN ) . unwrap( ) ;
236
+ }
237
+ RE . captures ( & name) . map ( |c| {
235
238
fn fn_map ( s : & str ) -> Option < String > {
236
239
if s == "" {
237
240
None
@@ -251,21 +254,22 @@ impl PartialTargetTriple {
251
254
252
255
impl PartialToolchainDesc {
253
256
pub fn from_str ( name : & str ) -> Result < Self > {
254
- let channels = [
257
+ const CHANNELS : & [ & str ] = & [
255
258
"nightly" ,
256
259
"beta" ,
257
260
"stable" ,
258
261
r"\d{1}\.\d{1}\.\d{1}" ,
259
262
r"\d{1}\.\d{2}\.\d{1}" ,
260
263
] ;
261
264
262
- let pattern = format ! (
263
- r"^({})(?:-(\d{{4}}-\d{{2}}-\d{{2}}))?(?:-(.*))?$" ,
264
- channels. join( "|" )
265
- ) ;
266
-
267
- let re = Regex :: new ( & pattern) . unwrap ( ) ;
268
- let d = re. captures ( name) . map ( |c| {
265
+ lazy_static ! {
266
+ static ref PATTERN : String = format!(
267
+ r"^({})(?:-(\d{{4}}-\d{{2}}-\d{{2}}))?(?:-(.*))?$" ,
268
+ CHANNELS . join( "|" )
269
+ ) ;
270
+ static ref RE : Regex = Regex :: new( & PATTERN ) . unwrap( ) ;
271
+ }
272
+ let d = RE . captures ( name) . map ( |c| {
269
273
fn fn_map ( s : & str ) -> Option < String > {
270
274
if s == "" {
271
275
None
@@ -341,21 +345,23 @@ impl PartialToolchainDesc {
341
345
342
346
impl ToolchainDesc {
343
347
pub fn from_str ( name : & str ) -> Result < Self > {
344
- let channels = [
348
+ const CHANNELS : & [ & str ] = & [
345
349
"nightly" ,
346
350
"beta" ,
347
351
"stable" ,
348
352
r"\d{1}\.\d{1}\.\d{1}" ,
349
353
r"\d{1}\.\d{2}\.\d{1}" ,
350
354
] ;
351
355
352
- let pattern = format ! (
353
- r"^({})(?:-(\d{{4}}-\d{{2}}-\d{{2}}))?-(.*)?$" ,
354
- channels. join( "|" ) ,
355
- ) ;
356
+ lazy_static ! {
357
+ static ref PATTERN : String = format!(
358
+ r"^({})(?:-(\d{{4}}-\d{{2}}-\d{{2}}))?-(.*)?$" ,
359
+ CHANNELS . join( "|" ) ,
360
+ ) ;
361
+ static ref RE : Regex = Regex :: new( & PATTERN ) . unwrap( ) ;
362
+ }
356
363
357
- let re = Regex :: new ( & pattern) . unwrap ( ) ;
358
- re. captures ( name)
364
+ RE . captures ( name)
359
365
. map ( |c| {
360
366
fn fn_map ( s : & str ) -> Option < String > {
361
367
if s == "" {
0 commit comments