pub struct CIntegerLiteralCodec;Expand description
Decodes restricted non-negative C integer literal fragments.
This codec accepts decimal literals such as 123, octal literals such as
0123, and hexadecimal literals such as 0x123 or 0X123. It trims
surrounding whitespace and returns a u64. It intentionally accepts only
a complete unsigned token: signs, integer suffixes, digit separators, and
token-stream boundaries are outside this codec’s contract.
§Examples
use qubit_codec_misc::CIntegerLiteralCodec;
let codec = CIntegerLiteralCodec::new();
assert_eq!(codec.decode("0x2a").unwrap(), 42);Implementations§
Source§impl CIntegerLiteralCodec
impl CIntegerLiteralCodec
Sourcepub fn decode(&self, text: &str) -> MiscCodecResult<u64>
pub fn decode(&self, text: &str) -> MiscCodecResult<u64>
Decodes a C integer literal into a u64.
§Parameters
text: C integer literal text.
§Returns
Parsed integer value.
§Errors
Returns MiscCodecError::InvalidInput when the input is empty, lacks
digits, or overflows u64; returns MiscCodecError::InvalidDigit
when a character is not valid for the detected radix.
Trait Implementations§
Source§impl Clone for CIntegerLiteralCodec
impl Clone for CIntegerLiteralCodec
impl Copy for CIntegerLiteralCodec
Source§impl Debug for CIntegerLiteralCodec
impl Debug for CIntegerLiteralCodec
Source§impl Default for CIntegerLiteralCodec
impl Default for CIntegerLiteralCodec
impl Eq for CIntegerLiteralCodec
Source§impl PartialEq for CIntegerLiteralCodec
impl PartialEq for CIntegerLiteralCodec
impl StructuralPartialEq for CIntegerLiteralCodec
Source§impl ValueDecoder<str> for CIntegerLiteralCodec
impl ValueDecoder<str> for CIntegerLiteralCodec
Source§type Error = MiscCodecError
type Error = MiscCodecError
Error returned when a C integer token is malformed or unsupported.
Source§fn decode(&mut self, input: &str) -> Result<Self::Output, Self::Error>
fn decode(&mut self, input: &str) -> Result<Self::Output, Self::Error>
Decodes a complete C integer token into a u64.
§Parameters
input: C integer literal text.
§Returns
The decoded unsigned integer.
§Errors
Returns MiscCodecError::InvalidInput when the input is empty, lacks
digits, or overflows u64; returns MiscCodecError::InvalidDigit
when a character is not valid for the detected radix.