pub struct Chunk<'a> { /* private fields */ }Expand description
A chunk of text with positional metadata.
Chunks are produced by Chunker and contain
borrowed text along with metadata useful for tracking position
within the original document.
§Example
use pdfvec::{Chunker, ChunkStrategy};
let text = "First paragraph.\n\nSecond paragraph.";
let chunker = Chunker::new(ChunkStrategy::Paragraph);
for chunk in chunker.chunks(text) {
println!("Chunk {}: {} chars at offset {}",
chunk.index(),
chunk.char_count(),
chunk.byte_offset());
}Implementations§
Source§impl<'a> Chunk<'a>
impl<'a> Chunk<'a>
Sourcepub fn new(text: &'a str, index: usize, byte_offset: usize) -> Self
pub fn new(text: &'a str, index: usize, byte_offset: usize) -> Self
Creates a new chunk with the given metadata.
Sourcepub fn text(&self) -> &'a str
pub fn text(&self) -> &'a str
Returns the text content of this chunk.
§Example
use pdfvec::{Chunker, ChunkStrategy};
let text = "Hello world";
let chunks: Vec<_> = Chunker::new(ChunkStrategy::Fixed)
.chunk_size(5)
.chunks(text)
.collect();
assert_eq!(chunks[0].text(), "Hello");Sourcepub fn index(&self) -> usize
pub fn index(&self) -> usize
Returns the zero-based index of this chunk.
§Example
use pdfvec::{Chunker, ChunkStrategy};
let text = "abcdefghij";
let chunks: Vec<_> = Chunker::new(ChunkStrategy::Fixed)
.chunk_size(5)
.chunks(text)
.collect();
assert_eq!(chunks[0].index(), 0);
assert_eq!(chunks[1].index(), 1);Sourcepub fn byte_offset(&self) -> usize
pub fn byte_offset(&self) -> usize
Returns the byte offset of this chunk within the original text.
§Example
use pdfvec::{Chunker, ChunkStrategy};
let text = "abcdefghij";
let chunks: Vec<_> = Chunker::new(ChunkStrategy::Fixed)
.chunk_size(5)
.chunks(text)
.collect();
assert_eq!(chunks[0].byte_offset(), 0);
assert_eq!(chunks[1].byte_offset(), 5);Sourcepub fn char_count(&self) -> usize
pub fn char_count(&self) -> usize
Returns the number of characters in this chunk.
§Example
use pdfvec::{Chunker, ChunkStrategy};
let text = "Hello";
let chunks: Vec<_> = Chunker::new(ChunkStrategy::Fixed)
.chunk_size(100)
.chunks(text)
.collect();
assert_eq!(chunks[0].char_count(), 5);Trait Implementations§
impl<'a> Eq for Chunk<'a>
impl<'a> StructuralPartialEq for Chunk<'a>
Auto Trait Implementations§
impl<'a> Freeze for Chunk<'a>
impl<'a> RefUnwindSafe for Chunk<'a>
impl<'a> Send for Chunk<'a>
impl<'a> Sync for Chunk<'a>
impl<'a> Unpin for Chunk<'a>
impl<'a> UnwindSafe for Chunk<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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