Skip to main content

parse_dcbor_item

Function parse_dcbor_item 

Source
pub fn parse_dcbor_item(src: &str) -> Result<CBOR>
Expand description

Parses a dCBOR item from a string input.

This function takes a string slice containing a dCBOR diagnostic notation encoded value and attempts to parse it into a CBOR object. If the input contains extra tokens after a valid item, an error is returned.

§Arguments

  • src - A string slice containing the dCBOR-encoded data.

§Returns

  • Ok(CBOR) if parsing is successful and the input contains exactly one valid dCBOR item, which itself might be an atomic value like a number or string, or a complex value like an array or map.
  • Err(Error) if parsing fails or if extra tokens are found after the item.

§Errors

Returns an error if the input is invalid, contains extra tokens, or if any token cannot be parsed as expected.

§Example

let cbor = parse_dcbor_item("[1, 2, 3]").unwrap();
assert_eq!(cbor.diagnostic(), "[1, 2, 3]");