| Crates.io | isrc |
| lib.rs | isrc |
| version | 0.1.2 |
| created_at | 2025-03-25 05:32:49.33783+00 |
| updated_at | 2025-04-30 05:08:42.529128+00 |
| description | ISRC (International Standard Recording Code) parser library. |
| homepage | |
| repository | https://github.com/contentstech-com/crates |
| max_upload_size | |
| id | 1604793 |
| size | 41,031 |
A Rust library for parsing, validating, and working with ISRC (International Standard Recording Code).
An ISRC uniquely identifies sound recordings and music videos internationally. Each ISRC consists of 12 alphanumeric characters with the following structure:
When formatted for display, an ISRC typically appears as: ISRC AA-RRR-YY-DDDDD
Add this to your Cargo.toml:
[dependencies]
isrc = "0.1"
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");
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);