Skip to main content

igraph_attribute_record_t

Struct igraph_attribute_record_t 

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

Implementations§

Source§

impl igraph_attribute_record_t

Source

pub fn new(name: &str, attribute_type: AttributeType) -> Result<Self>

Creates an empty record with the given name and type (igraph_attribute_record_init).

An AttributeType::Unspecified record is untyped: it holds no values until set_type gives it a type.

Time complexity: O(1).

§Errors

ErrorKind::InvalidValue if name contains a NUL byte or the type is AttributeType::Object (checked in Rust: since igraph 1.0.1 the C library treats an unsupported type as a fatal error and aborts the process, while 1.0.0 returned an error).

§Examples
use igraph::attributes::{AttributeRecord, AttributeType};
let mut rec = AttributeRecord::new("color", AttributeType::String).unwrap();
assert!(rec.is_empty());
rec.resize(2).unwrap();
assert_eq!(rec.values().as_strings().unwrap(), ["", ""]);
assert!(AttributeRecord::new("o", AttributeType::Object).is_err());
Source

pub fn numeric(name: &str, values: &[f64]) -> Result<Self>

Creates a numeric record holding values.

Source

pub fn boolean(name: &str, values: &[bool]) -> Result<Self>

Creates a boolean record holding values.

Source

pub fn string<S: AsRef<str>>(name: &str, values: &[S]) -> Result<Self>

Creates a string record holding values.

§Errors

ErrorKind::InvalidValue if a string contains a NUL byte.

Source

pub fn from_values( name: &str, values: impl Into<AttributeValues>, ) -> Result<Self>

Creates a record of the type of values.

Source

pub fn name(&self) -> Option<&str>

The name of the attribute (None if unset or not UTF-8).

Source

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

Renames the record (igraph_attribute_record_set_name).

Source

pub fn attribute_type(&self) -> AttributeType

The type of the values.

Source

pub fn set_type(&mut self, attribute_type: AttributeType) -> Result<()>

Changes the type of the record (igraph_attribute_record_set_type).

When the type changes, the values are discarded and the record becomes empty; setting the same type is a no-op.

§Errors

ErrorKind::InvalidValue for AttributeType::Unspecified and AttributeType::Object, checked in Rust: igraph 1.0.1 aborts the process on these (a fatal error in igraph_attribute_record_set_type; 1.0.0 returned IGRAPH_EINVAL).

§Examples
use igraph::attributes::{AttributeRecord, AttributeType};
let mut rec = AttributeRecord::numeric("x", &[1.0, 2.0]).unwrap();
rec.set_type(AttributeType::Numeric).unwrap(); // same type: no-op
assert_eq!(rec.len(), 2);
rec.set_type(AttributeType::Boolean).unwrap(); // new type: values dropped
assert!(rec.is_empty());
assert!(rec.set_type(AttributeType::Unspecified).is_err());
Source

pub fn check_type(&self, expected: AttributeType) -> Result<()>

Checks that the record has the expected type (igraph_attribute_record_check_type).

§Errors

ErrorKind::InvalidValue if the types differ.

Source

pub fn len(&self) -> usize

Number of values (igraph_attribute_record_size).

Source

pub fn is_empty(&self) -> bool

Whether the record holds no values.

Source

pub fn resize(&mut self, len: usize) -> Result<()>

Resizes the value vector, filling new slots with the default value (igraph_attribute_record_resize).

§Errors

ErrorKind::InvalidValue if the record has no type yet.

Source

pub fn set_default(&mut self, value: impl Into<AttributeValue>) -> Result<()>

Sets the value used to fill new slots on resize (igraph_attribute_record_set_default_numeric, _boolean, _string).

§Errors

ErrorKind::InvalidValue if the value’s type is not the record’s type.

Source

pub fn default_value(&self) -> Option<AttributeValue>

The value used to fill new slots on resize, see set_default; None for an untyped record.

Unless changed, it is NaN, false or "" depending on the type.

use igraph::attributes::{AttributeRecord, AttributeValue};
let mut rec = AttributeRecord::string("city", &["Firenze"]).unwrap();
assert_eq!(rec.default_value(), Some(AttributeValue::String(String::new())));
rec.set_default("unknown").unwrap();
assert_eq!(rec.default_value(), Some(AttributeValue::String("unknown".into())));
Source

pub fn values(&self) -> AttributeValues

A copy of the values (an empty AttributeValues::Numeric for an untyped record).

Trait Implementations§

Source§

impl Clone for igraph_attribute_record_t

Source§

fn clone(&self) -> Self

Deep copy of the name, type, values and default value.

It does not use igraph_attribute_record_init_copy: that function does not copy the default value, and when it fails its partially initialized result can be neither destroyed nor leaked safely.

§Panics

If igraph fails to allocate the copy.

1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for igraph_attribute_record_t

Source§

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

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

impl Drop for igraph_attribute_record_t

Source§

fn drop(&mut self)

Frees the name and the values (igraph_attribute_record_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 PartialEq for igraph_attribute_record_t

Source§

fn eq(&self, other: &Self) -> bool

Records are equal when their names, types, values and default values are. Records are compared as data: a NaN number equals another NaN (the default value of a numeric record is NaN unless changed, so with f64 semantics a numeric record would never equal its clone).

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 Send for igraph_attribute_record_t

Source§

impl Sync for igraph_attribute_record_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> 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, 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.