Skip to content

Commit

Permalink
Add 'Data::file_exact()': search-less file source.
Browse files Browse the repository at this point in the history
Resolves #94.
  • Loading branch information
nmathewson authored and SergioBenitez committed Mar 16, 2024
1 parent 5180f6d commit e7c9c35
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/providers/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ impl<F: Format> Data<F> {
/// the current working directory and all parent directories until the root,
/// and the first hit is used.
///
/// (If you don't want want to search parent directories,
/// use [`file_exact()`](Data::file_exact) instead.)
///
/// Nesting is not enabled by default; use [`Data::nested()`] to enable
/// nesting.
///
Expand Down Expand Up @@ -133,6 +136,19 @@ impl<F: Format> Data<F> {
Data::new(Source::File(find(path.as_ref())), Some(Profile::Default))
}

/// Returns a `Data` provider that sources its values by parsing the file at
/// `path` as format `F`. If `path` is relative, it is located relative
/// to the current working directory—no other directories are searched.
///
/// (If you want to search parent directories, use [`file()`](Data::file)
/// instead.)
///
/// Nesting is not enabled by default; use [`Data::nested()`] to enable
/// nesting.
pub fn file_exact<P:AsRef<Path>>(path: P) -> Self {
Data::new(Source::File(Some(path.as_ref().to_owned())), Some(Profile::Default))
}

/// Returns a `Data` provider that sources its values by parsing the string
/// `string` as format `F`. Nesting is not enabled by default; use
/// [`Data::nested()`] to enable nesting.
Expand Down Expand Up @@ -322,6 +338,13 @@ pub trait Format: Sized {
Data::file(path)
}

/// Returns a `Data` provider that sources its values by parsing the file at
/// `path` as format `Self`. See [`Data::file_exact()`] for more details. The
/// default implementation calls `Data::file_exact(path)`.
fn file_exact<P: AsRef<Path>>(path: P) -> Data<Self> {
Data::file_exact(path)
}

/// Returns a `Data` provider that sources its values by parsing `string` as
/// format `Self`. See [`Data::string()`] for more details. The default
/// implementation calls `Data::string(string)`.
Expand Down

0 comments on commit e7c9c35

Please sign in to comment.