3 releases

Uses new Rust 2024

0.1.2 Apr 30, 2025
0.1.1 Mar 25, 2025
0.1.0 Mar 25, 2025

#3 in #assigned

Download history 111/week @ 2025-03-19 113/week @ 2025-03-26 2/week @ 2025-04-02 1/week @ 2025-04-09 139/week @ 2025-04-30

141 downloads per month

Apache-2.0 OR MIT

34KB
475 lines

isrc-rs

Crates.io Documentation License

A Rust library for parsing, validating, and working with ISRC (International Standard Recording Code).

What is ISRC?

An ISRC uniquely identifies sound recordings and music videos internationally. Each ISRC consists of 12 alphanumeric characters with the following structure:

  • Agency Code (2 characters): Unique identifier for the ISRC agency
  • Registrant Code (3 characters): Unique identifier for the ISRC registrant
  • Year of Reference (2 digits): Identifies the year the ISRC was assigned
  • Designation Code (5 digits): Uniquely assigned number by the registrant

When formatted for display, an ISRC typically appears as: ISRC AA-RRR-YY-DDDDD

Features

  • Memory-efficient representation (8 bytes)
  • Format-aware serialization/deserialization with serde
  • Binary serialization support via bitcode
  • Comprehensive error handling for invalid input
  • No-std compatible, zero heap allocation

Usage

Add this to your Cargo.toml:

[dependencies]
isrc = "0.1"

Basic examples

use isrc::Isrc;
use std::str::FromStr;

// Parse an ISRC from a string
let isrc = Isrc::from_code("AA6Q72000047")?;

// Parse using FromStr trait
let isrc = Isrc::from_str("AA6Q72000047")?;

// From a compact binary format
let isrc = Isrc::from_bytes(b"\xAF\x84\x1E\x00\x41\x41\x0F\x22")?;

// Display a formatted ISRC
assert_eq!(isrc.to_string(), "ISRC AA-6Q7-20-00047");

// Convert to compact code format
assert_eq!(isrc.to_code(), "AA6Q72000047");

// Binary representation
assert_eq!(isrc.to_bytes(), *b"\xAF\x84\x1E\x00\x41\x41\x0F\x22");

Serde integration

use isrc::Isrc;
use serde::{Deserialize, Serialize};

// Define a struct with an ISRC field
#[derive(Serialize, Deserialize)]
struct Recording {
    title: String,
    isrc: Isrc,
}

// For human-readable formats like JSON and TOML, ISRCs are serialized as strings
let json = r#"{"title":"Some Song","isrc":"AA6Q72000047"}"#;
let recording: Recording = serde_json::from_str(json)?;
assert_eq!(recording.isrc.to_code(), "AA6Q72000047");

// For binary formats like bincode, ISRCs are serialized efficiently as 8-byte arrays
let binary = bincode::serialize(&recording)?;
let deserialized: Recording = bincode::deserialize(&binary)?;
assert_eq!(deserialized.isrc, recording.isrc);

Dependencies

~0.2–1.6MB
~41K SLoC