Skip to content

Commit

Permalink
make RegexSet non-public
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdrz committed Nov 20, 2024
1 parent 727cf38 commit 14cc944
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
1 change: 0 additions & 1 deletion bindgen/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ pub use codegen::{
pub use features::{RustTarget, LATEST_STABLE_RUST};
pub use ir::annotations::FieldVisibilityKind;
pub use ir::function::Abi;
pub use regex_set::RegexSet;

use codegen::CodegenError;
use features::RustFeatures;
Expand Down
2 changes: 1 addition & 1 deletion bindgen/options/as_args.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::PathBuf;

use crate::RegexSet;
use crate::regex_set::RegexSet;

/// Trait used to turn [`crate::BindgenOptions`] fields into CLI args.
pub(super) trait AsArgs {
Expand Down
7 changes: 4 additions & 3 deletions bindgen/options/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use crate::{
AttributeInfo, DeriveInfo, ItemInfo, ParseCallbacks, TypeKind,
},
features::RUST_TARGET_STRINGS,
regex_set::RegexSet,
Abi, AliasVariation, Builder, CodegenConfig, EnumVariation,
FieldVisibilityKind, Formatter, MacroTypeVariation, NonCopyUnionStyle,
RegexSet, RustTarget, DEFAULT_ANON_FIELDS_PREFIX,
RustTarget, DEFAULT_ANON_FIELDS_PREFIX,
};
use clap::{
error::{Error, ErrorKind},
Expand Down Expand Up @@ -1180,7 +1181,7 @@ where
let name = emit_diagnostics.then_some(_name);

for (derives, regex) in custom_derives {
let mut regex_set = RegexSet::new();
let mut regex_set = RegexSet::default();
regex_set.insert(regex);

#[cfg(feature = "experimental")]
Expand Down Expand Up @@ -1258,7 +1259,7 @@ where
let name = emit_diagnostics.then_some(_name);

for (attributes, regex) in custom_attributes {
let mut regex_set = RegexSet::new();
let mut regex_set = RegexSet::default();
regex_set.insert(regex);

#[cfg(feature = "experimental")]
Expand Down
21 changes: 8 additions & 13 deletions bindgen/regex_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::cell::Cell;

/// A dynamic set of regular expressions.
#[derive(Clone, Debug, Default)]
pub struct RegexSet {
pub(crate) struct RegexSet {
items: Vec<Box<str>>,
/// Whether any of the items in the set was ever matched. The length of this
/// vector is exactly the length of `items`.
Expand All @@ -17,18 +17,13 @@ pub struct RegexSet {
}

impl RegexSet {
/// Create a new RegexSet
pub fn new() -> RegexSet {
RegexSet::default()
}

/// Is this set empty?
pub fn is_empty(&self) -> bool {
pub(crate) fn is_empty(&self) -> bool {
self.items.is_empty()
}

/// Insert a new regex into this set.
pub fn insert<S>(&mut self, string: S)
pub(crate) fn insert<S>(&mut self, string: S)
where
S: AsRef<str>,
{
Expand All @@ -38,13 +33,13 @@ impl RegexSet {
}

/// Returns slice of String from its field 'items'
pub fn get_items(&self) -> &[Box<str>] {
pub(crate) fn get_items(&self) -> &[Box<str>] {
&self.items
}

/// Returns an iterator over regexes in the set which didn't match any
/// strings yet.
pub fn unmatched_items(&self) -> impl Iterator<Item = &str> {
pub(crate) fn unmatched_items(&self) -> impl Iterator<Item = &str> {
self.items.iter().enumerate().filter_map(move |(i, item)| {
if !self.record_matches || self.matched[i].get() {
return None;
Expand All @@ -59,7 +54,7 @@ impl RegexSet {
/// Must be called before calling `matches()`, or it will always return
/// false.
#[inline]
pub fn build(&mut self, record_matches: bool) {
pub(crate) fn build(&mut self, record_matches: bool) {
self.build_inner(record_matches, None)
}

Expand All @@ -70,7 +65,7 @@ impl RegexSet {
/// Must be called before calling `matches()`, or it will always return
/// false.
#[inline]
pub fn build_with_diagnostics(
pub(crate) fn build_with_diagnostics(
&mut self,
record_matches: bool,
name: Option<&'static str>,
Expand Down Expand Up @@ -114,7 +109,7 @@ impl RegexSet {
}

/// Does the given `string` match any of the regexes in this set?
pub fn matches<S>(&self, string: S) -> bool
pub(crate) fn matches<S>(&self, string: S) -> bool
where
S: AsRef<str>,
{
Expand Down

0 comments on commit 14cc944

Please sign in to comment.