TokenRef

Struct TokenRef 

Source
pub struct TokenRef<'a> {
    pub text: &'a str,
    pub offset: Offset,
    pub reference_offsets: &'a [OffsetSize],
    pub mask: Mask,
}
Expand description

Reference token that references the original text, with a string slice representation

Fields§

§text: &'a str

String representation

§offset: Offset

Start and end positions of the token with respect to the original text

§reference_offsets: &'a [OffsetSize]

Sequence of positions with respect to the original text contained in the token. For example, if the token offset is start: 4, end: 10, corresponding reference_offsets are [4, 5, 6, 7, 8, 9]

§mask: Mask

Mask indicating the type of the token

Implementations§

Source§

impl<'a> TokenRef<'a>

Source

pub fn new(text: &'a str, offsets: &'a [OffsetSize]) -> TokenRef<'a>

Creates a new token reference from a text and list of offsets.

§Parameters
  • text (&str): text reference
  • offsets (&[OffsetSize]): reference positions with respect to the original text
§Example
use rust_tokenizers::TokenRef;
let _original_text = "Hello, world";
let text = "world";
let offsets = &[7, 8, 9, 10, 11];

let token_ref = TokenRef::new(text, offsets);
Source

pub fn to_owned(self) -> Token

Converts a token reference to an owned form.

§Example
use rust_tokenizers::TokenRef;
let _original_text = "Hello, world";
let text = "world";
let offsets = &[7, 8, 9, 10, 11];
let token_ref = TokenRef::new(text, offsets);

let owned_token = token_ref.to_owned();

Trait Implementations§

Source§

impl<'a> Clone for TokenRef<'a>

Source§

fn clone(&self) -> TokenRef<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> ConsolidatableTokens<TokenRef<'a>> for Vec<TokenRef<'a>>

Source§

fn iter_consolidate_tokens(&self) -> ConsolidatedTokenIterator<'_, TokenRef<'a>>

Creates an iterator from a sequence of ConsolidatableTokens.
Source§

impl<'a> Debug for TokenRef<'a>

Source§

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

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

impl<'a> From<&'a Token> for TokenRef<'a>

Source§

fn from(other: &'a Token) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<TokenRef<'a>> for Token

Source§

fn from(other: TokenRef<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> PartialEq for TokenRef<'a>

Source§

fn eq(&self, other: &TokenRef<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> TokenTrait for TokenRef<'a>

Source§

fn offset(&self) -> Option<Offset>

Returns the offset of the token with respect to the original string
Source§

fn mask(&self) -> Mask

Returns the token mask
Source§

fn as_str(&self) -> &str

Returns a string representation for the token
Source§

impl<'a> Copy for TokenRef<'a>

Source§

impl<'a> Eq for TokenRef<'a>

Source§

impl<'a> StructuralPartialEq for TokenRef<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for TokenRef<'a>

§

impl<'a> RefUnwindSafe for TokenRef<'a>

§

impl<'a> Send for TokenRef<'a>

§

impl<'a> Sync for TokenRef<'a>

§

impl<'a> Unpin for TokenRef<'a>

§

impl<'a> UnwindSafe for TokenRef<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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.
Source§

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

Source§

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.