Skip to content

Commit be4e5d2

Browse files
hovinenbcopybara-github
authored andcommitted
Add some references to make StrMatcherConfigurator more discoverable.
Previously, finding this extension trait and its methods would require navigating manually through the documentation, which made nearly impossible to discover. These references call out specifically that one can use this trait to configure matching of strings in places where one constructs matchers which can be configued by it. PiperOrigin-RevId: 527889895
1 parent ab303ae commit be4e5d2

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

googletest/src/matchers/eq_matcher.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use std::{fmt::Debug, marker::PhantomData};
3737
/// ```
3838
///
3939
/// `expected` to `actual` must be comparable with one another via the
40-
/// `PartialEq` trait. In most cases, this means that they must be of the same
40+
/// [`PartialEq`] trait. In most cases, this means that they must be of the same
4141
/// type. However, there are a few cases where different but closely related
4242
/// types are comparable, for example `String` with `&str`.
4343
///
@@ -65,8 +65,10 @@ use std::{fmt::Debug, marker::PhantomData};
6565
/// verify_that(actual, eq(&expected))?; // Compiles
6666
/// ```
6767
///
68-
/// You can find the standard library PartialEq implementation in
69-
/// <https://doc.rust-lang.org/core/cmp/trait.PartialEq.html#implementors>
68+
/// When matching with string types (`&str` and `String`), one can set more
69+
/// options on how equality is checked through the
70+
/// [`StrMatcherConfigurator`][crate::matchers::str_matcher::StrMatcherConfigurator]
71+
/// extension trait, which is implemented for this matcher.
7072
pub fn eq<A: ?Sized, T>(expected: T) -> EqMatcher<A, T> {
7173
EqMatcher { expected, phantom: Default::default() }
7274
}

googletest/src/matchers/str_matcher.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ use std::ops::Deref;
4848
/// # should_pass_2().unwrap();
4949
/// ```
5050
///
51+
/// See the [`StrMatcherConfigurator`] extension trait for more options on how
52+
/// the string is matched.
53+
///
5154
/// > Note on memory use: In most cases, this matcher does not allocate memory
5255
/// > when matching strings. However, it must allocate copies of both the actual
5356
/// > and expected values when matching strings while
@@ -90,6 +93,9 @@ pub fn contains_substring<A: ?Sized, T>(expected: T) -> StrMatcher<A, T> {
9093
/// # should_fail_2().unwrap_err();
9194
/// # should_pass_2().unwrap();
9295
/// ```
96+
///
97+
/// See the [`StrMatcherConfigurator`] extension trait for more options on how
98+
/// the string is matched.
9399
pub fn starts_with<A: ?Sized, T>(expected: T) -> StrMatcher<A, T> {
94100
StrMatcher {
95101
configuration: Configuration { mode: MatchMode::StartsWith, ..Default::default() },
@@ -127,6 +133,9 @@ pub fn starts_with<A: ?Sized, T>(expected: T) -> StrMatcher<A, T> {
127133
/// # should_fail_2().unwrap_err();
128134
/// # should_pass_2().unwrap();
129135
/// ```
136+
///
137+
/// See the [`StrMatcherConfigurator`] extension trait for more options on how
138+
/// the string is matched.
130139
pub fn ends_with<A: ?Sized, T>(expected: T) -> StrMatcher<A, T> {
131140
StrMatcher {
132141
configuration: Configuration { mode: MatchMode::EndsWith, ..Default::default() },
@@ -135,11 +144,11 @@ pub fn ends_with<A: ?Sized, T>(expected: T) -> StrMatcher<A, T> {
135144
}
136145
}
137146

138-
/// Extension trait to configure [StrMatcher].
147+
/// Extension trait to configure [`StrMatcher`].
139148
///
140149
/// Matchers which match against string values and, through configuration,
141-
/// specialise to [StrMatcher] implement this trait. Currently that only
142-
/// includes [EqMatcher] and [StrMatcher].
150+
/// specialise to [`StrMatcher`] implement this trait. That includes
151+
/// [`EqMatcher`] and [`StrMatcher`].
143152
pub trait StrMatcherConfigurator<ActualT: ?Sized, ExpectedT> {
144153
/// Configures the matcher to ignore any leading whitespace in either the
145154
/// actual or the expected value.

0 commit comments

Comments
 (0)