| Crates.io | camel-case-token-with-comment |
| lib.rs | camel-case-token-with-comment |
| version | 0.2.2 |
| created_at | 2025-02-27 05:37:00.090786+00 |
| updated_at | 2025-07-13 10:33:30.29036+00 |
| description | Handles camel case tokens with optional comments and provides utilities for parsing token files and extracting JSON fields. |
| homepage | |
| repository | https://github.com/klebs6/klebs-general |
| max_upload_size | |
| id | 1571335 |
| size | 144,898 |
The camel-case-token-with-comment crate provides functionality for handling and parsing tokens in camel case format with optional comments. It includes utilities for processing token files, extracting relevant token fields from JSON, and serializing tokens to and from strings.
token_name field from JSON data.The CamelCaseTokenWithComment struct holds a camel case token with an optional comment. This structure supports various utilities for managing the data.
pub struct CamelCaseTokenWithComment {
data: String,
comment: Option<String>,
}
The crate includes the function parse_token_file, which asynchronously reads a file and parses each line into CamelCaseTokenWithComment.
pub async fn parse_token_file(filename: &str) -> Result<Vec<CamelCaseTokenWithComment>, TokenParseError>;
A utility function extract_token_name_field extracts the "token_name" field from JSON data.
pub fn extract_token_name_field(json: &serde_json::Value) -> Result<&str, TokenParseError>;
This crate uses custom error types to handle parsing and I/O errors:
error_tree! {
pub enum TokenParseError {
InvalidTokenName,
InvalidTokenLine(String),
MissingTokenNameField,
#[cmp_neq]
IoError(std::io::Error),
}
}
To parse a file containing tokens with optional comments:
let tokens = parse_token_file("path_to_file.txt").await?;
To extract the token_name field from a JSON object:
let json = serde_json::json!({ "token_name": "example_token" });
let token_name = extract_token_name_field(&json)?;
This crate is licensed under the MIT License. See LICENSE for details.