Struct cdtoc::AccurateRip

source ·
pub struct AccurateRip(/* private fields */);
Available on crate feature accuraterip only.
Expand description

AccurateRip ID.

This struct holds an AccurateRip ID.

Values of this type are returned by Toc::accuraterip_id.

Examples

use cdtoc::Toc;

let toc = Toc::from_cdtoc("4+96+2D2B+6256+B327+D84A").unwrap();
let ar_id = toc.accuraterip_id();

// Usually you'll want this value as a string:
assert_eq!(
    ar_id.to_string(),
    "004-0002189a-00087f33-1f02e004",
);

// But you can also get a binary version matching the format of the
// checksum bin files:
assert_eq!(
    <[u8; 13]>::from(ar_id),
    [4, 154, 24, 2, 0, 51, 127, 8, 0, 4, 224, 2, 31],
);

Implementations§

source§

impl AccurateRip

source

pub const DRIVE_OFFSET_URL: &'static str = "http://www.accuraterip.com/accuraterip/DriveOffsets.bin"

Drive Offset Data URL.

The binary-encoded list of known AccurateRip drive offsets can be downloaded from this fixed URL.

The method AccurateRip::parse_drive_offsets can be used to parse the raw data into a Rustful structure.

source§

impl AccurateRip

source

pub const fn audio_len(&self) -> u8

Number of Audio Tracks.
Examples
use cdtoc::Toc;

// From Toc.
let toc = Toc::from_cdtoc("4+96+2D2B+6256+B327+D84A").unwrap();
assert_eq!(toc.audio_len(), 4_usize);

// From AccurateRip.
let disc_id = toc.accuraterip_id();
assert_eq!(disc_id.audio_len(), 4_u8);
source

pub fn checksum_url(&self) -> String

AccurateRip Checksum URL.

This returns the URL where you can download the v1 and v2 checksums for the disc, provided it is actually in the AccurateRip database. (If it isn’t, their server will return a 404.)

You can also get this directly via Toc::accuraterip_checksum_url.

Examples
use cdtoc::Toc;

let toc = Toc::from_cdtoc("4+96+2D2B+6256+B327+D84A").unwrap();
let ar_id = toc.accuraterip_id();
assert_eq!(
    ar_id.checksum_url(),
    "http://www.accuraterip.com/accuraterip/a/9/8/dBAR-004-0002189a-00087f33-1f02e004.bin",
);
source

pub const fn cddb_id(&self) -> Cddb

CDDB ID.

In cases where your application requires both AccurateRip and CDDB IDs, using this method to obtain the latter is cheaper than calling Toc::cddb_id.

Examples
use cdtoc::Toc;

let toc = Toc::from_cdtoc("4+96+2D2B+6256+B327+D84A").unwrap();
let ar_id = toc.accuraterip_id();
assert_eq!(
    ar_id.cddb_id(),
    toc.cddb_id(),
);
source

pub fn decode<S>(src: S) -> Result<Self, TocError>where S: AsRef<str>,

Decode.

Convert an AccurateRip ID string back into an AccurateRip instance.

Examples
use cdtoc::{AccurateRip, Toc};

let toc = Toc::from_cdtoc("4+96+2D2B+6256+B327+D84A").unwrap();
let ar_id = toc.accuraterip_id();
let ar_str = ar_id.to_string();
assert_eq!(ar_str, "004-0002189a-00087f33-1f02e004");
assert_eq!(AccurateRip::decode(ar_str), Ok(ar_id));

Alternatively, you can use its FromStr and TryFrom<&str> impls:

use cdtoc::{AccurateRip, Toc};

let toc = Toc::from_cdtoc("4+96+2D2B+6256+B327+D84A").unwrap();
let ar_id = toc.accuraterip_id();
let ar_str = ar_id.to_string();
assert_eq!(AccurateRip::try_from(ar_str.as_str()), Ok(ar_id));
assert_eq!(ar_str.parse::<AccurateRip>(), Ok(ar_id));
Errors

This will return an error if decoding fails.

source

pub fn parse_checksums( &self, bin: &[u8] ) -> Result<Vec<BTreeMap<u32, u8>>, TocError>

Parse Checksums.

This will parse the v1 and v2 track checksums from a raw AccurateRip checksum bin file.

The return result is a vector — indexed by track number (n-1) — of checksum => confidence pairs.

Note: AccurateRip does not differentiate between v1 and v2 checksums; the only way to know which is which is to find a match for a checksum you calculated yourself.

Errors

This will return an error if parsing is unsuccessful, or the result is empty.

source

pub fn parse_drive_offsets( raw: &[u8] ) -> Result<BTreeMap<(&str, &str), i16>, TocError>

Parse Drive Offsets.

This will parse the vendor, model, and sample read offset information from the raw AccurateRip offset list (bin file).

The parsed offsets will be grouped by (vendor, model). Some entries will not have a vendor, but entries without models are silently ignored.

Errors

This will return an error if parsing is unsuccessful, or the result is empty.

source

pub fn pretty_print(&self) -> String

Pretty Print.

Return a String representation of the disc ID, same as AccurateRip::to_string, but a little faster.

Examples
use cdtoc::Toc;

let toc = Toc::from_cdtoc("D+96+4FFB+7F76+BB0A+EF38+12FB3+16134+1BCC4+1EC21+24A6A+272F9+299FA+2CCA6+30EE6").unwrap();
assert_eq!(
    toc.accuraterip_id().pretty_print(),
    "013-0015deca-00d9b921-9a0a6e0d",
);

Trait Implementations§

source§

impl AsRef<[u8]> for AccurateRip

source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for AccurateRip

source§

fn clone(&self) -> AccurateRip

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for AccurateRip

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for AccurateRip

Available on crate feature serde only.
source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for AccurateRip

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<&Toc> for AccurateRip

source§

fn from(src: &Toc) -> Self

Converts to this type from the input type.
source§

impl From<AccurateRip> for [u8; 13]

source§

fn from(src: AccurateRip) -> Self

Converts to this type from the input type.
source§

impl FromStr for AccurateRip

§

type Err = TocError

The associated error which can be returned from parsing.
source§

fn from_str(src: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl Hash for AccurateRip

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for AccurateRip

source§

fn eq(&self, other: &AccurateRip) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for AccurateRip

Available on crate feature serde only.
source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl TryFrom<&str> for AccurateRip

§

type Error = TocError

The type returned in the event of a conversion error.
source§

fn try_from(src: &str) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Copy for AccurateRip

source§

impl Eq for AccurateRip

source§

impl StructuralEq for AccurateRip

source§

impl StructuralPartialEq for AccurateRip

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,