Skip to content

Commit 3697935

Browse files
committed
Change rust project APIs to accept "impl AsRef<Path>" instead of "&str" for path arguments
1 parent b3f490f commit 3697935

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

rust/src/project.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ impl Project {
4141
///
4242
/// * `path` - Path to the project directory (.bnpr)
4343
/// * `name` - Name of the new project
44-
pub fn create(path: &str, name: &str) -> Option<Ref<Self>> {
45-
let path_raw = path.to_cstr();
44+
pub fn create(path: impl AsRef<Path>, name: &str) -> Option<Ref<Self>> {
45+
let path_raw = path.as_ref().to_cstr();
4646
let name_raw = name.to_cstr();
4747
let handle = unsafe { BNCreateProject(path_raw.as_ptr(), name_raw.as_ptr()) };
4848
NonNull::new(handle).map(|h| unsafe { Self::ref_from_raw(h) })
@@ -52,8 +52,8 @@ impl Project {
5252
/// Open an existing project
5353
///
5454
/// * `path` - Path to the project directory (.bnpr) or project metadata file (.bnpm)
55-
pub fn open_project(path: &str) -> Option<Ref<Self>> {
56-
let path_raw = path.to_cstr();
55+
pub fn open_project(path: impl AsRef<Path>) -> Option<Ref<Self>> {
56+
let path_raw = path.as_ref().to_cstr();
5757
let handle = unsafe { BNOpenProject(path_raw.as_ptr()) };
5858
NonNull::new(handle).map(|h| unsafe { Self::ref_from_raw(h) })
5959
}
@@ -146,7 +146,7 @@ impl Project {
146146
/// * `description` - Description for created root folder
147147
pub fn create_folder_from_path(
148148
&self,
149-
path: &str,
149+
path: impl AsRef<Path>,
150150
parent: Option<&ProjectFolder>,
151151
description: &str,
152152
) -> Result<Ref<ProjectFolder>, ()> {
@@ -161,15 +161,15 @@ impl Project {
161161
/// * `progress` - [`ProgressCallback`] that will be called as the [`ProjectFolder`] is being created
162162
pub fn create_folder_from_path_with_progress<PC>(
163163
&self,
164-
path: &str,
164+
path: impl AsRef<Path>,
165165
parent: Option<&ProjectFolder>,
166166
description: &str,
167167
mut progress: PC,
168168
) -> Result<Ref<ProjectFolder>, ()>
169169
where
170170
PC: ProgressCallback,
171171
{
172-
let path_raw = path.to_cstr();
172+
let path_raw = path.as_ref().to_cstr();
173173
let description_raw = description.to_cstr();
174174
let parent_ptr = parent.map(|p| p.handle.as_ptr()).unwrap_or(null_mut());
175175

@@ -300,7 +300,7 @@ impl Project {
300300
/// * `description` - Description to assign to the created file
301301
pub fn create_file_from_path(
302302
&self,
303-
path: &str,
303+
path: impl AsRef<Path>,
304304
folder: Option<&ProjectFolder>,
305305
name: &str,
306306
description: &str,
@@ -323,7 +323,7 @@ impl Project {
323323
/// * `progress` - [`ProgressCallback`] that will be called as the [`ProjectFile`] is being added
324324
pub fn create_file_from_path_with_progress<PC>(
325325
&self,
326-
path: &str,
326+
path: impl AsRef<Path>,
327327
folder: Option<&ProjectFolder>,
328328
name: &str,
329329
description: &str,
@@ -332,7 +332,7 @@ impl Project {
332332
where
333333
PC: ProgressCallback,
334334
{
335-
let path_raw = path.to_cstr();
335+
let path_raw = path.as_ref().to_cstr();
336336
let name_raw = name.to_cstr();
337337
let description_raw = description.to_cstr();
338338
let folder_ptr = folder.map(|p| p.handle.as_ptr()).unwrap_or(null_mut());
@@ -361,7 +361,7 @@ impl Project {
361361
/// * `creation_time` - Creation time of the file
362362
pub unsafe fn create_file_from_path_unsafe(
363363
&self,
364-
path: &str,
364+
path: impl AsRef<Path>,
365365
folder: Option<&ProjectFolder>,
366366
name: &str,
367367
description: &str,
@@ -391,7 +391,7 @@ impl Project {
391391
#[allow(clippy::too_many_arguments)]
392392
pub unsafe fn create_file_from_path_unsafe_with_progress<PC>(
393393
&self,
394-
path: &str,
394+
path: impl AsRef<Path>,
395395
folder: Option<&ProjectFolder>,
396396
name: &str,
397397
description: &str,
@@ -402,7 +402,7 @@ impl Project {
402402
where
403403
PC: ProgressCallback,
404404
{
405-
let path_raw = path.to_cstr();
405+
let path_raw = path.as_ref().to_cstr();
406406
let name_raw = name.to_cstr();
407407
let description_raw = description.to_cstr();
408408
let id_raw = id.to_cstr();

0 commit comments

Comments
 (0)