pub struct TextContent { /* private fields */ }Expand description
Validated, bounded UTF-8 text with mandatory security metadata.
Text is preserved byte-for-byte without trimming or Unicode normalization.
StateKnot rejects C0/C1 controls other than tab, line feed, and carriage
return, plus Unicode noncharacters. Multilingual text and bidi formatting
characters remain valid data; renderers and logs must still escape untrusted
content for their output context.
Implementations§
Source§impl TextContent
impl TextContent
Sourcepub fn new(
text: &str,
language: Option<LanguageTag>,
metadata: ContentMetadata,
) -> Result<Self, TextContentError>
pub fn new( text: &str, language: Option<LanguageTag>, metadata: ContentMetadata, ) -> Result<Self, TextContentError>
Validates borrowed text and copies it into an immutable value.
§Errors
Returns TextContentError when text is empty, exceeds the byte
ceiling, or contains a disallowed control or Unicode noncharacter.
Sourcepub fn from_string(
text: String,
language: Option<LanguageTag>,
metadata: ContentMetadata,
) -> Result<Self, TextContentError>
pub fn from_string( text: String, language: Option<LanguageTag>, metadata: ContentMetadata, ) -> Result<Self, TextContentError>
Validates owned text without copying its bytes.
§Errors
Returns TextContentError when text is empty, exceeds the byte
ceiling, or contains a disallowed control or Unicode noncharacter.
Sourcepub const fn language(&self) -> Option<&LanguageTag>
pub const fn language(&self) -> Option<&LanguageTag>
Returns the optional stable language tag.
Sourcepub const fn metadata(&self) -> &ContentMetadata
pub const fn metadata(&self) -> &ContentMetadata
Returns the mandatory security metadata.
Trait Implementations§
Source§impl Clone for TextContent
impl Clone for TextContent
Source§impl Debug for TextContent
impl Debug for TextContent
Source§impl<'de> Deserialize<'de> for TextContent
impl<'de> Deserialize<'de> for TextContent
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
impl Eq for TextContent
Source§impl From<TextContent> for ContentPart
impl From<TextContent> for ContentPart
Source§fn from(value: TextContent) -> Self
fn from(value: TextContent) -> Self
Source§impl From<TextContent> for InstructionContent
impl From<TextContent> for InstructionContent
Source§fn from(value: TextContent) -> Self
fn from(value: TextContent) -> Self
Source§impl JsonSchema for TextContent
impl JsonSchema for TextContent
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read more