pub struct igraph_attribute_combination_t { /* private fields */ }Implementations§
Source§impl igraph_attribute_combination_t
impl igraph_attribute_combination_t
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty combination list
(igraph_attribute_combination_init).
§Panics
If igraph fails to allocate it.
Sourcepub fn from_pairs(
pairs: &[(Option<&str>, AttributeCombinationType)],
) -> Result<Self>
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.
Sourcepub fn all(kind: AttributeCombinationType) -> Result<Self>
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);Sourcepub fn add(
&mut self,
name: Option<&str>,
kind: AttributeCombinationType,
) -> Result<()>
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.
Sourcepub unsafe fn add_function(
&mut self,
name: Option<&str>,
func: CombineFunction,
) -> Result<()>
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();Sourcepub fn remove(&mut self, name: Option<&str>) -> Result<()>
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).
Sourcepub fn query(&self, name: Option<&str>) -> Result<AttributeCombinationType>
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.
Sourcepub fn as_ptr(&self) -> *const igraph_attribute_combination_t
pub fn as_ptr(&self) -> *const igraph_attribute_combination_t
Raw pointer for the igraph functions taking a
const igraph_attribute_combination_t *.