Struct text_splitter::ChunkConfig

source ·
pub struct ChunkConfig<Sizer>
where Sizer: ChunkSizer,
{ /* private fields */ }
Expand description

Configuration for how chunks should be created

Implementations§

source§

impl ChunkConfig<Characters>

source

pub fn new(capacity: impl Into<ChunkCapacity>) -> Self

Create a basic configuration for chunking with only the required value a chunk capacity.

By default, chunk sizes will be calculated based on the number of characters in each chunk. You can set a custom chunk sizer by calling Self::with_sizer.

By default, chunks will be trimmed. If you want to preserve whitespace, call Self::with_trim and set it to false.

source§

impl<Sizer> ChunkConfig<Sizer>
where Sizer: ChunkSizer,

source

pub fn capacity(&self) -> &ChunkCapacity

Retrieve a reference to the chunk capacity for this configuration.

source

pub fn overlap(&self) -> usize

Retrieve the amount of overlap between chunks.

source

pub fn with_overlap(self, overlap: usize) -> Result<Self, ChunkConfigError>

Set the amount of overlap between chunks.

§Errors

Will return an error if the overlap is larger than or equal to the chunk capacity.

source

pub fn sizer(&self) -> &Sizer

Retrieve a reference to the chunk sizer for this configuration.

source

pub fn with_sizer<S: ChunkSizer>(self, sizer: S) -> ChunkConfig<S>

Set a custom chunk sizer to use for determining the size of each chunk

use text_splitter::{Characters, ChunkConfig};

let config = ChunkConfig::new(512).with_sizer(Characters);
source

pub fn trim(&self) -> bool

Whether chunkd should have whitespace trimmed from the beginning and end or not.

source

pub fn with_trim(self, trim: bool) -> Self

Specify whether chunks should have whitespace trimmed from the beginning and end or not.

If false (default), joining all chunks should return the original string. If true, all chunks will have whitespace removed from beginning and end.

use text_splitter::ChunkConfig;

let config = ChunkConfig::new(512).with_trim(false);

Trait Implementations§

source§

impl<Sizer> Debug for ChunkConfig<Sizer>
where Sizer: ChunkSizer + Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> From<T> for ChunkConfig<Characters>
where T: Into<ChunkCapacity>,

source§

fn from(capacity: T) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<Sizer> Freeze for ChunkConfig<Sizer>
where Sizer: Freeze,

§

impl<Sizer> RefUnwindSafe for ChunkConfig<Sizer>
where Sizer: RefUnwindSafe,

§

impl<Sizer> Send for ChunkConfig<Sizer>
where Sizer: Send,

§

impl<Sizer> Sync for ChunkConfig<Sizer>
where Sizer: Sync,

§

impl<Sizer> Unpin for ChunkConfig<Sizer>
where Sizer: Unpin,

§

impl<Sizer> UnwindSafe for ChunkConfig<Sizer>
where Sizer: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V