Skip to main content

DecodedString

Struct DecodedString 

Source
#[non_exhaustive]
pub struct DecodedString { pub code: BchCode, pub corrections_applied: usize, pub corrected_positions: Vec<usize>, pub data_with_checksum: Vec<u8>, }
Expand description

Result of a successful mk1 string decode at the BCH layer.

Use Self::data to access the data part as 5-bit values (header symbols + payload, checksum stripped); the string-layer reassembler in crate::string_layer splits header symbols off and feeds the remaining payload through five_bit_to_bytes to recover the original fragment bytes.

The full post-correction 5-bit symbol sequence (data plus the trailing 13- or 15-char checksum) is retained internally as Self::data_with_checksum and can be queried by Self::corrected_char_at for any position in the data part — including positions that fall inside the checksum region. The decoder-report layer uses this to surface the real corrected character when BCH ECC repairs a substitution inside the checksum (parallels md-codec’s Correction.corrected field).

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§code: BchCode

Detected BCH code variant.

§corrections_applied: usize

Number of substitution errors corrected (0 = clean input, 1 = recovered).

§corrected_positions: Vec<usize>

Indices into the data-part (chars after "md1") of any corrected positions.

§data_with_checksum: Vec<u8>

Full post-correction 5-bit symbol sequence (data part + checksum), in the same coordinate system as Self::corrected_positions.

Length is data().len() + 13 (regular code) or data().len() + 15 (long code). Indices 0..data().len() mirror Self::data symbol-for-symbol; indices data().len().. are the corrected checksum symbols. Use Self::corrected_char_at for the human-readable bech32 character at any position.

Implementations§

Source§

impl DecodedString

Source

pub fn data(&self) -> &[u8]

Data part as 5-bit values, with the trailing checksum stripped.

Returns a slice into Self::data_with_checksum — the data part is data_with_checksum[..len - checksum_len], where checksum_len is 13 for BchCode::Regular and 15 for BchCode::Long.

Source

pub fn corrected_char_at(&self, char_position: usize) -> char

Look up the corrected bech32 character at the given position in the data part (chars after the "md1" HRP+separator).

char_position is 0-indexed. Positions 0..data().len() are in the data region; positions data().len()..data().len() + checksum_len are inside the BCH checksum (13 chars for BchCode::Regular, 15 for BchCode::Long). All positions return the post-correction character — i.e., what the symbol should be after BCH repair, which is exactly what [Correction.corrected][crate::Correction::corrected] is documented to report.

§Panics

Panics if char_position >= data_with_checksum.len(). Callers are responsible for clamping the position to a valid range; in the decode pipeline this is guaranteed by the BCH layer (it never reports a corrected_position outside data_with_checksum). Note that data_with_checksum includes the checksum region; “outside the data part” elsewhere in this crate excludes the checksum and is a tighter bound than what this method requires.

Trait Implementations§

Source§

impl Clone for DecodedString

Source§

fn clone(&self) -> DecodedString

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 DecodedString

Source§

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

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

impl Eq for DecodedString

Source§

impl PartialEq for DecodedString

Source§

fn eq(&self, other: &DecodedString) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DecodedString

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.