pub struct igraph_attribute_record_t { /* private fields */ }Implementations§
Source§impl igraph_attribute_record_t
impl igraph_attribute_record_t
Sourcepub fn new(name: &str, attribute_type: AttributeType) -> Result<Self>
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());Sourcepub fn numeric(name: &str, values: &[f64]) -> Result<Self>
pub fn numeric(name: &str, values: &[f64]) -> Result<Self>
Creates a numeric record holding values.
Sourcepub fn boolean(name: &str, values: &[bool]) -> Result<Self>
pub fn boolean(name: &str, values: &[bool]) -> Result<Self>
Creates a boolean record holding values.
Sourcepub fn string<S: AsRef<str>>(name: &str, values: &[S]) -> Result<Self>
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.
Sourcepub fn from_values(
name: &str,
values: impl Into<AttributeValues>,
) -> Result<Self>
pub fn from_values( name: &str, values: impl Into<AttributeValues>, ) -> Result<Self>
Creates a record of the type of values.
Sourcepub fn set_name(&mut self, name: &str) -> Result<()>
pub fn set_name(&mut self, name: &str) -> Result<()>
Renames the record
(igraph_attribute_record_set_name).
Sourcepub fn attribute_type(&self) -> AttributeType
pub fn attribute_type(&self) -> AttributeType
The type of the values.
Sourcepub fn set_type(&mut self, attribute_type: AttributeType) -> Result<()>
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());Sourcepub fn check_type(&self, expected: AttributeType) -> Result<()>
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.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of values
(igraph_attribute_record_size).
Sourcepub fn resize(&mut self, len: usize) -> Result<()>
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.
Sourcepub fn set_default(&mut self, value: impl Into<AttributeValue>) -> Result<()>
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.
Sourcepub fn default_value(&self) -> Option<AttributeValue>
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())));Sourcepub fn values(&self) -> AttributeValues
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
impl Clone for igraph_attribute_record_t
Source§fn clone(&self) -> Self
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)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for igraph_attribute_record_t
impl Debug for igraph_attribute_record_t
Source§impl Drop for igraph_attribute_record_t
impl Drop for igraph_attribute_record_t
Source§impl PartialEq for igraph_attribute_record_t
impl PartialEq for igraph_attribute_record_t
Source§fn eq(&self, other: &Self) -> bool
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).