Skip to main content

Opus

Struct Opus 

Source
pub struct Opus { /* private fields */ }
Expand description

Represents a work (book, article, etc.) identified by its title.

Implementations§

Source§

impl Opus

Source

pub fn new(title: impl Into<String>) -> Opus

Creates a new Opus from a title, filed as written (no article language).

Source

pub fn with_article_language(self, language: Option<Language>) -> Self

Sets the language whose initial article the title is filed without (see Language::strip_initial_article); None files the title as written. The last call wins.

§Examples
use csan_core::{Language, Opus};

let opus = Opus::new("A Christmas Carol").with_article_language(Some(Language::English));
assert_eq!(opus.article_language(), Some(Language::English));
assert_eq!(opus.filing_title(), "Christmas Carol");
assert_eq!(opus.title(), "A Christmas Carol");

let opus = opus.with_article_language(None);
assert_eq!(opus.filing_title(), "A Christmas Carol");
Source

pub fn article_language(&self) -> Option<Language>

The language whose initial article the title is filed without, if any.

Source

pub fn filing_title(&self) -> &str

The title as filed: without its initial article when an article language is set and Language::strip_initial_article finds one, and otherwise the title as written. It is always a subslice of title.

Cutter-Sanborn files on letters, so when the filing title has none (The 100 under English, filed as 100) it uses the title as written instead; LoC files 100 by its numeral rule.

§Examples
use csan_core::{Language, Opus};

let english = Some(Language::English);
assert_eq!(Opus::new("The Bear").with_article_language(english).filing_title(), "Bear");
assert_eq!(Opus::new("Theory").with_article_language(english).filing_title(), "Theory");
assert_eq!(Opus::new("The").with_article_language(english).filing_title(), "The");
assert_eq!(Opus::new("The Bear").filing_title(), "The Bear");
Source

pub fn as_suffix( &self, suffix_len: usize, ) -> Result<Cow<'_, str>, NormalizationError>

Normalizes the filing title and truncates it to at most suffix_len characters, producing the lowercase-able work mark material used by Cutter-Sanborn generation. When the filing title has no letters (The 100 under English), the title as written is used instead.

The result is guaranteed to be ASCII-alphabetic. It may be shorter than suffix_len (including empty when suffix_len == 0).

§Errors

Returns a NormalizationError if the title normalizes to an empty string or contains untransliterable non-ASCII characters.

Source

pub fn title(&self) -> &str

Returns the raw (unnormalized) title of the work.

Trait Implementations§

Source§

impl Clone for Opus

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Opus

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Opus

§

impl RefUnwindSafe for Opus

§

impl Send for Opus

§

impl Sync for Opus

§

impl Unpin for Opus

§

impl UnsafeUnpin for Opus

§

impl UnwindSafe for Opus

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> ToOwned for T
where T: Clone,

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.