Skip to content

Commit

Permalink
more references in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Fogapod committed Feb 6, 2024
1 parent 2aa8566 commit ab2bada
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions src/replacement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct ReplacementOptions {

clone_trait_object!(Replacement);

/// Receives match and provides replacement//! # Table of contents
/// Receives match and provides replacement
#[cfg_attr(feature = "deserialize", typetag::deserialize)]
pub trait Replacement: DynClone + Debug {
/// Select suitable replacement
Expand All @@ -26,7 +26,7 @@ pub trait Replacement: DynClone + Debug {
/// input is reference to full input
fn generate<'a>(&self, caps: &Captures, input: &'a str) -> Cow<'a, str>;

/// Runs after `generate` and applies additional operations set by options
/// Runs after [`generate`][Self::generate] and applies additional operations set by options
///
/// By default it does not perform extra work
fn apply_options<'a>(
Expand Down Expand Up @@ -70,8 +70,9 @@ pub trait Replacement: DynClone + Debug {
}
}

/// Shortcut for `"$0"` `Literal`. Returns entire match. Does not act as template by default unlike
/// `Literal`
/// Same as [`Literal`] with `"$0"` argument: returns entire match.
///
/// Does not act as template by default unlike [`Literal`]
#[derive(Clone, Debug, Default)] // i dont know why clippy DEMANDS default here. its nuts
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
pub struct Original;
Expand All @@ -93,8 +94,9 @@ impl Replacement for Original {
}
}

/// Static string. Acts as template, see regex docs for syntax:
/// `https://docs.rs/regex/latest/regex/struct.Regex.html#example-9`
/// Static string
///
/// Acts as regex template, syntax doc: <https://docs.rs/regex/latest/regex/struct.Regex.html#example-9>
#[derive(Clone, Debug)]
#[cfg_attr(
feature = "deserialize",
Expand All @@ -116,7 +118,6 @@ impl Literal {
#[cfg_attr(feature = "deserialize", typetag::deserialize)]
impl Replacement for Literal {
fn generate<'a>(&self, _: &Captures, _: &'a str) -> Cow<'a, str> {
// implementation lives in `apply` entirely
panic!("not meant to be called directly");
}

Expand Down Expand Up @@ -153,7 +154,7 @@ impl Replacement for Literal {
}
}

/// Any creation might fail
/// [`Any`] creation might fail
#[derive(Debug)]
pub enum AnyError {
/// Must provide at least one element
Expand Down Expand Up @@ -200,7 +201,7 @@ impl Replacement for Any {
}
}

/// Weights creation might fail
/// [`Weights`] creation might fail
#[derive(Debug)]
pub enum WeightsError {
/// Must provide at least one element
Expand Down Expand Up @@ -233,7 +234,6 @@ impl Weights {
#[cfg_attr(feature = "deserialize", typetag::deserialize)]
impl Replacement for Weights {
fn generate<'a>(&self, _: &Captures, _: &'a str) -> Cow<'a, str> {
// does not transform input so does not need to implement this
panic!("not meant to be called directly");
}

Expand Down Expand Up @@ -275,7 +275,6 @@ impl Upper {
#[cfg_attr(feature = "deserialize", typetag::deserialize)]
impl Replacement for Upper {
fn generate<'a>(&self, _: &Captures, _: &'a str) -> Cow<'a, str> {
// this does not do anything on its own, only changes case, invalidating mimic_case
panic!("not meant to be called directly");
}

Expand Down Expand Up @@ -321,7 +320,6 @@ impl Lower {
#[cfg_attr(feature = "deserialize", typetag::deserialize)]
impl Replacement for Lower {
fn generate<'a>(&self, _: &Captures, _: &'a str) -> Cow<'a, str> {
// this does not do anything on its own, only changes case, invalidating mimic_case
panic!("not meant to be called directly");
}

Expand Down Expand Up @@ -367,7 +365,6 @@ impl Template {
#[cfg_attr(feature = "deserialize", typetag::deserialize)]
impl Replacement for Template {
fn generate<'a>(&self, _: &Captures, _: &'a str) -> Cow<'a, str> {
// this only changes options
panic!("not meant to be called directly");
}

Expand Down Expand Up @@ -404,7 +401,6 @@ impl NoTemplate {
#[cfg_attr(feature = "deserialize", typetag::deserialize)]
impl Replacement for NoTemplate {
fn generate<'a>(&self, _: &Captures, _: &'a str) -> Cow<'a, str> {
// this only changes options
panic!("not meant to be called directly");
}

Expand Down Expand Up @@ -441,7 +437,6 @@ impl MimicCase {
#[cfg_attr(feature = "deserialize", typetag::deserialize)]
impl Replacement for MimicCase {
fn generate<'a>(&self, _: &Captures, _: &'a str) -> Cow<'a, str> {
// this only changes options
panic!("not meant to be called directly");
}

Expand Down Expand Up @@ -478,7 +473,6 @@ impl NoMimicCase {
#[cfg_attr(feature = "deserialize", typetag::deserialize)]
impl Replacement for NoMimicCase {
fn generate<'a>(&self, _: &Captures, _: &'a str) -> Cow<'a, str> {
// this only changes options
panic!("not meant to be called directly");
}

Expand Down

0 comments on commit ab2bada

Please sign in to comment.