@@ -41,7 +41,7 @@ pub struct GWasmBinary<'a> {
41
41
/// wasm: &[],
42
42
/// };
43
43
/// let workspace = tempdir().unwrap();
44
- /// let task = TaskBuilder::new (&workspace, binary).build();
44
+ /// let task = TaskBuilder::try_new (&workspace, binary).unwrap( ).build();
45
45
/// assert!(task.is_ok());
46
46
/// assert!(task.unwrap().options().subtasks().next().is_none());
47
47
/// ```
@@ -66,6 +66,10 @@ pub struct TaskBuilder<'a> {
66
66
67
67
impl < ' a > TaskBuilder < ' a > {
68
68
/// Creates new `TaskBuilder` from workspace `Path` and `GWasmBinary`
69
+ #[ deprecated(
70
+ since = "0.3.0" ,
71
+ note = "Use try_new instead, which properly handles relative paths"
72
+ ) ]
69
73
pub fn new < P : AsRef < Path > > ( workspace : P , binary : GWasmBinary < ' a > ) -> Self {
70
74
Self {
71
75
binary,
@@ -81,6 +85,13 @@ impl<'a> TaskBuilder<'a> {
81
85
}
82
86
}
83
87
88
+ /// Creates new `TaskBuilder` from workspace `Path` and `GWasmBinary`
89
+ pub fn try_new < P : AsRef < Path > > ( workspace : P , binary : GWasmBinary < ' a > ) -> Result < Self > {
90
+ let abspath = workspace. as_ref ( ) . canonicalize ( ) ?;
91
+ #[ allow( deprecated) ]
92
+ Ok ( Self :: new ( abspath, binary) )
93
+ }
94
+
84
95
/// Sets task's name
85
96
pub fn name < S : AsRef < str > > ( mut self , name : S ) -> Self {
86
97
self . name = Some ( name. as_ref ( ) . to_owned ( ) ) ;
@@ -226,7 +237,7 @@ impl<'a> TaskBuilder<'a> {
226
237
/// wasm: &[],
227
238
/// };
228
239
/// let workspace = tempdir().unwrap();
229
- /// let task = TaskBuilder::new (&workspace, binary).build().unwrap();
240
+ /// let task = TaskBuilder::try_new (&workspace, binary).unwrap( ).build().unwrap();
230
241
/// let json_manifest = json!(task);
231
242
/// ```
232
243
///
@@ -432,7 +443,7 @@ impl Subtask {
432
443
/// wasm: &[],
433
444
/// };
434
445
/// let workspace = tempdir().unwrap();
435
- /// let task = TaskBuilder::new (&workspace, binary).build().unwrap();
446
+ /// let task = TaskBuilder::try_new (&workspace, binary).unwrap( ).build().unwrap();
436
447
/// let computed_task: Result<ComputedTask, _> = task.try_into();
437
448
///
438
449
/// assert!(computed_task.is_ok());
0 commit comments