pub struct DcMstr { /* private fields */ }Expand description
A borrowed slice representing valid DcMixed format data (.dcmm). Analogous to DcStr and Rust’s str.
Implementations§
Source§impl DcMstr
impl DcMstr
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<&Self, DcMixedError>
pub fn from_bytes(bytes: &[u8]) -> Result<&Self, DcMixedError>
Validates the provided byte slice as valid DcMixed and wraps it as a &DcMstr.
§Errors
Returns DcMixedError if the byte slice does not conform to the DcMixed specification.
Sourcepub const unsafe fn from_bytes_unchecked(bytes: &[u8]) -> &Self
pub const unsafe fn from_bytes_unchecked(bytes: &[u8]) -> &Self
Creates a &DcMstr from a byte slice without validation.
§Safety
The caller must ensure that bytes contains valid DcMixed data.
Sourcepub fn from_bytes_mut(bytes: &mut [u8]) -> Result<&mut Self, DcMixedError>
pub fn from_bytes_mut(bytes: &mut [u8]) -> Result<&mut Self, DcMixedError>
Validates the mutable byte slice as valid DcMixed and wraps it as a &mut DcMstr.
§Errors
Returns DcMixedError if the slice does not conform to DcMixed.
Sourcepub unsafe fn from_bytes_unchecked_mut(bytes: &mut [u8]) -> &mut Self
pub unsafe fn from_bytes_unchecked_mut(bytes: &mut [u8]) -> &mut Self
Creates a &mut DcMstr without validation.
§Safety
The caller must ensure bytes contains valid DcMixed data.
Sourcepub const fn as_bytes(&self) -> &[u8] ⓘ
pub const fn as_bytes(&self) -> &[u8] ⓘ
Returns the underlying byte slice (including the 21-byte header).
Sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Returns the total byte length of the slice (including the 21-byte header).
Sourcepub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
Returns true if the document has no payload data (only contains the 21-byte header).
Sourcepub fn payload_bytes(&self) -> &[u8] ⓘ
pub fn payload_bytes(&self) -> &[u8] ⓘ
Returns the slice of payload bytes occurring after the 21-byte header.
Sourcepub fn payload_len(&self) -> usize
pub fn payload_len(&self) -> usize
Returns the length in bytes of the payload after the 21-byte header.
Sourcepub fn chunks(&self) -> DcMixedChunks<'_> ⓘ
pub fn chunks(&self) -> DcMixedChunks<'_> ⓘ
Returns an iterator yielding DcMixed chunks (text segments and encapsulated payloads).
Sourcepub fn to_dc_string(&self) -> Result<DcString>
pub fn to_dc_string(&self) -> Result<DcString>
Converts this DcMstr into a standard DcString (DcUtf) representation.
Binary payloads are converted into base64 characters between Dc 203 and Dc 204, with byte length and any declared type or checksum.
§Errors
Returns error if base64 encoding fails.
Sourcepub fn to_dc_string_with_policy(
&self,
policy: &DcProjectionPolicy,
) -> Result<DcString>
pub fn to_dc_string_with_policy( &self, policy: &DcProjectionPolicy, ) -> Result<DcString>
Converts this DcMstr into a standard DcString (DcUtf) representation
using the provided crate::DcProjectionPolicy.
Sourcepub fn to_dc_string_with_policy_and_resolver(
&self,
policy: &DcProjectionPolicy,
resolver: &dyn SyntaxRuleResolver,
) -> Result<DcString>
pub fn to_dc_string_with_policy_and_resolver( &self, policy: &DcProjectionPolicy, resolver: &dyn SyntaxRuleResolver, ) -> Result<DcString>
Converts this DcMstr into a standard DcString (DcUtf) representation
using the provided crate::DcProjectionPolicy and crate::SyntaxRuleResolver.
Source§impl DcMstr
impl DcMstr
Sourcepub fn decode<T: DcMixedDecode>(&self, policy: &DcProjectionPolicy) -> Result<T>
pub fn decode<T: DcMixedDecode>(&self, policy: &DcProjectionPolicy) -> Result<T>
Interprets the entire string as a typed value without changing source.
§Errors
Returns an error on unsupported syntax, missing fields, or trailing data.
Sourcepub fn decode_with_context<T: DcMixedDecode>(
&self,
context: &SharedValueContext,
policy: &DcProjectionPolicy,
) -> Result<T>
pub fn decode_with_context<T: DcMixedDecode>( &self, context: &SharedValueContext, policy: &DcProjectionPolicy, ) -> Result<T>
Interprets the whole string with explicitly supplied outer bindings.
§Errors
Returns an error if interpretation fails or trailing content remains.
Sourcepub fn decode_with_resolver<T: DcMixedDecode>(
&self,
resolver: &dyn SyntaxRuleResolver,
policy: &DcProjectionPolicy,
) -> Result<T>
pub fn decode_with_resolver<T: DcMixedDecode>( &self, resolver: &dyn SyntaxRuleResolver, policy: &DcProjectionPolicy, ) -> Result<T>
Interprets the string using a custom SyntaxRuleResolver.
§Errors
Returns an error if interpretation fails or trailing content remains.
Sourcepub fn decode_with_resolver_and_context<T: DcMixedDecode>(
&self,
resolver: &dyn SyntaxRuleResolver,
context: Option<&SharedValueContext>,
policy: &DcProjectionPolicy,
) -> Result<T>
pub fn decode_with_resolver_and_context<T: DcMixedDecode>( &self, resolver: &dyn SyntaxRuleResolver, context: Option<&SharedValueContext>, policy: &DcProjectionPolicy, ) -> Result<T>
Interprets the string using a custom SyntaxRuleResolver and optional
outer shared context.
§Errors
Returns an error if interpretation fails or trailing content remains.
Source§impl DcMstr
impl DcMstr
Sourcepub fn inspect<T: DcMixedDecode>(&self) -> DcInspection<'_, T>
pub fn inspect<T: DcMixedDecode>(&self) -> DcInspection<'_, T>
Annotates an interpretation, preserving source even when decoding fails.
Sourcepub fn inspect_with_policy<'a, T: DcMixedDecode>(
&'a self,
policy: &DcProjectionPolicy,
) -> DcInspection<'a, T>
pub fn inspect_with_policy<'a, T: DcMixedDecode>( &'a self, policy: &DcProjectionPolicy, ) -> DcInspection<'a, T>
Annotates with an explicit projection policy.
Sourcepub fn inspect_with_context<'a, T: DcMixedDecode>(
&'a self,
context: &'a SharedValueContext,
) -> DcInspection<'a, T>
pub fn inspect_with_context<'a, T: DcMixedDecode>( &'a self, context: &'a SharedValueContext, ) -> DcInspection<'a, T>
Annotates with explicitly supplied outer reference bindings.
Sourcepub fn inspect_with_resolver<'a, T: DcMixedDecode>(
&'a self,
resolver: &'a dyn SyntaxRuleResolver,
) -> DcInspection<'a, T>
pub fn inspect_with_resolver<'a, T: DcMixedDecode>( &'a self, resolver: &'a dyn SyntaxRuleResolver, ) -> DcInspection<'a, T>
Annotates an interpretation with a custom SyntaxRuleResolver.
Sourcepub fn inspect_with_policy_and_resolver<'a, T: DcMixedDecode>(
&'a self,
policy: &DcProjectionPolicy,
resolver: &'a dyn SyntaxRuleResolver,
) -> DcInspection<'a, T>
pub fn inspect_with_policy_and_resolver<'a, T: DcMixedDecode>( &'a self, policy: &DcProjectionPolicy, resolver: &'a dyn SyntaxRuleResolver, ) -> DcInspection<'a, T>
Annotates an interpretation with an explicit policy and custom SyntaxRuleResolver.
Trait Implementations§
Source§impl DcMixedEncode for DcMstr
impl DcMixedEncode for DcMstr
Source§fn encode_dc_mixed_to(&self, mst: &mut DcWriter<'_>) -> Result<()>
fn encode_dc_mixed_to(&self, mst: &mut DcWriter<'_>) -> Result<()>
fn encode_dc_mixed(&self, mst: &mut DcMstring) -> Result<()>
fn encode_dc_mixed_with_context( &self, mst: &mut DcMstring, context: &SharedValueContext, ) -> Result<()>
fn encode_format_elements_with_context( &self, format: DcChar, mst: &mut DcMstring, context: &SharedValueContext, ) -> Result<()>
Source§fn write_dc_mixed(&self, output: &mut dyn Write) -> Result<()>
fn write_dc_mixed(&self, output: &mut dyn Write) -> Result<()>
Source§fn to_dc_mixed(&self) -> Result<DcMstring>
fn to_dc_mixed(&self) -> Result<DcMstring>
Source§fn to_dc_string(&self) -> Result<DcString>
fn to_dc_string(&self) -> Result<DcString>
Source§fn encode_dc_mixed_to_with_context(
&self,
mst: &mut DcWriter<'_>,
_context: &SharedValueContext,
) -> Result<()>
fn encode_dc_mixed_to_with_context( &self, mst: &mut DcWriter<'_>, _context: &SharedValueContext, ) -> Result<()>
Source§fn encode_format_elements_to_with_context(
&self,
format: DcChar,
mst: &mut DcWriter<'_>,
context: &SharedValueContext,
) -> Result<()>
fn encode_format_elements_to_with_context( &self, format: DcChar, mst: &mut DcWriter<'_>, context: &SharedValueContext, ) -> Result<()>
Dc 511 [format] ... Dc 512 format representation container.Source§impl DcSource for DcMstr
impl DcSource for DcMstr
Source§fn source_bytes(&self) -> &[u8] ⓘ
fn source_bytes(&self) -> &[u8] ⓘ
Source§fn replace_typed_source_field_with_policy_and_resolver(
&self,
range: Range<usize>,
fragment: &DcMstr,
policy: &DcProjectionPolicy,
resolver: &dyn SyntaxRuleResolver,
) -> Result<DcMstring>
fn replace_typed_source_field_with_policy_and_resolver( &self, range: Range<usize>, fragment: &DcMstr, policy: &DcProjectionPolicy, resolver: &dyn SyntaxRuleResolver, ) -> Result<DcMstring>
policy and resolver. Read moreSource§fn replace_source_field(
&self,
range: Range<usize>,
fragment: &DcMstr,
) -> Result<DcMstring>
fn replace_source_field( &self, range: Range<usize>, fragment: &DcMstr, ) -> Result<DcMstring>
Source§fn replace_typed_source_field(
&self,
range: Range<usize>,
fragment: &DcMstr,
) -> Result<Self::Owned>
fn replace_typed_source_field( &self, range: Range<usize>, fragment: &DcMstr, ) -> Result<Self::Owned>
Source§fn replace_typed_source_field_with_resolver(
&self,
range: Range<usize>,
fragment: &DcMstr,
resolver: &dyn SyntaxRuleResolver,
) -> Result<Self::Owned>
fn replace_typed_source_field_with_resolver( &self, range: Range<usize>, fragment: &DcMstr, resolver: &dyn SyntaxRuleResolver, ) -> Result<Self::Owned>
resolver. Read moreSource§impl PartialOrd for DcMstr
impl PartialOrd for DcMstr
Source§impl ToOwned for DcMstr
impl ToOwned for DcMstr
impl Eq for DcMstr
impl StructuralPartialEq for DcMstr
Auto Trait Implementations§
impl Freeze for DcMstr
impl RefUnwindSafe for DcMstr
impl Send for DcMstr
impl !Sized for DcMstr
impl Sync for DcMstr
impl Unpin for DcMstr
impl UnwindSafe for DcMstr
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);