Skip to main content

ContextBuilder

Struct ContextBuilder 

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

Builds a system prompt from named, ordered sections.

Implementations§

Source§

impl ContextBuilder

Source

pub fn new() -> Self

Source

pub fn separator(self, sep: impl Into<String>) -> Self

Set the separator between sections (default: double newline).

Source

pub fn section( self, name: impl Into<String>, content: impl Into<String>, ) -> Self

Add a named section. If a section with this name exists, replace it.

Source

pub fn section_with_priority( self, name: impl Into<String>, content: impl Into<String>, priority: i32, ) -> Self

Add a section with explicit priority (higher = earlier in output).

Source

pub fn disable(self, name: &str) -> Self

Disable a section by name (it will be omitted from build output).

Source

pub fn enable(self, name: &str) -> Self

Re-enable a previously disabled section.

Source

pub fn remove(self, name: &str) -> Self

Remove a section entirely.

Source

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

Get content of a section by name.

Source

pub fn section_names(&self) -> Vec<&str>

Names of all sections (in render order, enabled and disabled).

Source

pub fn enabled_count(&self) -> usize

Count of enabled sections.

Source

pub fn build(&self) -> String

Render the prompt: enabled sections sorted by priority desc, then insertion order.

Source

pub fn has(&self, name: &str) -> bool

Check if a section with the given name exists.

Source

pub fn duplicate_names(&self) -> Vec<String>

All duplicate section names (should be empty in normal use).

Trait Implementations§

Source§

impl Debug for ContextBuilder

Source§

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

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

impl Default for ContextBuilder

Source§

fn default() -> ContextBuilder

Returns the “default value” for a type. 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> 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, 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.