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
impl PromptSection
Sourcepub fn new(content: impl Into<String>) -> PromptSection
pub fn new(content: impl Into<String>) -> PromptSection
Build an unnamed section. Renders as {content}\n\n with no
header.
Sourcepub fn with_name(
name: impl Into<String>,
content: impl Into<String>,
) -> PromptSection
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.
Sourcepub fn from_file(path: impl AsRef<Path>) -> Result<PromptSection, PromptError>
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.
Sourcepub fn name(&self) -> Option<&str>
pub fn name(&self) -> Option<&str>
Section name supplied at construction (None for unnamed
sections built via Self::new / Self::from_file).
Sourcepub fn content(&self) -> &str
pub fn content(&self) -> &str
Section body text (without any header Prompt::render would
inject).
Sourcepub fn token_count(&self, tokenizer: &dyn Tokenizer) -> usize
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
impl Clone for PromptSection
Source§fn clone(&self) -> PromptSection
fn clone(&self) -> PromptSection
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more