Skip to main content

Label

Struct Label 

Source
pub struct Label<T: LabelMembership> { /* private fields */ }
Expand description

Fuzzy label struct.

It is defined by a membership function and a name.

Implementations§

Source§

impl<T: LabelMembership> Label<T>

Source

pub fn new(name: String, membership: T) -> Result<Self, LabelError>

Creates a new label.

§Arguments
  • name: Label name.
  • membership: Membership function.
§Examples
let label = Label::new(
    String::from("a"),
    Trapezoidal::new(vec![0.0, 0.5, 1.0]).unwrap()
).unwrap();
assert_eq!(format!("{}", label), "a => (0.00, 0.50, 1.00)");
§Errors

LabelError::NonStandardizedName: If name isn’t standardized.

let names = vec![" a", "A", " c "];
for name in names {
    assert_eq!(
        Label::new(
            name.to_string(),
            Trapezoidal::new(vec![0.0, 0.5, 1.0]).unwrap()
        ),
        Err(LabelError::NonStandardizedName { name: name.to_string() })
    );
}

LabelError::EmptyName: If name.len() == 0.

assert_eq!(
    Label::new(
        String::new(),
        Trapezoidal::new(vec![0.0, 0.5, 1.0]).unwrap()
    ),
    Err(LabelError::EmptyName)
);
Source

pub fn name(&self) -> &String

Returns label name.

§Examples
let name = String::from("a");
let label = Label::new(
    name.clone(),
    Trapezoidal::new(vec![0.0, 0.5, 1.0]).unwrap()
).unwrap();
assert_eq!(*label.name(), name);
Source

pub fn membership(&self) -> &T

Returns label membership.

§Examples
let membership = Trapezoidal::new(vec![0.0, 0.5, 1.0]).unwrap();
let label = Label::new(
    String::from("a"),
    membership
).unwrap();
assert_eq!(format!("{}", *label.membership()), "(0.00, 0.50, 1.00)");

Trait Implementations§

Source§

impl<T: Clone + LabelMembership> Clone for Label<T>

Source§

fn clone(&self) -> Label<T>

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<T: Debug + LabelMembership> Debug for Label<T>

Source§

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

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

impl<T: LabelMembership + Display> Display for Label<T>

Source§

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

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

impl From<&Label<Trapezoidal>> for PiecewiseLinearFunction

Generates a PiecewiseLinearFunction from a trapezoidal label.

§Examples

let labels = trapezoidal_labels![
    "a" => vec![0.0, 0.1, 0.2, 0.3],
    "b" => vec![0.0, 0.1, 0.1, 0.2],
    "c" => vec![0.0, 0.1, 0.2]
].unwrap();

assert_eq!(format!("{}", PiecewiseLinearFunction::from(&labels[0])), "([0.00, 0.10] => y = 10.00·x + 0.00); ([0.10, 0.20] => y = 0.00·x + 1.00); ([0.20, 0.30] => y = -10.00·x + 3.00)");
assert_eq!(format!("{}", PiecewiseLinearFunction::from(&labels[1])), "([0.00, 0.10] => y = 10.00·x + 0.00); ([0.10, 0.20] => y = -10.00·x + 2.00)");
assert_eq!(format!("{}", PiecewiseLinearFunction::from(&labels[2])), "([0.00, 0.10] => y = 10.00·x + 0.00); ([0.10, 0.20] => y = -10.00·x + 2.00)");
Source§

fn from(l: &Label<Trapezoidal>) -> Self

Converts to this type from the input type.
Source§

impl<T: PartialEq + LabelMembership> PartialEq for Label<T>

Source§

fn eq(&self, other: &Label<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: LabelMembership> StructuralPartialEq for Label<T>

Auto Trait Implementations§

§

impl<T> Freeze for Label<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Label<T>
where T: RefUnwindSafe,

§

impl<T> Send for Label<T>
where T: Send,

§

impl<T> Sync for Label<T>
where T: Sync,

§

impl<T> Unpin for Label<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Label<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Label<T>
where T: UnwindSafe,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

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

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

Source§

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 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.