Skip to main content

igraph_attribute_combination_t

Struct igraph_attribute_combination_t 

Source
pub struct igraph_attribute_combination_t { /* private fields */ }

Implementations§

Source§

impl igraph_attribute_combination_t

Source

pub fn new() -> Self

Creates an empty combination list (igraph_attribute_combination_init).

§Panics

If igraph fails to allocate it.

Source

pub fn from_pairs( pairs: &[(Option<&str>, AttributeCombinationType)], ) -> Result<Self>

Creates a combination list from (name, type) pairs, None naming the default entry (the Rust counterpart of the variadic igraph_attribute_combination).

§Errors

As add.

Source

pub fn all(kind: AttributeCombinationType) -> Result<Self>

A combination applying kind to every attribute (a single default entry).

§Errors

As add.

use igraph::attributes::{AttributeCombination, AttributeCombinationType as Comb};
let comb = AttributeCombination::all(Comb::Max).unwrap();
assert_eq!(comb.query(None).unwrap(), Comb::Max);
assert_eq!(comb.query(Some("anything")).unwrap(), Comb::Max);
Source

pub fn add( &mut self, name: Option<&str>, kind: AttributeCombinationType, ) -> Result<()>

Adds or replaces the entry of an attribute (None: the default entry) (igraph_attribute_combination_add).

§Errors

ErrorKind::InvalidValue for AttributeCombinationType::Function (use add_function) or a name containing a NUL byte.

Source

pub unsafe fn add_function( &mut self, name: Option<&str>, func: CombineFunction, ) -> Result<()>

Adds or replaces the entry of an attribute with a user supplied C function (igraph_attribute_combination_add with IGRAPH_ATTRIBUTE_COMBINE_FUNCTION).

For each merged vertex or edge, the function receives the values of the merged elements and writes the combined value.

§Safety

The C attribute handler chooses the calling convention from the type of the attribute at combination time: the function must match it, i.e. a CombineFunction::Numeric may only be registered for numeric attributes and a CombineFunction::Boolean for boolean ones (registering a default entry with name = None requires every combined attribute to have that type). The function must not unwind. String functions are not supported by this wrapper (igraph would need to free a string allocated by Rust).

use igraph::{ffi, attributes::{AttributeCombination, CombineFunction}};

unsafe extern "C" fn count(
    input: *const ffi::igraph_vector_t,
    output: *mut f64,
) -> ffi::igraph_error_t {
    unsafe { *output = (&*input).len() as f64 };
    ffi::igraph_error_type_t_IGRAPH_SUCCESS
}

let mut comb = AttributeCombination::new();
// SAFETY: "multiplicity" will be a numeric attribute.
unsafe { comb.add_function(Some("multiplicity"), CombineFunction::Numeric(count)) }.unwrap();
Source

pub fn remove(&mut self, name: Option<&str>) -> Result<()>

Removes the entry of an attribute (None: the default entry); missing entries are ignored (igraph_attribute_combination_remove).

Source

pub fn query(&self, name: Option<&str>) -> Result<AttributeCombinationType>

How the attribute name will be combined (igraph_attribute_combination_query).

Falls back to the default entry, and to AttributeCombinationType::Default when there is none.

Source

pub fn as_ptr(&self) -> *const igraph_attribute_combination_t

Raw pointer for the igraph functions taking a const igraph_attribute_combination_t *.

Trait Implementations§

Source§

impl Debug for igraph_attribute_combination_t

Source§

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

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

impl Default for igraph_attribute_combination_t

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for igraph_attribute_combination_t

Source§

fn drop(&mut self)

Frees the list (igraph_attribute_combination_destroy).

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for igraph_attribute_combination_t

Auto Trait Implementations§

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