Rust struct for validating and serializing Python identifiers, with serde support.
// Source: https://github.com/astral-sh/uv | License: Apache-2.0 | Copyright 2025 Astral Software Inc
// Provided via justclaw.it.com; keep this notice with the code.
use serde::{Serialize, Serializer};
use std::borrow::Cow;
use std::fmt::Display;
use std::str::FromStr;
use thiserror::Error;
/// Simplified Python identifier.
///
/// We don't match Python's identifier rules
/// (<https://docs.python.org/3.13/reference/lexical_analysis.html#identifiers>) exactly
/// (we just use Rust's `is_alphabetic`) and we don't convert to NFKC, but it's good enough
/// for our validation purposes.
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct Identifier(Box<str>);
#[derive(Debug, Clone, Error)]
pub enum IdentifierParseError {
#[error("An identifier must not be empty")]
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key