pub struct Opus { /* private fields */ }Expand description
Represents a work (book, article, etc.) identified by its title.
Implementations§
Source§impl Opus
impl Opus
Sourcepub fn new(title: impl Into<String>) -> Opus
pub fn new(title: impl Into<String>) -> Opus
Creates a new Opus from a title, filed as written (no article
language).
Sourcepub fn with_article_language(self, language: Option<Language>) -> Self
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");Sourcepub fn article_language(&self) -> Option<Language>
pub fn article_language(&self) -> Option<Language>
The language whose initial article the title is filed without, if any.
Sourcepub fn filing_title(&self) -> &str
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");Sourcepub fn as_suffix(
&self,
suffix_len: usize,
) -> Result<Cow<'_, str>, NormalizationError>
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.