Skip to content

Commit

Permalink
Rename 'value' to 'item' where relevant
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrutar committed Dec 2, 2024
1 parent 87945aa commit 8af3dd2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
10 changes: 5 additions & 5 deletions src/injector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ impl<T: Send + Sync + 'static, R: Render<T>> Injector<T, R> {
}

impl<T, R: Render<T>> Injector<T, R> {
/// Send a value to the matcher engine.
pub fn push(&self, value: T) {
self.inner.push(value, |s, columns| {
/// Add an item to the picker.
pub fn push(&self, item: T) {
self.inner.push(item, |s, columns| {
columns[0] = self.render.render(s).as_ref().into();
});
}
Expand Down Expand Up @@ -102,8 +102,8 @@ mod serde {
where
S: SeqAccess<'de>,
{
while let Some(value) = seq.next_element()? {
self.push(value);
while let Some(item) = seq.next_element()? {
self.push(item);
}

Ok(())
Expand Down
34 changes: 17 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ use crate::{
/// impl Render<DirEntry> for DirEntryRenderer {
/// type Str<'a> = Cow<'a, str>;
///
/// fn render<'a>(&self, value: &'a DirEntry) -> Self::Str<'a> {
/// value.path().to_string_lossy()
/// fn render<'a>(&self, item: &'a DirEntry) -> Self::Str<'a> {
/// item.path().to_string_lossy()
/// }
/// }
/// ```
Expand All @@ -107,10 +107,10 @@ use crate::{
/// type Str<'a> = String
/// where T: 'a;
///
/// fn render<'a>(&self, value: &'a T) -> Self::Str<'a> {
/// fn render<'a>(&self, item: &'a T) -> Self::Str<'a> {
/// let mut rendered = String::new();
/// rendered.push_str(&self.prefix);
/// rendered.push_str(value.as_ref());
/// rendered.push_str(item.as_ref());
/// rendered
/// }
/// }
Expand Down Expand Up @@ -141,14 +141,14 @@ use crate::{
/// where
/// T: 'a;
///
/// fn render<'a>(&self, value: &'a T) -> Self::Str<'a> {
/// let value_ref = value.as_ref();
/// fn render<'a>(&self, item: &'a T) -> Self::Str<'a> {
/// let item_ref = item.as_ref();
///
/// if value_ref.contains('\t') {
/// if item_ref.contains('\t') {
/// // replace tabs with two spaces
/// Cow::Owned(value_ref.replace('\t', " "))
/// Cow::Owned(item_ref.replace('\t', " "))
/// } else {
/// Cow::Borrowed(value_ref)
/// Cow::Borrowed(item_ref)
/// }
/// }
/// }
Expand Down Expand Up @@ -195,9 +195,9 @@ pub trait Render<T> {
where
T: 'a;

/// Render the given value as a column in the picker. See the [trait-level docs](Render) for
/// more detail.
fn render<'a>(&self, value: &'a T) -> Self::Str<'a>;
/// Render the given item as it should appear in the picker. See the
/// [trait-level docs](Render) for more detail.
fn render<'a>(&self, item: &'a T) -> Self::Str<'a>;
}

/// Specify configuration options for a [`Picker`].
Expand Down Expand Up @@ -385,8 +385,8 @@ impl<T: Send + Sync + 'static, R: Render<T>> Picker<T, R> {
Duration::from_millis(16)
}

/// Update the default query string to a provided value. This is mainly useful for modifying the
/// query string before re-using the [`Picker`].
/// Update the default query string. This is mainly useful for modifying the query string
/// before re-using the [`Picker`].
///
/// See also the [`PickerOptions::query`] method to set the query during initialization.
#[inline]
Expand Down Expand Up @@ -424,14 +424,14 @@ impl<T: Send + Sync + 'static, R: Render<T>> Picker<T, R> {
Injector::new(self.matcher.injector(), self.render.clone())
}

/// A convenience method to obtain the rendered version of a value as it would appear in the
/// A convenience method to obtain the rendered version of an item as it would appear in the
/// picker.
///
/// This is the same as calling [`Render::render`] on the [`Render`] implementation internal
/// to the picker.
#[inline]
pub fn render<'a>(&self, value: &'a T) -> <R as Render<T>>::Str<'a> {
self.render.render(value)
pub fn render<'a>(&self, item: &'a T) -> <R as Render<T>>::Str<'a> {
self.render.render(item)
}

/// Open the interactive picker prompt and return the picked item, if any.
Expand Down
18 changes: 12 additions & 6 deletions src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use std::{borrow::Cow, path::Path};
use super::Render;

/// A renderer for any type which de-references as [`str`], such as a [`String`].
///
/// ## Example
/// ```
/// # use nucleo_picker::{render::StrRenderer, Render};
/// let str_renderer = StrRenderer;
Expand All @@ -25,13 +27,15 @@ impl<T: AsRef<str>> Render<T> for StrRenderer {
where
T: 'a;

fn render<'a>(&self, value: &'a T) -> Self::Str<'a> {
value.as_ref()
fn render<'a>(&self, item: &'a T) -> Self::Str<'a> {
item.as_ref()
}
}

/// A renderer for any type which de-references as [`Path`], such as a
/// [`PathBuf`](std::path::PathBuf).
///
/// ## Example
/// ```
/// # use nucleo_picker::{render::PathRenderer, Render};
/// use std::path::PathBuf;
Expand All @@ -54,12 +58,14 @@ impl<T: AsRef<Path>> Render<T> for PathRenderer {
where
T: 'a;

fn render<'a>(&self, value: &'a T) -> Self::Str<'a> {
value.as_ref().to_string_lossy()
fn render<'a>(&self, item: &'a T) -> Self::Str<'a> {
item.as_ref().to_string_lossy()
}
}

/// A renderer which uses a type's [`Display`](std::fmt::Display) implementation.
///
/// ## Example
/// ```
/// # use nucleo_picker::{render::DisplayRenderer, Render};
/// let display_renderer = DisplayRenderer;
Expand All @@ -74,7 +80,7 @@ impl<T: ToString> Render<T> for DisplayRenderer {
where
T: 'a;

fn render<'a>(&self, value: &'a T) -> Self::Str<'a> {
value.to_string()
fn render<'a>(&self, item: &'a T) -> Self::Str<'a> {
item.to_string()
}
}

0 comments on commit 8af3dd2

Please sign in to comment.