Skip to content

Commit 6852898

Browse files
committed
Mark MappingTarget as #[non_exhaustive] for increased semver flexibility
This will allow us to add new enum variants in the future without breaking semver compatibility. See https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute Since we already added an enum variant since v0.18.3, now is a good time to mark it as `#[non_exhaustive]`.
1 parent f89869b commit 6852898

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
- Deprecate `HighlightingAssets::syntaxes()` and `HighlightingAssets::syntax_for_file_name()`. Use `HighlightingAssets::get_syntaxes()` and `HighlightingAssets::get_syntax_for_path()` instead. They return a `Result` which is needed for upcoming lazy-loading work to improve startup performance. They also return which `SyntaxSet` the returned `SyntaxReference` belongs to. See #1747, #1755, #1776, #1862 (@Enselic)
5454
- Remove `HighlightingAssets::from_files` and `HighlightingAssets::save_to_cache`. Instead of calling the former and then the latter you now make a single call to `bat::assets::build`. See #1802, #1971 (@Enselic)
5555
- Replace the `error::Error(error::ErrorKind, _)` struct and enum with an `error::Error` enum. `Error(ErrorKind::UnknownSyntax, _)` becomes `Error::UnknownSyntax`, etc. Also remove the `error::ResultExt` trait. These changes stem from replacing `error-chain` with `thiserror`. See #1820 (@Enselic)
56-
- Add new `MappingTarget` enum variant `MapExtensionToUnknown`. Refer to its docummentation for more information. Clients are adviced to treat `MapExtensionToUnknown` the same as `MapToUnknown` in exhaustive matches. See #1703 (@cbolgiano)
56+
- Add new `MappingTarget` enum variant `MapExtensionToUnknown`. Refer to its documentation for more information. Also mark `MappingTarget` as `#[non_exhaustive]` since more enum variants might be added in the future. See #1703 (@cbolgiano), #2012 (@Enselic)
5757

5858

5959

src/bin/bat/main.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,9 @@ fn get_syntax_mapping_to_paths<'a>(
7474
) -> HashMap<&'a str, Vec<String>> {
7575
let mut map = HashMap::new();
7676
for mapping in mappings {
77-
match mapping {
78-
(_, MappingTarget::MapToUnknown) => {}
79-
(_, MappingTarget::MapExtensionToUnknown) => {}
80-
(matcher, MappingTarget::MapTo(s)) => {
81-
let globs = map.entry(*s).or_insert_with(Vec::new);
82-
globs.push(matcher.glob().glob().into());
83-
}
77+
if let (matcher, MappingTarget::MapTo(s)) = mapping {
78+
let globs = map.entry(*s).or_insert_with(Vec::new);
79+
globs.push(matcher.glob().glob().into());
8480
}
8581
}
8682
map

src/syntax_mapping.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use globset::{Candidate, GlobBuilder, GlobMatcher};
88
pub mod ignored_suffixes;
99

1010
#[derive(Debug, Clone, Copy, PartialEq)]
11+
#[non_exhaustive]
1112
pub enum MappingTarget<'a> {
1213
/// For mapping a path to a specific syntax.
1314
MapTo(&'a str),

0 commit comments

Comments
 (0)