Skip to main content

PromptSection

Struct PromptSection 

Source
pub struct PromptSection { /* private fields */ }
Expand description

One section of a Prompt.

Sections without a name render verbatim; named sections render with a Markdown ## {name} header followed by the content. The name is load-bearing for the rendered shape — keep it short, keep it stable.

Implementations§

Source§

impl PromptSection

Source

pub fn new(content: impl Into<String>) -> PromptSection

Build an unnamed section. Renders as {content}\n\n with no header.

Source

pub fn with_name( name: impl Into<String>, content: impl Into<String>, ) -> PromptSection

Build a named section. Renders as ## {name}\n\n{content}\n\n.

Source

pub fn from_file(path: impl AsRef<Path>) -> Result<PromptSection, PromptError>

Load a section’s content from path (sync std::fs::read_to_string). The resulting section is unnamed; chain with Self::with_name manually if a header is wanted.

Sync I/O is intentional: prompts are typically loaded once at startup. Failures surface as PromptError::LoadFile carrying the offending path and the underlying std::io::Error. Do not call from within a hot async path — wrap in tokio::task::spawn_blocking if the underlying filesystem may be slow.

Source

pub fn name(&self) -> Option<&str>

Section name supplied at construction (None for unnamed sections built via Self::new / Self::from_file).

Source

pub fn content(&self) -> &str

Section body text (without any header Prompt::render would inject).

Source

pub fn token_count(&self, tokenizer: &dyn Tokenizer) -> usize

Approximate token count of this section’s content under tokenizer. The optional ## name header that Prompt::render would prepend is not included — counting the header is the rendered prompt’s responsibility, not the section’s. For the full prompt-level cost, use Prompt::token_count.

Trait Implementations§

Source§

impl Clone for PromptSection

Source§

fn clone(&self) -> PromptSection

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for PromptSection

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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