Skip to content

Commit

Permalink
Remove failure dep, add MSVR 1.81, edition 2021 and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Arbuzov committed Sep 24, 2024
1 parent f62a10b commit afa9d5e
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 97 deletions.
9 changes: 3 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ license = "MIT/Apache-2.0"
name = "tlv_parser"
readme = "README.md"
repository = "https://github.com/lexxvir/tlv-parser"
version = "0.9.0"
version = "0.10.0"
exclude = ["benches/*", "tests/*", "fuzz/*", "decode-tlv/*", "amex-cda-in.txt", ".*"]

[dependencies.failure]
version = "0.1.1"
default-features = false
features = ["derive"]
rust-version = "1.81"
edition = "2021"

[dev-dependencies]
quickcheck = "^0"
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# tlv-parser
[![Build Status](https://travis-ci.org/lexxvir/tlv-parser.svg?branch=master)](https://travis-ci.org/lexxvir/tlv-parser)
[![Latest Version](https://img.shields.io/crates/v/tlv_parser.svg)](https://crates.io/crates/tlv_parser)
[![Docs](https://docs.rs/tlv_parser/badge.svg)](https://docs.rs/tlv_parser)

Expand Down
69 changes: 3 additions & 66 deletions decode-tlv/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion decode-tlv/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "decode-tlv"
version = "0.1.0"
authors = ["aarbuzov"]
edition = "2021"

[dependencies]
hex = "0.3.1"
Expand Down
3 changes: 0 additions & 3 deletions decode-tlv/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
extern crate hex;
extern crate tlv_parser;

use std::io::Read;
use tlv_parser::tlv::{Tlv, Value};

Expand Down
44 changes: 25 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,42 @@
//! assert_eq!(constructed_tlv.to_vec(), vec![0x21, 0x02, 0x01, 0x00]);
//! ```
extern crate core as std;
#[macro_use]
extern crate alloc;
#[macro_use]
extern crate failure;

pub mod tlv;

type Result<T> = core::result::Result<T, TlvError>;

#[derive(Debug, Fail)]
#[derive(Debug)]
pub enum TlvError {
#[fail(display = "Too short input vector")]
TruncatedTlv,

#[fail(display = "Invalid length value")]
InvalidLength,

#[fail(display = "Invalid tag number")]
InvalidTagNumber,

#[fail(display = "Too short body: expected {}, found {}", expected, found)]
TooShortBody { expected: usize, found: usize },

#[fail(
display = "Tag number defines primitive TLV, but value is not Value::Val: {}",
tag_number
)]
ValExpected { tag_number: usize },

#[fail(display = "Provided 'tag-path' have error")]
TagPathError,
}

use core::fmt;

impl fmt::Display for TlvError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use TlvError::*;

match self {
TruncatedTlv => write!(f, "Too short input vector"),
InvalidLength => writeln!(f, "Invalid length value"),
InvalidTagNumber => write!(f, "Invalid tag number"),
TooShortBody { expected, found } => {
write!(f, "Too short body: expected {expected}, found {found}")
}
ValExpected { tag_number } => write!(
f,
"Tag number defines primitive TLV, but value is not Value::Val: {tag_number}"
),
TagPathError => write!(f, "Provided 'tag-path' has error"),
}
}
}

impl core::error::Error for TlvError {}
2 changes: 1 addition & 1 deletion src/tlv.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloc::string::String;
use alloc::vec::Vec;
use alloc::{vec, vec::Vec};
use core::fmt::{self, Debug};

use super::{Result, TlvError};
Expand Down

0 comments on commit afa9d5e

Please sign in to comment.