@@ -240,10 +240,18 @@ impl FromStr for BranchName {
240
240
/// File name of a patch
241
241
#[ nutype(
242
242
validate( predicate = |p| !p. as_os_str( ) . is_empty( ) ) ,
243
- derive( Hash , Eq , PartialEq , Debug , AsRef , Deserialize , Clone , FromStr )
243
+ derive( Hash , Eq , PartialEq , Debug , AsRef , Deserialize , Clone , FromStr , TryFrom )
244
244
) ]
245
245
pub struct PatchName ( PathBuf ) ;
246
246
247
+ impl TryFrom < & str > for PatchName {
248
+ type Error = PatchNameError ;
249
+
250
+ fn try_from ( value : & str ) -> Result < Self , Self :: Error > {
251
+ PatchName :: try_new ( PathBuf :: from ( value) )
252
+ }
253
+ }
254
+
247
255
impl Display for PatchName {
248
256
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
249
257
write ! ( f, "{}" , self . as_ref( ) . display( ) )
@@ -258,8 +266,9 @@ impl Display for PatchName {
258
266
) ]
259
267
pub struct Commit ( String ) ;
260
268
261
- /// Does not check if the commit hash exists, just checks if it is potentially
262
- /// valid A commit hash can consist of `a-f` and `0-9` characters
269
+ /// Does not check if the commit exists, just checks if it is potentially valid
270
+ ///
271
+ /// A commit hash can consist of `a-f` and `0-9` characters
263
272
pub fn is_valid_commit_hash ( hash : & str ) -> bool {
264
273
hash. chars ( ) . all ( |ch| ch. is_ascii_hexdigit ( ) )
265
274
}
@@ -375,8 +384,8 @@ patches = ['remove-tab']"#;
375
384
pretty_assertions:: assert_eq!(
376
385
conf,
377
386
Config {
378
- local_branch: BranchName :: try_new ( "patchy" . to_string ( ) ) . unwrap( ) ,
379
- patches: indexset![ PatchName :: try_new ( "remove-tab" . into ( ) ) . unwrap( ) ] ,
387
+ local_branch: "patchy" . try_into ( ) . unwrap( ) ,
388
+ patches: indexset![ "remove-tab" . try_into ( ) . unwrap( ) ] ,
380
389
pull_requests: vec![
381
390
PullRequest {
382
391
number: 10000 . try_into( ) . unwrap( ) ,
@@ -388,17 +397,17 @@ patches = ['remove-tab']"#;
388
397
} ,
389
398
PullRequest {
390
399
number: 454 . try_into( ) . unwrap( ) ,
391
- commit: Some ( Commit :: try_new ( "a1b2c3" ) . unwrap( ) )
400
+ commit: Some ( "a1b2c3" . try_into ( ) . unwrap( ) )
392
401
} ,
393
402
PullRequest {
394
403
number: 1 . try_into( ) . unwrap( ) ,
395
- commit: Some ( Commit :: try_new ( "a1b2c3" ) . unwrap( ) )
404
+ commit: Some ( "a1b2c3" . try_into ( ) . unwrap( ) )
396
405
} ,
397
406
] ,
398
407
branches: vec![ ] ,
399
408
remote_branch: Branch {
400
- name: BranchName :: try_new ( "master" ) . unwrap( ) ,
401
- commit: Some ( Commit :: try_new ( "a1b2c4" ) . unwrap( ) )
409
+ name: "master" . try_into ( ) . unwrap( ) ,
410
+ commit: Some ( "a1b2c4" . try_into ( ) . unwrap( ) )
402
411
} ,
403
412
repo: "helix-editor/helix" . to_string( )
404
413
}
0 commit comments