Skip to content

Commit

Permalink
Into pr docs (#24)
Browse files Browse the repository at this point in the history
* intl_pr: add docs for IntoPluralOperands

* Put use bac in
  • Loading branch information
unclenachoduh committed Aug 15, 2018
1 parent fadafb9 commit ad89a0e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions intl_pluralrules/src/operands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,37 @@ impl PluralOperands {
}

// once TryFrom stabilizes we can use that instead
/// A trait that can be implemented on any type to allow it for passing to [`select`](../struct.IntlPluralRules.html#method.select). This trait is made public for implementations of custom types. If you are using generic types, you should use [`from`](struct.PluralOperands.html#method.from).
///
/// # Example
///
/// ```
/// use intl_pluralrules::operands::*;
/// use intl_pluralrules::{IntlPluralRules, PluralRuleType, PluralCategory};
///
/// struct MyType {
/// value: isize
/// }
///
/// impl IntoPluralOperands for MyType {
/// fn into_plural(self) -> Result<PluralOperands, &'static str> {
/// Ok(PluralOperands {
/// n: self.value as f64,
/// i: self.value as isize,
/// v: 0,
/// w: 0,
/// f: 0,
/// t: 0,
/// })
/// }
/// }
///
/// let pr = IntlPluralRules::create("en", PluralRuleType::CARDINAL).unwrap();
/// let v = MyType { value: 5 };
///
/// assert_eq!(pr.select(v), Ok(PluralCategory::OTHER));
///
/// ```
pub trait IntoPluralOperands {
fn into_plural(self) -> Result<PluralOperands, &'static str>;
}
Expand Down

0 comments on commit ad89a0e

Please sign in to comment.